Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: fixed movement bug (was in the lists), modified the player

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