Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/chris/src/player.cc @ 2404

Last change on this file since 2404 was 2194, checked in by chris, 20 years ago

orxonox/branches/chris: Implemented is_a() query for WorldEntities

File size: 3.1 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer: Christian Meyer
16*/
17
18#include "player.h"
19#include "stdincl.h"
20#include "collision.h"
21
22using namespace std;
23
24// initialize the pointers used for is_a identification
25bool (*Player::basefunc)(char*) = WorldEntity::is_a;
26char *Player::is = "Player";
27
28Player::Player(bool isFree) : WorldEntity(isFree)
29{
30}
31
32Player::~Player () 
33{
34}
35
36void Player::post_spawn ()
37{
38        travel_speed = 10.0;
39        velocity = Vector();
40        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
41        bFire = false;
42        acceleration = 10.0;
43        set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
44}
45
46void Player::tick (float time)
47{
48        // movement
49        move (time);
50}
51
52void Player::hit (Damage* dmg, WorldEntity* instigator, Uint32 hitflags)
53{
54}
55
56void Player::destroy ()
57{
58}
59
60void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
61{
62}
63
64void Player::command (Command* cmd)
65{
66        printf("Player|recieved command [%s]\n", cmd->cmd);
67        if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
68        else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
69        else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
70        else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
71        else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
72}
73
74void Player::draw ()
75{
76        glMatrixMode(GL_MODELVIEW);
77        glLoadIdentity();
78        float matrix[4][4];
79
80        glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
81  get_placement()->w.matrix (matrix);
82  glMultMatrixf ((float*)matrix);
83       
84        glBegin(GL_TRIANGLES);
85        glColor3f(1,0,0);
86        glVertex3f(0,0,0.5);
87        glColor3f(0,1,0);
88        glVertex3f(-0.5,0,-1);
89        glColor3f(0,0,1);
90        glVertex3f(0.5,0,-1);
91        glEnd();
92       
93        printf("Player is a Player: %d\n", is_a("Player"));
94        printf("Player is a WorldEntity: %d\n", is_a("WorldEntity"));
95        printf("Player is a Banana: %d\n", is_a("Banana"));
96        printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
97}
98
99void Player::get_lookat (Location* locbuf)
100{
101        *locbuf = *get_location();
102        //locbuf->dist += 5.0;
103}
104
105void Player::left_world ()
106{
107}
108
109void Player::move (float time)
110{
111        float xAccel, yAccel, zAccel;
112        xAccel = yAccel = zAccel = 0;
113        if( bUp) xAccel += acceleration;
114        if( bDown) xAccel -= acceleration;
115        if( bLeft) yAccel += acceleration;
116        if( bRight) yAccel -= acceleration;
117        if( bAscend) zAccel += acceleration;
118        if( bDescend) zAccel -= acceleration;
119       
120        Vector accel( xAccel, yAccel, zAccel);
121       
122        Location* l = get_location();
123       
124        // r(t) = r(0) + v(0)*t + 1/2*a*t^2
125        // r = position
126        // v = velocity
127        // a = acceleration
128       
129        l->pos = l->pos + velocity*time + (accel*(0.5*time*time));
130        l->dist += travel_speed * time;
131       
132        velocity = velocity + (accel * time);
133        printf("Player|velocity %f/%f/%f\n", velocity.x, velocity.y, velocity.z);
134}
135
136bool Player::is_a(char* name)
137{
138        if( !strcmp( name, is)) return true;
139        else return basefunc (name);
140}
Note: See TracBrowser for help on using the repository browser.