Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: weapon animation not realy nice but working now.. :)

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