Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: added the weapon module to the debug system. some minor changes in the weaponmanager

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
61  this->weapons->add(wpRight);
62  this->activeWeapon = wpRight;
63  this->activeWeaponL = wpLeft;
64}
65
66/**
67   \brief destructs the player, deletes alocated memory
68*/
69Player::~Player ()
70{
71  /* do not delete the weapons, they are contained in the pnode tree
72     and will be deleted there.
73     this only frees the memory allocated to save the list.
74  */
75  delete this->weapons;
76  delete this->weaponMan;
77}
78
79
80/**
81   \brief adds a weapon to the weapon list of player
82   \param weapon to add
83*/
84void Player::addWeapon(Weapon* weapon)
85{
86  this->weapons->add(weapon);
87}
88
89
90/**
91   \brief removes a weapon from the player
92   \param weapon to remove
93*/
94void Player::removeWeapon(Weapon* weapon)
95{
96  this->weapons->remove(weapon);
97}
98
99
100/**
101   \brief effect that occurs after the player is spawned
102*/
103void Player::postSpawn ()
104{
105  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
106}
107
108
109/**
110   \brief the action occuring if the player left the game
111*/
112void Player::leftWorld ()
113{}
114
115
116
117/**
118   \brief if the player is hit, call this function
119   \param weapon hit by this weapon
120   \param loc ??
121*/
122void Player::hit (WorldEntity* weapon, Vector* loc)
123{
124}
125
126
127/**
128    \brief Collision with another Entity has this effect
129    \param other the other colider
130    \param ownhitflags ??
131    \param otherhitflags ??
132*/
133void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
134{
135}
136
137
138/**
139   \brief draws the player after transforming him.
140*/
141void Player::draw ()
142{ 
143  glMatrixMode(GL_MODELVIEW);
144  glPushMatrix();
145  float matrix[4][4];
146 
147  /* translate */
148  glTranslatef (this->getAbsCoor ().x, 
149                this->getAbsCoor ().y, 
150                this->getAbsCoor ().z);
151  /* rotate */
152  this->getAbsDir ().matrix (matrix);
153  glMultMatrixf((float*)matrix);
154 
155  this->model->draw();
156  glPopMatrix();
157
158  this->activeWeapon->draw();
159  this->activeWeaponL->draw();
160}
161
162
163/**
164   \brief the function called for each passing timeSnap
165   \param time The timespan passed since last update
166*/
167void Player::tick (float time)
168{
169  /* link tick to weapon */
170  this->activeWeapon->tick(time);
171  this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
172  // player controlled movement
173  this->move(time);
174  // weapon system manipulation
175  this->weapon();
176}
177
178
179/**
180   \brief action if player moves
181   \param time the timeslice since the last frame
182*/
183void Player::move (float time)
184{
185  Vector accel(0.0, 0.0, 0.0);
186  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
187 
188  /* calculate the direction in which the craft is heading  */
189  Vector direction (1.0, 0.0, 0.0);
190  //direction = this->absDirection.apply (direction);
191  Vector orthDirection (0.0, 0.0, 1.0);
192  //orthDirection = orthDirection.cross (direction);
193
194  if( this->bUp && this->getRelCoor()->x < 20)
195    accel = accel+(direction*acceleration);
196  if( this->bDown && this->getRelCoor()->x > -5)
197    accel = accel-(direction*acceleration);
198  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor()->z*2)
199    accel = accel - (orthDirection*acceleration); 
200  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor()->z*2)
201    accel = accel + (orthDirection*acceleration);
202  if( this->bAscend )
203  if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */
204
205  Vector move = accel * time;
206  this->shiftCoor (move);
207}
208
209
210/**
211   \brief weapon manipulation by the player
212*/
213void Player::weapon()
214{
215  if( this->bFire)
216    {
217      //if(this->activeWeapon != NULL)
218      this->activeWeapon->fire();
219      //FIX THIS FIX FIIIIIIIIIIIX
220      this->activeWeaponL->fire();
221    }
222  if( this->bWeaponChange && this->weapons->getSize() > 1)
223    {
224      PRINTF(1)("changing the weapon of the player: deactivate old, activate new\n");
225      this->activeWeapon->deactivate();
226      //this->weapons->enumerate();  FIX: strang weapon change...
227      this->activeWeapon = this->weapons->nextElement(this->activeWeapon);
228      this->activeWeapon->activate();
229    }
230}
231
232
233/**
234   \brief The connection to the command node
235   \param cmd the Command unit from witch to map
236
237   here the commands are mapped to the players movement/weaponary
238*/
239void Player::command (Command* cmd)
240{
241  PRINTF(3)("recieved command [%s]\n", cmd->cmd);
242  if( !strcmp( cmd->cmd, "up")) this->bUp = !cmd->bUp;
243  if( !strcmp( cmd->cmd, "down")) this->bDown = !cmd->bUp;
244  if( !strcmp( cmd->cmd, "left")) this->bLeft = !cmd->bUp;
245  if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp;
246  if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp;
247  if( !strcmp( cmd->cmd, "mode")) this->bWeaponChange = !cmd->bUp;
248}
Note: See TracBrowser for help on using the repository browser.