Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/heightMap/src/world_entities/player.cc @ 4366

Last change on this file since 4366 was 4122, checked in by bensch, 20 years ago

orxonox/branches/heightMap: merged the Trunk back into branches/heightMap:
merged with Command
svn merge -r 3918:HEAD trunk branches/heightMap
conflicts resolved in favor of the Trunk

File size: 6.9 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#include "weapon.h"
24#include "test_gun.h"
25#include "world.h"
26
27#include "list.h"
28#include "stdincl.h"
29
30using namespace std;
31
32CREATE_FACTORY(Player);
33
34/**
35   \brief creates a new Player
36   \param isFree if the player is free
37*/
38Player::Player() : WorldEntity()
39{
40  /*
41    this is the debug player - actualy we would have to make a new
42     class derivated from Player for each player. for now, we just use
43     the player.cc for debug also
44  */
45  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
46  travelSpeed = 15.0;
47  velocity = new Vector();
48  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
49  bFire = false;
50  this->bWeaponChange = false;
51  acceleration = 10.0;
52  //weapons:
53  this->weaponMan = new WeaponManager();
54  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
55  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
56 
57  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
58  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
59  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
60  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
61
62}
63
64/**
65   \brief destructs the player, deletes alocated memory
66*/
67Player::~Player ()
68{
69  /* do not delete the weapons, they are contained in the pnode tree
70     and will be deleted there.
71     this only frees the memory allocated to save the list.
72  */
73  delete this->weaponMan;
74}
75
76/**
77   \brief 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(TiXmlElement* root) : WorldEntity(root)
83{
84  this->weapons = new tList<Weapon>();
85  this->activeWeapon = NULL;
86  /*
87    this is the debug player - actualy we would have to make a new
88     class derivated from Player for each player. for now, we just use
89     the player.cc for debug also
90  */
91  travelSpeed = 15.0;
92  velocity = new Vector();
93  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
94  bFire = false;
95  this->bWeaponChange = false;
96  acceleration = 10.0;
97  //weapons:
98  this->weaponMan = new WeaponManager();
99  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
100  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
101 
102  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
103  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
104  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
105  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
106}
107
108/**
109   \brief adds a weapon to the weapon list of player
110   \param weapon to add
111*/
112void Player::addWeapon(Weapon* weapon)
113{
114  this->weaponMan->addWeapon(weapon);
115}
116
117
118/**
119   \brief removes a weapon from the player
120   \param weapon to remove
121*/
122void Player::removeWeapon(Weapon* weapon)
123{
124  this->weaponMan->removeWeapon(weapon);
125}
126
127
128/**
129   \brief effect that occurs after the player is spawned
130*/
131void Player::postSpawn ()
132{
133  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
134}
135
136
137/**
138   \brief the action occuring if the player left the game
139*/
140void Player::leftWorld ()
141{}
142
143
144
145/**
146   \brief if the player is hit, call this function
147   \param weapon hit by this weapon
148   \param loc ??
149*/
150void Player::hit (WorldEntity* weapon, Vector* loc)
151{
152}
153
154
155/**
156    \brief Collision with another Entity has this effect
157    \param other the other colider
158    \param ownhitflags ??
159    \param otherhitflags ??
160*/
161void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
162{
163}
164
165
166/**
167   \brief draws the player after transforming him.
168*/
169void Player::draw ()
170{ 
171  glMatrixMode(GL_MODELVIEW);
172  glPushMatrix();
173  float matrix[4][4];
174 
175  /* translate */
176  glTranslatef (this->getAbsCoor ().x, 
177                this->getAbsCoor ().y, 
178                this->getAbsCoor ().z);
179  /* rotate */
180  this->getAbsDir ().matrix (matrix);
181  glMultMatrixf((float*)matrix);
182 
183  this->model->draw();
184  glPopMatrix();
185
186  this->weaponMan->draw();
187}
188
189
190/**
191   \brief the function called for each passing timeSnap
192   \param time The timespan passed since last update
193*/
194void Player::tick (float time)
195{
196  /* link tick to weapon */
197  //this->activeWeapon->tick(time);
198  //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
199  this->weaponMan->tick(time);
200  // player controlled movement
201  this->move(time);
202  // weapon system manipulation
203  this->weapon();
204}
205
206
207/**
208   \brief action if player moves
209   \param time the timeslice since the last frame
210*/
211void Player::move (float time)
212{
213  Vector accel(0.0, 0.0, 0.0);
214  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
215  /* calculate the direction in which the craft is heading  */
216  Vector direction (1.0, 0.0, 0.0);
217  //direction = this->absDirection.apply (direction);
218  Vector orthDirection (0.0, 0.0, 1.0);
219  //orthDirection = orthDirection.cross (direction);
220
221  if( this->bUp && this->getRelCoor().x < 20)
222    accel = accel+(direction*acceleration);
223  if( this->bDown && this->getRelCoor().x > -5)
224    accel = accel-(direction*acceleration);
225  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
226    accel = accel - (orthDirection*acceleration); 
227  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
228    accel = accel + (orthDirection*acceleration);
229  if( this->bAscend )
230  if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */
231
232  Vector move = accel * time;
233  this->shiftCoor (move);
234}
235
236
237/**
238   \brief weapon manipulation by the player
239*/
240void Player::weapon()
241{
242  if( this->bFire)
243    {
244      this->weaponMan->fire();
245    }
246  if( this->bWeaponChange)
247    {
248      this->weaponMan->nextWeaponConf();
249      this->bWeaponChange = false;
250    }
251}
252
253
254/**
255   \brief The connection to the command node
256   \param cmd the Command unit from witch to map
257
258   here the commands are mapped to the players movement/weaponary
259*/
260void Player::command (Command* cmd)
261{
262  PRINTF(3)("recieved command [%s]\n", cmd->cmd);
263  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_UP)) this->bUp = !cmd->bUp;
264  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_DOWN)) this->bDown = !cmd->bUp;
265  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_LEFT)) this->bLeft = !cmd->bUp;
266  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_RIGHT)) this->bRight = !cmd->bUp;
267  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_FIRE)) this->bFire = !cmd->bUp;
268  if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_NEXT_WEAPON)) if(cmd->bUp) this->bWeaponChange = !this->bWeaponChange;
269}
Note: See TracBrowser for help on using the repository browser.