Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: working on keymapping, there are some problems in genericaly map unknown keys to well undefined functions… which is not very surprising :)

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