Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: finished work on pnode interface

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