Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3595 was 3590, checked in by bensch, 20 years ago

orxonox/trunk: updated debug.h: now possibility to log per module (compile-time)

  1. write in the cc-file at the beginnig !!BEFORE ANY INCLUDES!!

#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_[MODULENAME]
where [MODULNAME] is a name of a module that can be defined in debug.h

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