Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/ll2trunktemp/src/world_entities/player.cc @ 4002

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

orxonox/branches/ll2trunktemp: now WorldEntity loads model property

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