Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/ll2trunktemp: weapon shoots again

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