Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3879 was 3878, checked in by patrick, 20 years ago

orxonox/trunk: the weaponconfiguration can now be changed by pressing the 'm' key.

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