Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: gun can be fired, projectil do not move jet

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