Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

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