Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: the player now works entirely with the WeaponManager. much more elegant! but its not yet finished.

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