Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: less output of Weapon

File size: 7.3 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
24#include "weapon_manager.h"
25#include "test_gun.h"
26#include "turret.h"
27#include "world.h"
28
29#include "list.h"
30
31#include "event_handler.h"
32
33#include "event.h"
34
35
36using namespace std;
37
38CREATE_FACTORY(Player);
39
40/**
41 * creates a new Player
42 * @param isFree if the player is free
43*/
44Player::Player()
45{
46  this->init();
47
48  //weapons:
49  Weapon* wpRight = new TestGun(this->weaponMan, 0);
50  Weapon* wpLeft = new TestGun(this->weaponMan, 1);
51
52  this->weaponMan->addWeapon(wpRight);
53//  this->weaponMan->addWeapon(wpLeft, WM_CONFIG1, WM_SLOT1);
54//  this->weaponMan->addWeapon(wpRight, WM_CONFIG2);
55//  this->weaponMan->addWeapon(wpLeft, WM_CONFIG2);
56}
57
58/**
59 * loads a Players information from a specified file.
60 * @param fileName the name of the File to load the player from (absolute path)
61 */
62Player::Player(const char* fileName)
63{
64  this->init();
65  TiXmlDocument doc(fileName);
66
67  if(!doc.LoadFile())
68  {
69    PRINTF(2)("Loading file %s failed for player.\n", fileName);
70    return;
71  }
72
73  this->loadParams(doc.RootElement());
74}
75
76/**
77 *  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(const TiXmlElement* root)
83{
84  this->init();
85  this->loadParams(root);
86
87  //weapons:
88  Weapon* wpRight = new TestGun(this->weaponMan, 0);
89  wpRight->setName("testGun Right");
90  Weapon* wpLeft = new TestGun(this->weaponMan, 1);
91  wpLeft->setName("testGun Left");
92
93  Weapon* turret = new Turret(this->weaponMan);
94  turret->setName("main-Turret");
95  Weapon* turret2 = new Turret(this->weaponMan);
96  this->weaponMan->addWeapon(wpLeft, 1, 0);
97  this->weaponMan->addWeapon(wpRight,1 ,1);
98  this->weaponMan->addWeapon(turret, 2, 2);
99  this->weaponMan->addWeapon(turret2, 2, 3);
100  //this->weaponMan->addWeapon(turret, 3, 0);
101
102  this->weaponMan->changeWeaponConfig(0);
103}
104
105/**
106 *  destructs the player, deletes alocated memory
107 */
108Player::~Player ()
109{
110  /* do not delete the weapons, they are contained in the pnode tree
111  and will be deleted there.
112  this only frees the memory allocated to save the list.
113  */
114  delete this->weaponMan;
115}
116
117/**
118 * initializes a Player
119 */
120void Player::init()
121{
122//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
123  this->setClassID(CL_PLAYER, "Player");
124  travelSpeed = 15.0;
125  velocity = new Vector();
126  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
127  bFire = false;
128  acceleration = 10.0;
129
130
131  this->weaponMan = new WeaponManager(this);
132  this->weaponMan->setSlotCount(4);
133  this->weaponMan->setSlotPosition(0, Vector(-2.6, .1, -3.0));
134  this->weaponMan->setSlotPosition(1, Vector(-2.6, .1, 3.0));
135  this->weaponMan->setSlotPosition(2, Vector(-1.5, .5, -.5));
136  this->weaponMan->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
137  this->weaponMan->setSlotPosition(3, Vector(-1.5, .5, .5));
138  this->weaponMan->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
139}
140
141
142/**
143 * loads the Settings of a Player from an XML-element.
144 * @param root the XML-element to load the Player's properties from
145 */
146void Player::loadParams(const TiXmlElement* root)
147{
148  static_cast<WorldEntity*>(this)->loadParams(root);
149
150
151
152}
153
154/**
155 * adds a weapon to the weapon list of player
156 * @param weapon to add
157*/
158void Player::addWeapon(Weapon* weapon)
159{
160  this->weaponMan->addWeapon(weapon);
161}
162
163
164/**
165 *  removes a weapon from the player
166 * @param weapon to remove
167*/
168void Player::removeWeapon(Weapon* weapon)
169{
170  this->weaponMan->removeWeapon(weapon);
171}
172
173
174/**
175 *  effect that occurs after the player is spawned
176*/
177void Player::postSpawn ()
178{
179  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
180}
181
182
183/**
184 *  the action occuring if the player left the game
185*/
186void Player::leftWorld ()
187{}
188
189
190
191/**
192 *  if the player is hit, call this function
193 * @param weapon hit by this weapon
194 * @param loc ??
195*/
196void Player::hit (WorldEntity* weapon, Vector* loc)
197{
198}
199
200
201/**
202  *  Collision with another Entity has this effect
203  * @param other the other colider
204  * @param ownhitflags ??
205  * @param otherhitflags ??
206*/
207void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
208{
209}
210
211
212/**
213 *  draws the player after transforming him.
214*/
215void Player::draw ()
216{
217  glMatrixMode(GL_MODELVIEW);
218  glPushMatrix();
219  /* translate */
220  glTranslatef (this->getAbsCoor ().x,
221                this->getAbsCoor ().y,
222                this->getAbsCoor ().z);
223  /* rotate */
224  Vector tmpRot = this->getAbsDir().getSpacialAxis();
225  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
226  this->model->draw();
227  glPopMatrix();
228
229  this->weaponMan->draw();
230
231  //this->debug(0);
232}
233
234
235/**
236 *  the function called for each passing timeSnap
237 * @param time The timespan passed since last update
238*/
239void Player::tick (float time)
240{
241  // player controlled movement
242  this->move(time);
243
244  this->weaponMan->tick(time);
245  // weapon system manipulation
246  this->weaponAction();
247}
248
249
250/**
251 *  action if player moves
252 * @param time the timeslice since the last frame
253*/
254void Player::move (float time)
255{
256  Vector accel(0.0, 0.0, 0.0);
257  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
258  /* calculate the direction in which the craft is heading  */
259  Vector direction (1.0, 0.0, 0.0);
260  //direction = this->absDirection.apply (direction);
261  Vector orthDirection (0.0, 0.0, 1.0);
262  //orthDirection = orthDirection.cross (direction);
263
264  if( this->bUp && this->getRelCoor().x < 20)
265    accel = accel+(direction*acceleration);
266  if( this->bDown && this->getRelCoor().x > -5)
267    accel = accel -(direction*acceleration);
268  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
269    accel = accel - (orthDirection*acceleration);
270  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
271    accel = accel + (orthDirection*acceleration);
272  if( this->bAscend ) { /* FIXME */ }
273  if( this->bDescend) {/* FIXME */} /* @todo up and down player movement */
274
275  Vector move = accel * time;
276  this->shiftCoor (move);
277}
278
279
280/**
281 * weapon manipulation by the player
282*/
283void Player::weaponAction()
284{
285  if( this->bFire)
286    {
287      this->weaponMan->fire();
288    }
289}
290
291/**
292 * @todo switch statement ??
293 */
294void Player::process(const Event &event)
295{
296  if( event.type == KeyMapper::PEV_UP)
297      this->bUp = event.bPressed;
298  else if( event.type == KeyMapper::PEV_DOWN)
299      this->bDown = event.bPressed;
300  else if( event.type == KeyMapper::PEV_RIGHT)
301      this->bRight= event.bPressed;
302  else if( event.type == KeyMapper::PEV_LEFT)
303      this->bLeft = event.bPressed;
304  else if( event.type == KeyMapper::PEV_FIRE1)
305      this->bFire = event.bPressed;
306  else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
307    this->weaponMan->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
308  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
309    this->weaponMan->previousWeaponConfig();
310}
Note: See TracBrowser for help on using the repository browser.