Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: multiple sounds on the turret
this does not really work, as openAL is only really able to play back one effect on a SoundSource, this is rather silly…. check it out …

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