Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged branches/particleEngine into the trunk, because of the new vector class
merged with command:
svn merge -r 3922:HEAD particleEngine/ ../trunk/

not merged src/story_entities/world.cc. will do this at a later time (do not forget)

File size: 5.7 KB
RevLine 
[3471]1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer: Christian Meyer
16*/
17
[3590]18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PLAYER
19
[3471]20#include "player.h"
[3596]21
[3620]22#include "track_manager.h"
[3484]23#include "objModel.h"
[3655]24#include "resource_manager.h"
[3583]25#include "weapon.h"
[3620]26#include "test_gun.h"
27#include "world.h"
[3471]28
[3620]29#include "list.h"
30#include "stdincl.h"
31
[3471]32using namespace std;
33
34/**
35   \brief creates a new Player
36   \param isFree if the player is free
37*/
[3620]38Player::Player() : WorldEntity()
[3471]39{
[3620]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  */
[3672]45  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
[3585]46  travelSpeed = 15.0;
[3608]47  velocity = new Vector();
[3585]48  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
49  bFire = false;
[3878]50  this->bWeaponChange = false;
[3585]51  acceleration = 10.0;
[3620]52  //weapons:
[3873]53  this->weaponMan = new WeaponManager();
[3881]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);
[3873]56 
[3878]57  this->weaponMan->addWeapon(wpRight, W_CONFIG0);
58  this->weaponMan->addWeapon(wpLeft, W_CONFIG1);
[3881]59  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
60  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
[3873]61
[3471]62}
63
64/**
[3544]65   \brief destructs the player, deletes alocated memory
[3471]66*/
67Player::~Player ()
68{
[3620]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  */
[3873]73  delete this->weaponMan;
[3583]74}
[3566]75
[3583]76
77/**
78   \brief adds a weapon to the weapon list of player
79   \param weapon to add
80*/
81void Player::addWeapon(Weapon* weapon)
82{
[3878]83  this->weaponMan->addWeapon(weapon);
[3471]84}
85
[3583]86
[3471]87/**
[3583]88   \brief removes a weapon from the player
89   \param weapon to remove
90*/
91void Player::removeWeapon(Weapon* weapon)
92{
[3878]93  this->weaponMan->removeWeapon(weapon);
[3583]94}
95
96
97/**
[3471]98   \brief effect that occurs after the player is spawned
99*/
100void Player::postSpawn ()
101{
[3474]102  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
[3471]103}
104
[3584]105
[3471]106/**
[3584]107   \brief the action occuring if the player left the game
[3471]108*/
[3584]109void Player::leftWorld ()
110{}
[3471]111
[3584]112
113
[3471]114/**
115   \brief if the player is hit, call this function
116   \param weapon hit by this weapon
117   \param loc ??
118*/
[3578]119void Player::hit (WorldEntity* weapon, Vector* loc)
[3471]120{
121}
122
123
124/**
125    \brief Collision with another Entity has this effect
126    \param other the other colider
127    \param ownhitflags ??
128    \param otherhitflags ??
129*/
130void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
131{
132}
133
134
135/**
136   \brief draws the player after transforming him.
137*/
138void Player::draw ()
139{ 
140  glMatrixMode(GL_MODELVIEW);
[3526]141  glPushMatrix();
[3471]142  float matrix[4][4];
143 
144  /* translate */
145  glTranslatef (this->getAbsCoor ().x, 
146                this->getAbsCoor ().y, 
147                this->getAbsCoor ().z);
148  /* rotate */
149  this->getAbsDir ().matrix (matrix);
150  glMultMatrixf((float*)matrix);
151 
152  this->model->draw();
[3526]153  glPopMatrix();
[3750]154
[3877]155  this->weaponMan->draw();
[3471]156}
157
158
159/**
[3584]160   \brief the function called for each passing timeSnap
161   \param time The timespan passed since last update
[3471]162*/
[3584]163void Player::tick (float time)
[3471]164{
[3685]165  /* link tick to weapon */
[3877]166  //this->activeWeapon->tick(time);
167  //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
168  this->weaponMan->tick(time);
[3584]169  // player controlled movement
[3620]170  this->move(time);
[3584]171  // weapon system manipulation
[3620]172  this->weapon();
[3471]173}
174
[3584]175
[3471]176/**
177   \brief action if player moves
178   \param time the timeslice since the last frame
179*/
180void Player::move (float time)
181{
182  Vector accel(0.0, 0.0, 0.0);
183  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
184  /* calculate the direction in which the craft is heading  */
185  Vector direction (1.0, 0.0, 0.0);
186  //direction = this->absDirection.apply (direction);
187  Vector orthDirection (0.0, 0.0, 1.0);
188  //orthDirection = orthDirection.cross (direction);
189
[3966]190  if( this->bUp && this->getRelCoor().x < 20)
[3596]191    accel = accel+(direction*acceleration);
[3966]192  if( this->bDown && this->getRelCoor().x > -5)
[3596]193    accel = accel-(direction*acceleration);
[3966]194  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
[3596]195    accel = accel - (orthDirection*acceleration); 
[3966]196  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
[3596]197    accel = accel + (orthDirection*acceleration);
198  if( this->bAscend )
[3586]199  if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */
[3471]200
201  Vector move = accel * time;
[3811]202  this->shiftCoor (move);
[3471]203}
[3584]204
205
206/**
207   \brief weapon manipulation by the player
208*/
[3620]209void Player::weapon()
[3584]210{
[3618]211  if( this->bFire)
[3584]212    {
[3875]213      this->weaponMan->fire();
[3584]214    }
[3877]215  if( this->bWeaponChange)
[3584]216    {
[3877]217      this->weaponMan->nextWeaponConf();
[3878]218      this->bWeaponChange = false;
[3584]219    }
220}
221
222
223/**
224   \brief The connection to the command node
225   \param cmd the Command unit from witch to map
226
227   here the commands are mapped to the players movement/weaponary
228*/
229void Player::command (Command* cmd)
230{
[3585]231  PRINTF(3)("recieved command [%s]\n", cmd->cmd);
[3584]232  if( !strcmp( cmd->cmd, "up")) this->bUp = !cmd->bUp;
[3764]233  if( !strcmp( cmd->cmd, "down")) this->bDown = !cmd->bUp;
234  if( !strcmp( cmd->cmd, "left")) this->bLeft = !cmd->bUp;
235  if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp;
236  if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp;
[3878]237  if( !strcmp( cmd->cmd, "mode")) if(cmd->bUp) this->bWeaponChange = !this->bWeaponChange;
[3584]238}
Note: See TracBrowser for help on using the repository browser.