Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: ok… forces now apply to the right objects, but i don't really like the way it works…. we will see….

File size: 7.1 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*/
[4397]41Player::Player() : WorldEntity(), PhysicsInterface(this)
[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  */
[4397]48  this->setClassName("Player");
[3672]49  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
[3585]50  travelSpeed = 15.0;
[3608]51  velocity = new Vector();
[3585]52  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
53  bFire = false;
[3878]54  this->bWeaponChange = false;
[3585]55  acceleration = 10.0;
[3620]56  //weapons:
[3873]57  this->weaponMan = new WeaponManager();
[3980]58  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
[3881]59  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
[3873]60 
[4000]61  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
62  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
[3881]63  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
64  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
[3471]65}
66
67/**
[3544]68   \brief destructs the player, deletes alocated memory
[3471]69*/
70Player::~Player ()
71{
[3620]72  /* do not delete the weapons, they are contained in the pnode tree
73     and will be deleted there.
74     this only frees the memory allocated to save the list.
75  */
[3873]76  delete this->weaponMan;
[3583]77}
[3566]78
[4010]79/**
80   \brief creates a new Player from Xml Data
81   \param root the xml element containing player data
82   
83   \todo add more parameters to load
84*/
[4397]85Player::Player(const TiXmlElement* root) : WorldEntity(root), PhysicsInterface(this)
[4010]86{
[4397]87  this->setClassName("Player");
[4010]88  this->weapons = new tList<Weapon>();
89  this->activeWeapon = NULL;
90  /*
91    this is the debug player - actualy we would have to make a new
92     class derivated from Player for each player. for now, we just use
93     the player.cc for debug also
94  */
95  travelSpeed = 15.0;
96  velocity = new Vector();
97  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
98  bFire = false;
99  this->bWeaponChange = false;
100  acceleration = 10.0;
101  //weapons:
102  this->weaponMan = new WeaponManager();
103  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
104  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
105 
106  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
107  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
108  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
109  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
110}
[3583]111
112/**
113   \brief adds a weapon to the weapon list of player
114   \param weapon to add
115*/
116void Player::addWeapon(Weapon* weapon)
117{
[3878]118  this->weaponMan->addWeapon(weapon);
[3471]119}
120
[3583]121
[3471]122/**
[3583]123   \brief removes a weapon from the player
124   \param weapon to remove
125*/
126void Player::removeWeapon(Weapon* weapon)
127{
[3878]128  this->weaponMan->removeWeapon(weapon);
[3583]129}
130
131
132/**
[3471]133   \brief effect that occurs after the player is spawned
134*/
135void Player::postSpawn ()
136{
[3474]137  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
[3471]138}
139
[3584]140
[3471]141/**
[3584]142   \brief the action occuring if the player left the game
[3471]143*/
[3584]144void Player::leftWorld ()
145{}
[3471]146
[3584]147
148
[3471]149/**
150   \brief if the player is hit, call this function
151   \param weapon hit by this weapon
152   \param loc ??
153*/
[3578]154void Player::hit (WorldEntity* weapon, Vector* loc)
[3471]155{
156}
157
158
159/**
160    \brief Collision with another Entity has this effect
161    \param other the other colider
162    \param ownhitflags ??
163    \param otherhitflags ??
164*/
165void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
166{
167}
168
169
170/**
171   \brief draws the player after transforming him.
172*/
173void Player::draw ()
174{ 
175  glMatrixMode(GL_MODELVIEW);
[3526]176  glPushMatrix();
[3471]177  float matrix[4][4];
178 
179  /* translate */
180  glTranslatef (this->getAbsCoor ().x, 
181                this->getAbsCoor ().y, 
182                this->getAbsCoor ().z);
183  /* rotate */
184  this->getAbsDir ().matrix (matrix);
185  glMultMatrixf((float*)matrix);
186 
187  this->model->draw();
[3526]188  glPopMatrix();
[3750]189
[3877]190  this->weaponMan->draw();
[3471]191}
192
193
194/**
[3584]195   \brief the function called for each passing timeSnap
196   \param time The timespan passed since last update
[3471]197*/
[3584]198void Player::tick (float time)
[3471]199{
[4397]200  printf("%p\n", this);
201  this->getRelCoor().debug();
202 
[3685]203  /* link tick to weapon */
[3877]204  //this->activeWeapon->tick(time);
205  //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
206  this->weaponMan->tick(time);
[3584]207  // player controlled movement
[3620]208  this->move(time);
[3584]209  // weapon system manipulation
[3620]210  this->weapon();
[3471]211}
212
[3584]213
[3471]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
[3966]228  if( this->bUp && this->getRelCoor().x < 20)
[3596]229    accel = accel+(direction*acceleration);
[3966]230  if( this->bDown && this->getRelCoor().x > -5)
[3596]231    accel = accel-(direction*acceleration);
[3966]232  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
[3596]233    accel = accel - (orthDirection*acceleration); 
[3966]234  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
[3596]235    accel = accel + (orthDirection*acceleration);
236  if( this->bAscend )
[3586]237  if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */
[3471]238
239  Vector move = accel * time;
[3811]240  this->shiftCoor (move);
[3471]241}
[3584]242
243
244/**
245   \brief weapon manipulation by the player
246*/
[3620]247void Player::weapon()
[3584]248{
[3618]249  if( this->bFire)
[3584]250    {
[3875]251      this->weaponMan->fire();
[3584]252    }
[3877]253  if( this->bWeaponChange)
[3584]254    {
[3877]255      this->weaponMan->nextWeaponConf();
[3878]256      this->bWeaponChange = false;
[3584]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{
[3585]269  PRINTF(3)("recieved command [%s]\n", cmd->cmd);
[4091]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;
[3584]276}
Note: See TracBrowser for help on using the repository browser.