Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4287 was 4287, checked in by patrick, 19 years ago

orxonox/trunk: implemented the objectmanager debug functon, some small fixed in the ol code

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