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
Line 
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
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PLAYER
19
20#include "player.h"
21
22#include "track_manager.h"
23#include "objModel.h"
24#include "resource_manager.h"
25#include "weapon.h"
26#include "test_gun.h"
27#include "world.h"
28
29#include "list.h"
30#include "stdincl.h"
31
32using namespace std;
33
34/**
35   \brief creates a new Player
36   \param isFree if the player is free
37*/
38Player::Player() : WorldEntity()
39{
40  this->weapons = new tList<Weapon>();
41  this->activeWeapon = NULL;
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  */
47  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
48  //this->model = (Model*)ResourceManager::getInstance()->load("models/weapon_packet.obj", OBJ, RP_CAMPAIGN);
49  travelSpeed = 15.0;
50  velocity = new Vector();
51  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
52  bFire = false;
53  acceleration = 10.0;
54  //weapons:
55  this->weaponMan = new WeaponManager();
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);
58 
59  this->weaponMan->addWeapon(wpRight);
60  this->weaponMan->addWeapon(wpLeft);
61
62  //this->weapons->add(wpRight);
63  //this->activeWeapon = wpRight;
64  //this->activeWeaponL = wpLeft;
65}
66
67/**
68   \brief destructs the player, deletes alocated memory
69*/
70Player::~Player ()
71{
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  */
76  delete this->weapons;
77  delete this->weaponMan;
78}
79
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);
88}
89
90
91/**
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/**
102   \brief effect that occurs after the player is spawned
103*/
104void Player::postSpawn ()
105{
106  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
107}
108
109
110/**
111   \brief the action occuring if the player left the game
112*/
113void Player::leftWorld ()
114{}
115
116
117
118/**
119   \brief if the player is hit, call this function
120   \param weapon hit by this weapon
121   \param loc ??
122*/
123void Player::hit (WorldEntity* weapon, Vector* loc)
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);
145  glPushMatrix();
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();
157  glPopMatrix();
158
159  //this->activeWeapon->draw();
160  //this->activeWeaponL->draw();
161  this->weaponMan->draw();
162}
163
164
165/**
166   \brief the function called for each passing timeSnap
167   \param time The timespan passed since last update
168*/
169void Player::tick (float time)
170{
171  /* link tick to weapon */
172  //this->activeWeapon->tick(time);
173  //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
174  this->weaponMan->tick(time);
175  // player controlled movement
176  this->move(time);
177  // weapon system manipulation
178  this->weapon();
179}
180
181
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
196  if( this->bUp && this->getRelCoor()->x < 20)
197    accel = accel+(direction*acceleration);
198  if( this->bDown && this->getRelCoor()->x > -5)
199    accel = accel-(direction*acceleration);
200  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor()->z*2)
201    accel = accel - (orthDirection*acceleration); 
202  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor()->z*2)
203    accel = accel + (orthDirection*acceleration);
204  if( this->bAscend )
205  if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */
206
207  Vector move = accel * time;
208  this->shiftCoor (move);
209}
210
211
212/**
213   \brief weapon manipulation by the player
214*/
215void Player::weapon()
216{
217  if( this->bFire)
218    {
219      this->weaponMan->fire();
220    }
221  if( this->bWeaponChange)
222    {
223      //this->activeWeapon->deactivate();
224      //this->weapons->enumerate();  FIX: strang weapon change...
225      //this->activeWeapon = this->weapons->nextElement(this->activeWeapon);
226      //this->activeWeapon->activate();
227      this->weaponMan->nextWeaponConf();
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{
240  PRINTF(3)("recieved command [%s]\n", cmd->cmd);
241  if( !strcmp( cmd->cmd, "up")) this->bUp = !cmd->bUp;
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;
247}
Note: See TracBrowser for help on using the repository browser.