Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/textEngine/src/world_entities/player.cc @ 3766

Last change on this file since 3766 was 3681, checked in by bensch, 20 years ago

orxonox/branches/textEngine: merged trunk here.
merged with command:
svn merge ../trunk textEngine -r 3467:HEAD
no conflicts

File size: 5.6 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#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PLAYER
19
20#include "player.h"
21
22#include "track_manager.h"
23#include "objModel.h"
24#include "resource_manager.h"
25#include "weapon.h"
26#include "test_gun.h"
27#include "world.h"
28
29#include "list.h"
30#include "stdincl.h"
31
32using namespace std;
33
34/**
35   \brief creates a new Player
36   \param isFree if the player is free
37*/
38Player::Player() : WorldEntity()
39{
40  this->weapons = new tList<Weapon>();
41  this->activeWeapon = NULL;
42  /*
43    this is the debug player - actualy we would have to make a new
44     class derivated from Player for each player. for now, we just use
45     the player.cc for debug also
46  */
47  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
48  travelSpeed = 15.0;
49  velocity = new Vector();
50  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
51  bFire = false;
52  acceleration = 10.0;
53  //weapons:
54  Weapon* wp = new TestGun(this, new Vector(), new Quaternion);
55  this->weapons->add(wp);
56  this->activeWeapon = wp; 
57}
58
59/**
60   \brief destructs the player, deletes alocated memory
61*/
62Player::~Player ()
63{
64  /* do not delete the weapons, they are contained in the pnode tree
65     and will be deleted there.
66     this only frees the memory allocated to save the list.
67  */
68  delete this->weapons;
69}
70
71
72/**
73   \brief adds a weapon to the weapon list of player
74   \param weapon to add
75*/
76void Player::addWeapon(Weapon* weapon)
77{
78  this->weapons->add(weapon);
79}
80
81
82/**
83   \brief removes a weapon from the player
84   \param weapon to remove
85*/
86void Player::removeWeapon(Weapon* weapon)
87{
88  this->weapons->remove(weapon);
89}
90
91
92/**
93   \brief effect that occurs after the player is spawned
94*/
95void Player::postSpawn ()
96{
97  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
98}
99
100
101/**
102   \brief the action occuring if the player left the game
103*/
104void Player::leftWorld ()
105{}
106
107
108
109/**
110   \brief if the player is hit, call this function
111   \param weapon hit by this weapon
112   \param loc ??
113*/
114void Player::hit (WorldEntity* weapon, Vector* loc)
115{
116}
117
118
119/**
120    \brief Collision with another Entity has this effect
121    \param other the other colider
122    \param ownhitflags ??
123    \param otherhitflags ??
124*/
125void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
126{
127}
128
129
130/**
131   \brief draws the player after transforming him.
132*/
133void Player::draw ()
134{ 
135  glMatrixMode(GL_MODELVIEW);
136  glPushMatrix();
137  float matrix[4][4];
138 
139  /* translate */
140  glTranslatef (this->getAbsCoor ().x, 
141                this->getAbsCoor ().y, 
142                this->getAbsCoor ().z);
143  /* rotate */
144  this->getAbsDir ().matrix (matrix);
145  glMultMatrixf((float*)matrix);
146 
147  this->model->draw();
148  glPopMatrix();
149}
150
151
152/**
153   \brief the function called for each passing timeSnap
154   \param time The timespan passed since last update
155*/
156void Player::tick (float time)
157{
158  // player controlled movement
159  this->move(time);
160  // weapon system manipulation
161  this->weapon();
162}
163
164
165/**
166   \brief action if player moves
167   \param time the timeslice since the last frame
168*/
169void Player::move (float time)
170{
171  Vector accel(0.0, 0.0, 0.0);
172  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
173 
174  /* calculate the direction in which the craft is heading  */
175  Vector direction (1.0, 0.0, 0.0);
176  //direction = this->absDirection.apply (direction);
177  Vector orthDirection (0.0, 0.0, 1.0);
178  //orthDirection = orthDirection.cross (direction);
179
180  if( this->bUp && this->getRelCoor()->x < 20)
181    accel = accel+(direction*acceleration);
182  if( this->bDown && this->getRelCoor()->x > -5)
183    accel = accel-(direction*acceleration);
184  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor()->z*2)
185    accel = accel - (orthDirection*acceleration); 
186  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor()->z*2)
187    accel = accel + (orthDirection*acceleration);
188  if( this->bAscend )
189  if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */
190
191  Vector move = accel * time;
192  this->shiftCoor (&move);
193}
194
195
196/**
197   \brief weapon manipulation by the player
198*/
199void Player::weapon()
200{
201  if( this->bFire)
202    {
203      if(this->activeWeapon != NULL)
204        this->activeWeapon->fire();
205    }
206  if( this->bWeaponChange && this->weapons->getSize() > 1)
207    {
208      PRINTF(1)("changing the weapon of the player: deactivate old, activate new\n");
209      this->activeWeapon->deactivate();
210      //this->weapons->enumerate();  FIX: strang weapon change...
211      this->activeWeapon = this->weapons->nextElement(this->activeWeapon);
212      this->activeWeapon->activate();
213    }
214}
215
216
217/**
218   \brief The connection to the command node
219   \param cmd the Command unit from witch to map
220
221   here the commands are mapped to the players movement/weaponary
222*/
223void Player::command (Command* cmd)
224{
225  PRINTF(3)("recieved command [%s]\n", cmd->cmd);
226  if( !strcmp( cmd->cmd, "up")) this->bUp = !cmd->bUp;
227  else if( !strcmp( cmd->cmd, "down")) this->bDown = !cmd->bUp;
228  else if( !strcmp( cmd->cmd, "left")) this->bLeft = !cmd->bUp;
229  else if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp;
230  else if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp;
231  else if( !strcmp( cmd->cmd, "mode")) this->bWeaponChange = !cmd->bUp;
232}
Note: See TracBrowser for help on using the repository browser.