Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/physics/src/world_entities/player.cc @ 4283

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

orxonox/branches/physics: merged the trunk back to branches/physics
merged with command
svn merge -r 4223:HEAD ../../trunk/ .
conflicts additively included

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