Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/ll2trunktemp/src/world_entities/player.cc @ 3989

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

orxonox/branches/ll2trunktemp: some more headers, now the level really gets loaded

File size: 7.2 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
34CREATE_FACTORY(Player);
35
36/**
37   \brief creates a new Player
38   \param isFree if the player is free
39*/
40Player::Player() : WorldEntity()
41{
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  travelSpeed = 15.0;
49  velocity = new Vector();
50  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
51  bFire = false;
52  this->bWeaponChange = false;
53  acceleration = 10.0;
54  //weapons:
55  this->weaponMan = new WeaponManager();
56  Weapon* wpRight = new TestGun(this,Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
57  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
58 
59  this->weaponMan->addWeapon(wpRight, W_CONFIG0);
60  this->weaponMan->addWeapon(wpLeft, W_CONFIG1);
61  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
62  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
63
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   \brief creates a new Player from Xml Data
80   \param root the xml element containing player data
81   
82   \todo add more parameters to load
83*/
84Player::Player(TiXmlElement* root)
85{
86        char* temp;
87        const char* string;
88        string = grabParameter( root, "name");
89        if( string == NULL)
90        {
91                PRINTF0("Player is missing a proper 'name'\n");
92                string = "Unknown";
93                temp = new char[strlen(string + 2)];
94                strcpy( temp, string);
95                this->setName( temp);
96        }
97        else
98        {
99                temp = new char[strlen(string + 2)];
100                strcpy( temp, string);
101                this->setName( temp);
102        }
103       
104        this->model = NULL;
105        string = grabParameter( root, "model");
106        if( string != NULL)
107        this->model = (Model*)ResourceManager::getInstance()->load(string, OBJ, RP_CAMPAIGN);
108        else
109        {
110                PRINTF0("Player is missing a proper 'model'\n");
111        this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
112        }
113        if( this->model == NULL)
114        {
115                PRINTF0("Player model '%s' could not be loaded\n", string);
116        }
117       
118        this->weapons = new tList<Weapon>();
119  this->activeWeapon = NULL;
120  /*
121    this is the debug player - actualy we would have to make a new
122     class derivated from Player for each player. for now, we just use
123     the player.cc for debug also
124  */
125  travelSpeed = 15.0;
126  velocity = new Vector();
127  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
128  bFire = false;
129  acceleration = 10.0;
130  //weapons:
131  Weapon* wp = new TestGun(this, Vector(-1.1, 0.0, 2.6), Quaternion(), 0);
132  this->weapons->add(wp);
133  this->activeWeapon = wp; 
134}
135
136/**
137   \brief adds a weapon to the weapon list of player
138   \param weapon to add
139*/
140void Player::addWeapon(Weapon* weapon)
141{
142  this->weaponMan->addWeapon(weapon);
143}
144
145
146/**
147   \brief removes a weapon from the player
148   \param weapon to remove
149*/
150void Player::removeWeapon(Weapon* weapon)
151{
152  this->weaponMan->removeWeapon(weapon);
153}
154
155
156/**
157   \brief effect that occurs after the player is spawned
158*/
159void Player::postSpawn ()
160{
161  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
162}
163
164
165/**
166   \brief the action occuring if the player left the game
167*/
168void Player::leftWorld ()
169{}
170
171
172
173/**
174   \brief if the player is hit, call this function
175   \param weapon hit by this weapon
176   \param loc ??
177*/
178void Player::hit (WorldEntity* weapon, Vector* loc)
179{
180}
181
182
183/**
184    \brief Collision with another Entity has this effect
185    \param other the other colider
186    \param ownhitflags ??
187    \param otherhitflags ??
188*/
189void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
190{
191}
192
193
194/**
195   \brief draws the player after transforming him.
196*/
197void Player::draw ()
198{ 
199  glMatrixMode(GL_MODELVIEW);
200  glPushMatrix();
201  float matrix[4][4];
202 
203  /* translate */
204  glTranslatef (this->getAbsCoor ().x, 
205                this->getAbsCoor ().y, 
206                this->getAbsCoor ().z);
207  /* rotate */
208  this->getAbsDir ().matrix (matrix);
209  glMultMatrixf((float*)matrix);
210 
211  this->model->draw();
212  glPopMatrix();
213
214  this->weaponMan->draw();
215}
216
217
218/**
219   \brief the function called for each passing timeSnap
220   \param time The timespan passed since last update
221*/
222void Player::tick (float time)
223{
224  /* link tick to weapon */
225  //this->activeWeapon->tick(time);
226  //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
227  //  this->weaponMan->tick(time);
228  // player controlled movement
229  this->move(time);
230  // weapon system manipulation
231  this->weapon();
232}
233
234
235/**
236   \brief action if player moves
237   \param time the timeslice since the last frame
238*/
239void Player::move (float time)
240{
241  Vector accel(0.0, 0.0, 0.0);
242  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
243  /* calculate the direction in which the craft is heading  */
244  Vector direction (1.0, 0.0, 0.0);
245  //direction = this->absDirection.apply (direction);
246  Vector orthDirection (0.0, 0.0, 1.0);
247  //orthDirection = orthDirection.cross (direction);
248
249  if( this->bUp && this->getRelCoor()->x < 20)
250    accel = accel+(direction*acceleration);
251  if( this->bDown && this->getRelCoor()->x > -5)
252    accel = accel-(direction*acceleration);
253  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor()->z*2)
254    accel = accel - (orthDirection*acceleration); 
255  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor()->z*2)
256    accel = accel + (orthDirection*acceleration);
257  if( this->bAscend )
258  if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */
259
260  Vector move = accel * time;
261  this->shiftCoor (move);
262}
263
264
265/**
266   \brief weapon manipulation by the player
267*/
268void Player::weapon()
269{
270  if( this->bFire)
271    {
272      this->weaponMan->fire();
273    }
274  if( this->bWeaponChange)
275    {
276      this->weaponMan->nextWeaponConf();
277      this->bWeaponChange = false;
278    }
279}
280
281
282/**
283   \brief The connection to the command node
284   \param cmd the Command unit from witch to map
285
286   here the commands are mapped to the players movement/weaponary
287*/
288void Player::command (Command* cmd)
289{
290  PRINTF(3)("recieved command [%s]\n", cmd->cmd);
291  if( !strcmp( cmd->cmd, "up")) this->bUp = !cmd->bUp;
292  if( !strcmp( cmd->cmd, "down")) this->bDown = !cmd->bUp;
293  if( !strcmp( cmd->cmd, "left")) this->bLeft = !cmd->bUp;
294  if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp;
295  if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp;
296  if( !strcmp( cmd->cmd, "mode")) if(cmd->bUp) this->bWeaponChange = !this->bWeaponChange;
297}
Note: See TracBrowser for help on using the repository browser.