Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: weapon now works perfectly: it shoots and moves to it. now i will have to change the projectile model itself….

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