Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: added class turret, a subclass for turrets, this is not finished yet, but will be in some time from now…

File size: 6.5 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/**
60 *  destructs the player, deletes alocated memory
61*/
62Player::~Player ()
63{
64  /* do not delete the weapons, they are contained in the pnode tree
65     and will be deleted there.
66     this only frees the memory allocated to save the list.
67  */
68  delete this->weaponMan;
69}
70
71/**
72 *  creates a new Player from Xml Data
73 * @param root the xml element containing player data
74
75   @todo add more parameters to load
76*/
77Player::Player(const TiXmlElement* root)
78{
79  this->init();
80  this->loadParams(root);
81
82  //weapons:
83  Weapon* wpRight = new TestGun(this->weaponMan, 0);
84  wpRight->setName("testGun Right");
85  Weapon* wpLeft = new TestGun(this->weaponMan, 1);
86  wpLeft->setName("testGun Left");
87
88  Weapon* turret = new Turret(this->weaponMan);
89  this->weaponMan->addWeapon(wpLeft, 1, 0);
90  this->weaponMan->addWeapon(wpRight,1 ,1);
91  this->weaponMan->addWeapon(turret, 3, 1);
92
93  this->weaponMan->changeWeaponConfig(0);
94}
95
96/**
97 * initializes a Player
98 */
99void Player::init()
100{
101  this->setClassID(CL_PLAYER, "Player");
102
103//  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
104  travelSpeed = 15.0;
105  velocity = new Vector();
106  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
107  bFire = false;
108  acceleration = 10.0;
109
110
111  this->weaponMan = new WeaponManager(this);
112  this->weaponMan->setSlotPosition(0, Vector(-2.6, .1, -3.0));
113  this->weaponMan->setSlotPosition(1, Vector(-2.6, .1, 3.0));
114
115}
116
117
118/**
119 * loads the Settings of a Player from an XML-element.
120 * @param root the XML-element to load the Player's properties from
121 */
122void Player::loadParams(const TiXmlElement* root)
123{
124  static_cast<WorldEntity*>(this)->loadParams(root);
125
126
127
128}
129
130
131/**
132 * adds a weapon to the weapon list of player
133 * @param weapon to add
134*/
135void Player::addWeapon(Weapon* weapon)
136{
137  this->weaponMan->addWeapon(weapon);
138}
139
140
141/**
142 *  removes a weapon from the player
143 * @param weapon to remove
144*/
145void Player::removeWeapon(Weapon* weapon)
146{
147  this->weaponMan->removeWeapon(weapon);
148}
149
150
151/**
152 *  effect that occurs after the player is spawned
153*/
154void Player::postSpawn ()
155{
156  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
157}
158
159
160/**
161 *  the action occuring if the player left the game
162*/
163void Player::leftWorld ()
164{}
165
166
167
168/**
169 *  if the player is hit, call this function
170 * @param weapon hit by this weapon
171 * @param loc ??
172*/
173void Player::hit (WorldEntity* weapon, Vector* loc)
174{
175}
176
177
178/**
179  *  Collision with another Entity has this effect
180  * @param other the other colider
181  * @param ownhitflags ??
182  * @param otherhitflags ??
183*/
184void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
185{
186}
187
188
189/**
190 *  draws the player after transforming him.
191*/
192void Player::draw ()
193{
194  glMatrixMode(GL_MODELVIEW);
195  glPushMatrix();
196  float matrix[4][4];
197
198  /* translate */
199  glTranslatef (this->getAbsCoor ().x,
200                this->getAbsCoor ().y,
201                this->getAbsCoor ().z);
202  /* rotate */
203  this->getAbsDir ().matrix (matrix);
204  glMultMatrixf((float*)matrix);
205
206  this->model->draw();
207  glPopMatrix();
208
209  this->weaponMan->draw();
210}
211
212
213/**
214 *  the function called for each passing timeSnap
215 * @param time The timespan passed since last update
216*/
217void Player::tick (float time)
218{
219  // player controlled movement
220  this->move(time);
221
222  this->weaponMan->tick(time);
223  // weapon system manipulation
224  this->weaponAction();
225}
226
227
228/**
229 *  action if player moves
230 * @param time the timeslice since the last frame
231*/
232void Player::move (float time)
233{
234  Vector accel(0.0, 0.0, 0.0);
235  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
236  /* calculate the direction in which the craft is heading  */
237  Vector direction (1.0, 0.0, 0.0);
238  //direction = this->absDirection.apply (direction);
239  Vector orthDirection (0.0, 0.0, 1.0);
240  //orthDirection = orthDirection.cross (direction);
241
242  if( this->bUp && this->getRelCoor().x < 20)
243    accel = accel+(direction*acceleration);
244  if( this->bDown && this->getRelCoor().x > -5)
245    accel = accel -(direction*acceleration);
246  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
247    accel = accel - (orthDirection*acceleration);
248  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
249    accel = accel + (orthDirection*acceleration);
250  if( this->bAscend ) { /* FIXME */ }
251  if( this->bDescend) {/* FIXME */} /* @todo up and down player movement */
252
253  Vector move = accel * time;
254  this->shiftCoor (move);
255}
256
257
258/**
259 * weapon manipulation by the player
260*/
261void Player::weaponAction()
262{
263  if( this->bFire)
264    {
265      this->weaponMan->fire();
266    }
267}
268
269/**
270 * @todo switch statement ??
271 */
272void Player::process(const Event &event)
273{
274  if( event.type == KeyMapper::PEV_UP)
275      this->bUp = event.bPressed;
276  else if( event.type == KeyMapper::PEV_DOWN)
277      this->bDown = event.bPressed;
278  else if( event.type == KeyMapper::PEV_RIGHT)
279      this->bRight= event.bPressed;
280  else if( event.type == KeyMapper::PEV_LEFT)
281      this->bLeft = event.bPressed;
282  else if( event.type == KeyMapper::PEV_FIRE1)
283      this->bFire = event.bPressed;
284  else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
285    this->weaponMan->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
286  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
287    this->weaponMan->previousWeaponConfig();
288}
Note: See TracBrowser for help on using the repository browser.