Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/player.cc @ 4332

Last change on this file since 4332 was 4289, checked in by patrick, 20 years ago

orxonox/trunk: now all unused projectiles are added to the dead list and not deleted anymore

File size: 6.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: Christian Meyer
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PLAYER
17
18#include "player.h"
19
20#include "track_manager.h"
21#include "objModel.h"
22#include "resource_manager.h"
23#include "weapon.h"
24#include "test_gun.h"
25#include "world.h"
26
27#include "list.h"
28#include "stdincl.h"
29
30#include "object_manager.h"
31#include "projectile.h"
32
33using namespace std;
34
35CREATE_FACTORY(Player);
36
37/**
38   \brief creates a new Player
39   \param isFree if the player is free
40*/
41Player::Player() : WorldEntity()
42{
43  /*
44    this is the debug player - actualy we would have to make a new
45     class derivated from Player for each player. for now, we just use
46     the player.cc for debug also
47  */
48  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
49  travelSpeed = 15.0;
50  velocity = new Vector();
51  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
52  bFire = false;
53  this->bWeaponChange = false;
54  acceleration = 10.0;
55  //weapons:
56  this->weaponMan = new WeaponManager();
57  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
58  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
59 
60  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
61  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
62  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
63  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
64}
65
66/**
67   \brief destructs the player, deletes alocated memory
68*/
69Player::~Player ()
70{
71  /* do not delete the weapons, they are contained in the pnode tree
72     and will be deleted there.
73     this only frees the memory allocated to save the list.
74  */
75  delete this->weaponMan;
76}
77
78/**
79   \brief creates a new Player from Xml Data
80   \param root the xml element containing player data
81   
82   \todo add more parameters to load
83*/
84Player::Player(const TiXmlElement* root) : WorldEntity(root)
85{
86  this->weapons = new tList<Weapon>();
87  this->activeWeapon = NULL;
88  /*
89    this is the debug player - actualy we would have to make a new
90     class derivated from Player for each player. for now, we just use
91     the player.cc for debug also
92  */
93  travelSpeed = 15.0;
94  velocity = new Vector();
95  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
96  bFire = false;
97  this->bWeaponChange = false;
98  acceleration = 10.0;
99  //weapons:
100  this->weaponMan = new WeaponManager();
101  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
102  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
103 
104  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
105  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
106  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
107  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
108}
109
110/**
111   \brief adds a weapon to the weapon list of player
112   \param weapon to add
113*/
114void Player::addWeapon(Weapon* weapon)
115{
116  this->weaponMan->addWeapon(weapon);
117}
118
119
120/**
121   \brief removes a weapon from the player
122   \param weapon to remove
123*/
124void Player::removeWeapon(Weapon* weapon)
125{
126  this->weaponMan->removeWeapon(weapon);
127}
128
129
130/**
131   \brief effect that occurs after the player is spawned
132*/
133void Player::postSpawn ()
134{
135  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
136}
137
138
139/**
140   \brief the action occuring if the player left the game
141*/
142void Player::leftWorld ()
143{}
144
145
146
147/**
148   \brief if the player is hit, call this function
149   \param weapon hit by this weapon
150   \param loc ??
151*/
152void Player::hit (WorldEntity* weapon, Vector* loc)
153{
154}
155
156
157/**
158    \brief Collision with another Entity has this effect
159    \param other the other colider
160    \param ownhitflags ??
161    \param otherhitflags ??
162*/
163void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
164{
165}
166
167
168/**
169   \brief draws the player after transforming him.
170*/
171void Player::draw ()
172{ 
173  glMatrixMode(GL_MODELVIEW);
174  glPushMatrix();
175  float matrix[4][4];
176 
177  /* translate */
178  glTranslatef (this->getAbsCoor ().x, 
179                this->getAbsCoor ().y, 
180                this->getAbsCoor ().z);
181  /* rotate */
182  this->getAbsDir ().matrix (matrix);
183  glMultMatrixf((float*)matrix);
184 
185  this->model->draw();
186  glPopMatrix();
187
188  this->weaponMan->draw();
189}
190
191
192/**
193   \brief the function called for each passing timeSnap
194   \param time The timespan passed since last update
195*/
196void Player::tick (float time)
197{
198  /* link tick to weapon */
199  //this->activeWeapon->tick(time);
200  //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
201  this->weaponMan->tick(time);
202  // player controlled movement
203  this->move(time);
204  // weapon system manipulation
205  this->weapon();
206}
207
208
209/**
210   \brief action if player moves
211   \param time the timeslice since the last frame
212*/
213void Player::move (float time)
214{
215  Vector accel(0.0, 0.0, 0.0);
216  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
217  /* calculate the direction in which the craft is heading  */
218  Vector direction (1.0, 0.0, 0.0);
219  //direction = this->absDirection.apply (direction);
220  Vector orthDirection (0.0, 0.0, 1.0);
221  //orthDirection = orthDirection.cross (direction);
222
223  if( this->bUp && this->getRelCoor().x < 20)
224    accel = accel+(direction*acceleration);
225  if( this->bDown && this->getRelCoor().x > -5)
226    accel = accel-(direction*acceleration);
227  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
228    accel = accel - (orthDirection*acceleration); 
229  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
230    accel = accel + (orthDirection*acceleration);
231  if( this->bAscend )
232  if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */
233
234  Vector move = accel * time;
235  this->shiftCoor (move);
236}
237
238
239/**
240   \brief weapon manipulation by the player
241*/
242void Player::weapon()
243{
244  if( this->bFire)
245    {
246      this->weaponMan->fire();
247    }
248  if( this->bWeaponChange)
249    {
250      this->weaponMan->nextWeaponConf();
251      this->bWeaponChange = false;
252    }
253}
254
255
256/**
257   \brief The connection to the command node
258   \param cmd the Command unit from witch to map
259
260   here the commands are mapped to the players movement/weaponary
261*/
262void Player::command (Command* cmd)
263{
264  PRINTF(3)("recieved command [%s]\n", cmd->cmd);
265  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_UP)) this->bUp = !cmd->bUp;
266  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_DOWN)) this->bDown = !cmd->bUp;
267  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_LEFT)) this->bLeft = !cmd->bUp;
268  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_RIGHT)) this->bRight = !cmd->bUp;
269  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_FIRE)) this->bFire = !cmd->bUp;
270  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_NEXT_WEAPON)) if(cmd->bUp) this->bWeaponChange = !this->bWeaponChange;
271}
Note: See TracBrowser for help on using the repository browser.