Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Turret now turns into the dirrection of the Target, projectiles are aligned into this direction too.

File size: 6.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
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, 2);
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->setSlotCount(3);
113  this->weaponMan->setSlotPosition(0, Vector(-2.6, .1, -3.0));
114  this->weaponMan->setSlotPosition(1, Vector(-2.6, .1, 3.0));
115  this->weaponMan->setSlotPosition(2, Vector(-1.5, .5, 0));
116}
117
118
119/**
120 * loads the Settings of a Player from an XML-element.
121 * @param root the XML-element to load the Player's properties from
122 */
123void Player::loadParams(const TiXmlElement* root)
124{
125  static_cast<WorldEntity*>(this)->loadParams(root);
126
127
128
129}
130
131
132/**
133 * adds a weapon to the weapon list of player
134 * @param weapon to add
135*/
136void Player::addWeapon(Weapon* weapon)
137{
138  this->weaponMan->addWeapon(weapon);
139}
140
141
142/**
143 *  removes a weapon from the player
144 * @param weapon to remove
145*/
146void Player::removeWeapon(Weapon* weapon)
147{
148  this->weaponMan->removeWeapon(weapon);
149}
150
151
152/**
153 *  effect that occurs after the player is spawned
154*/
155void Player::postSpawn ()
156{
157  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
158}
159
160
161/**
162 *  the action occuring if the player left the game
163*/
164void Player::leftWorld ()
165{}
166
167
168
169/**
170 *  if the player is hit, call this function
171 * @param weapon hit by this weapon
172 * @param loc ??
173*/
174void Player::hit (WorldEntity* weapon, Vector* loc)
175{
176}
177
178
179/**
180  *  Collision with another Entity has this effect
181  * @param other the other colider
182  * @param ownhitflags ??
183  * @param otherhitflags ??
184*/
185void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
186{
187}
188
189
190/**
191 *  draws the player after transforming him.
192*/
193void Player::draw ()
194{
195  glMatrixMode(GL_MODELVIEW);
196  glPushMatrix();
197  float matrix[4][4];
198
199  /* translate */
200  glTranslatef (this->getAbsCoor ().x,
201                this->getAbsCoor ().y,
202                this->getAbsCoor ().z);
203  /* rotate */
204  this->getAbsDir ().matrix (matrix);
205  glMultMatrixf((float*)matrix);
206
207  this->model->draw();
208  glPopMatrix();
209
210  this->weaponMan->draw();
211}
212
213
214/**
215 *  the function called for each passing timeSnap
216 * @param time The timespan passed since last update
217*/
218void Player::tick (float time)
219{
220  // player controlled movement
221  this->move(time);
222
223  this->weaponMan->tick(time);
224  // weapon system manipulation
225  this->weaponAction();
226}
227
228
229/**
230 *  action if player moves
231 * @param time the timeslice since the last frame
232*/
233void Player::move (float time)
234{
235  Vector accel(0.0, 0.0, 0.0);
236  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
237  /* calculate the direction in which the craft is heading  */
238  Vector direction (1.0, 0.0, 0.0);
239  //direction = this->absDirection.apply (direction);
240  Vector orthDirection (0.0, 0.0, 1.0);
241  //orthDirection = orthDirection.cross (direction);
242
243  if( this->bUp && this->getRelCoor().x < 20)
244    accel = accel+(direction*acceleration);
245  if( this->bDown && this->getRelCoor().x > -5)
246    accel = accel -(direction*acceleration);
247  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
248    accel = accel - (orthDirection*acceleration);
249  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
250    accel = accel + (orthDirection*acceleration);
251  if( this->bAscend ) { /* FIXME */ }
252  if( this->bDescend) {/* FIXME */} /* @todo up and down player movement */
253
254  Vector move = accel * time;
255  this->shiftCoor (move);
256}
257
258
259/**
260 * weapon manipulation by the player
261*/
262void Player::weaponAction()
263{
264  if( this->bFire)
265    {
266      this->weaponMan->fire();
267    }
268}
269
270/**
271 * @todo switch statement ??
272 */
273void Player::process(const Event &event)
274{
275  if( event.type == KeyMapper::PEV_UP)
276      this->bUp = event.bPressed;
277  else if( event.type == KeyMapper::PEV_DOWN)
278      this->bDown = event.bPressed;
279  else if( event.type == KeyMapper::PEV_RIGHT)
280      this->bRight= event.bPressed;
281  else if( event.type == KeyMapper::PEV_LEFT)
282      this->bLeft = event.bPressed;
283  else if( event.type == KeyMapper::PEV_FIRE1)
284      this->bFire = event.bPressed;
285  else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
286    this->weaponMan->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
287  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
288    this->weaponMan->previousWeaponConfig();
289}
Note: See TracBrowser for help on using the repository browser.