Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4010 was 4010, checked in by bensch, 19 years ago

orxonox/trunk: merged the levelloader from lltrunktemp to the trunk. Big thanks to fuzzy to make this so easy for us, and for implementing it in the first place.

File size: 7.6 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
30using namespace std;
31
32CREATE_FACTORY(Player);
33
34/**
35   \brief creates a new Player
36   \param isFree if the player is free
37*/
38Player::Player() : WorldEntity()
39{
40  /*
41    this is the debug player - actualy we would have to make a new
42     class derivated from Player for each player. for now, we just use
43     the player.cc for debug also
44  */
45  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
46  travelSpeed = 15.0;
47  velocity = new Vector();
48  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
49  bFire = false;
50  this->bWeaponChange = false;
51  acceleration = 10.0;
52  //weapons:
53  this->weaponMan = new WeaponManager();
54  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
55  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
56 
57  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
58  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
59  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
60  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
61
62}
63
64/**
65   \brief destructs the player, deletes alocated memory
66*/
67Player::~Player ()
68{
69  /* do not delete the weapons, they are contained in the pnode tree
70     and will be deleted there.
71     this only frees the memory allocated to save the list.
72  */
73  delete this->weaponMan;
74}
75
76/**
77   \brief creates a new Player from Xml Data
78   \param root the xml element containing player data
79   
80   \todo add more parameters to load
81*/
82Player::Player(TiXmlElement* root) : WorldEntity(root)
83{
84  /*
85    char* temp;
86    const char* string;
87    string = grabParameter( root, "name");
88    if( string == NULL)
89    {
90    PRINTF0("Player is missing a proper 'name'\n");
91    string = "Unknown";
92    temp = new char[strlen(string + 2)];
93    strcpy( temp, string);
94    this->setName( temp);
95    }
96    else
97    {
98    temp = new char[strlen(string + 2)];
99    strcpy( temp, string);
100    this->setName( temp);
101    }
102   
103    this->model = NULL;
104    string = grabParameter( root, "model");
105    if( string != NULL)
106    this->model = (Model*)ResourceManager::getInstance()->load(string, OBJ, RP_CAMPAIGN);
107    else
108    {
109    PRINTF0("Player is missing a proper 'model'\n");
110    this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
111    }
112    if( this->model == NULL)
113    {
114    PRINTF0("Player model '%s' could not be loaded\n", string);
115    }
116  */
117  this->weapons = new tList<Weapon>();
118  this->activeWeapon = NULL;
119  /*
120    this is the debug player - actualy we would have to make a new
121     class derivated from Player for each player. for now, we just use
122     the player.cc for debug also
123  */
124  travelSpeed = 15.0;
125  velocity = new Vector();
126  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
127  bFire = false;
128  this->bWeaponChange = false;
129  acceleration = 10.0;
130  //weapons:
131  this->weaponMan = new WeaponManager();
132  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
133  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
134 
135  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
136  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
137  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
138  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
139}
140
141/**
142   \brief adds a weapon to the weapon list of player
143   \param weapon to add
144*/
145void Player::addWeapon(Weapon* weapon)
146{
147  this->weaponMan->addWeapon(weapon);
148}
149
150
151/**
152   \brief removes a weapon from the player
153   \param weapon to remove
154*/
155void Player::removeWeapon(Weapon* weapon)
156{
157  this->weaponMan->removeWeapon(weapon);
158}
159
160
161/**
162   \brief effect that occurs after the player is spawned
163*/
164void Player::postSpawn ()
165{
166  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
167}
168
169
170/**
171   \brief the action occuring if the player left the game
172*/
173void Player::leftWorld ()
174{}
175
176
177
178/**
179   \brief if the player is hit, call this function
180   \param weapon hit by this weapon
181   \param loc ??
182*/
183void Player::hit (WorldEntity* weapon, Vector* loc)
184{
185}
186
187
188/**
189    \brief Collision with another Entity has this effect
190    \param other the other colider
191    \param ownhitflags ??
192    \param otherhitflags ??
193*/
194void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
195{
196}
197
198
199/**
200   \brief draws the player after transforming him.
201*/
202void Player::draw ()
203{ 
204  glMatrixMode(GL_MODELVIEW);
205  glPushMatrix();
206  float matrix[4][4];
207 
208  /* translate */
209  glTranslatef (this->getAbsCoor ().x, 
210                this->getAbsCoor ().y, 
211                this->getAbsCoor ().z);
212  /* rotate */
213  this->getAbsDir ().matrix (matrix);
214  glMultMatrixf((float*)matrix);
215 
216  this->model->draw();
217  glPopMatrix();
218
219  this->weaponMan->draw();
220}
221
222
223/**
224   \brief the function called for each passing timeSnap
225   \param time The timespan passed since last update
226*/
227void Player::tick (float time)
228{
229  /* link tick to weapon */
230  //this->activeWeapon->tick(time);
231  //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
232  this->weaponMan->tick(time);
233  // player controlled movement
234  this->move(time);
235  // weapon system manipulation
236  this->weapon();
237}
238
239
240/**
241   \brief action if player moves
242   \param time the timeslice since the last frame
243*/
244void Player::move (float time)
245{
246  Vector accel(0.0, 0.0, 0.0);
247  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
248  /* calculate the direction in which the craft is heading  */
249  Vector direction (1.0, 0.0, 0.0);
250  //direction = this->absDirection.apply (direction);
251  Vector orthDirection (0.0, 0.0, 1.0);
252  //orthDirection = orthDirection.cross (direction);
253
254  if( this->bUp && this->getRelCoor().x < 20)
255    accel = accel+(direction*acceleration);
256  if( this->bDown && this->getRelCoor().x > -5)
257    accel = accel-(direction*acceleration);
258  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
259    accel = accel - (orthDirection*acceleration); 
260  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
261    accel = accel + (orthDirection*acceleration);
262  if( this->bAscend )
263  if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */
264
265  Vector move = accel * time;
266  this->shiftCoor (move);
267}
268
269
270/**
271   \brief weapon manipulation by the player
272*/
273void Player::weapon()
274{
275  if( this->bFire)
276    {
277      this->weaponMan->fire();
278    }
279  if( this->bWeaponChange)
280    {
281      this->weaponMan->nextWeaponConf();
282      this->bWeaponChange = false;
283    }
284}
285
286
287/**
288   \brief The connection to the command node
289   \param cmd the Command unit from witch to map
290
291   here the commands are mapped to the players movement/weaponary
292*/
293void Player::command (Command* cmd)
294{
295  PRINTF(3)("recieved command [%s]\n", cmd->cmd);
296  if( !strcmp( cmd->cmd, "up")) this->bUp = !cmd->bUp;
297  if( !strcmp( cmd->cmd, "down")) this->bDown = !cmd->bUp;
298  if( !strcmp( cmd->cmd, "left")) this->bLeft = !cmd->bUp;
299  if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp;
300  if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp;
301  if( !strcmp( cmd->cmd, "mode")) if(cmd->bUp) this->bWeaponChange = !this->bWeaponChange;
302}
Note: See TracBrowser for help on using the repository browser.