Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/weaponSystem/src/world_entities/player.cc @ 4882

Last change on this file since 4882 was 4878, checked in by bensch, 19 years ago

orxonox/branches/weaponSystem: some definitions of the Weapon

File size: 6.3 KB
RevLine 
[4592]1/*
[3471]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: Christian Meyer
14*/
15
[3590]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PLAYER
17
[3471]18#include "player.h"
[3596]19
[3620]20#include "track_manager.h"
[3484]21#include "objModel.h"
[3655]22#include "resource_manager.h"
[4826]23
24#include "weapon_manager.h"
[3620]25#include "test_gun.h"
26#include "world.h"
[3471]27
[3620]28#include "list.h"
29
[4404]30#include "event_handler.h"
[4389]31
[4404]32#include "event.h"
[4287]33
[4780]34
[3471]35using namespace std;
36
[4010]37CREATE_FACTORY(Player);
38
[3471]39/**
[4877]40 * creates a new Player
[4836]41 * @param isFree if the player is free
[3471]42*/
[4762]43Player::Player()
[3471]44{
[4780]45  this->init();
[4597]46
[3620]47  //weapons:
[3980]48  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
[3881]49  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
[4592]50
[4000]51  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
52  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
[3881]53  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
54  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
[3471]55}
56
[4404]57
[3471]58/**
[4836]59 *  destructs the player, deletes alocated memory
[3471]60*/
61Player::~Player ()
62{
[3620]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  */
[3873]67  delete this->weaponMan;
[3583]68}
[3566]69
[4010]70/**
[4836]71 *  creates a new Player from Xml Data
72 * @param root the xml element containing player data
[4592]73
[4836]74   @todo add more parameters to load
[4010]75*/
[4780]76Player::Player(const TiXmlElement* root)
[4010]77{
[4780]78  this->init();
79  this->loadParams(root);
[4597]80
[4010]81  //weapons:
82  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
83  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
[4592]84
[4010]85  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
86  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
87  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
88  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
89}
[3583]90
[4780]91/**
92 * initializes a Player
93 */
94void Player::init()
95{
96  this->setClassID(CL_PLAYER, "Player");
[4404]97
[4780]98  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
99  travelSpeed = 15.0;
100  velocity = new Vector();
101  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
102  bFire = false;
103  this->bWeaponChange = false;
104  acceleration = 10.0;
[4834]105
106
107  this->weaponMan = new WeaponManager();
[4780]108}
109
110
[3583]111/**
[4877]112 * loads the Settings of a Player from an XML-element.
[4780]113 * @param root the XML-element to load the Player's properties from
114 */
115void Player::loadParams(const TiXmlElement* root)
116{
117  static_cast<WorldEntity*>(this)->loadParams(root);
118
119
120
121}
122
123
124/**
[4877]125 * adds a weapon to the weapon list of player
[4836]126 * @param weapon to add
[3583]127*/
128void Player::addWeapon(Weapon* weapon)
129{
[3878]130  this->weaponMan->addWeapon(weapon);
[3471]131}
132
[3583]133
[3471]134/**
[4836]135 *  removes a weapon from the player
136 * @param weapon to remove
[3583]137*/
138void Player::removeWeapon(Weapon* weapon)
139{
[3878]140  this->weaponMan->removeWeapon(weapon);
[3583]141}
142
143
144/**
[4836]145 *  effect that occurs after the player is spawned
[3471]146*/
147void Player::postSpawn ()
148{
[3474]149  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
[3471]150}
151
[3584]152
[3471]153/**
[4836]154 *  the action occuring if the player left the game
[3471]155*/
[3584]156void Player::leftWorld ()
157{}
[3471]158
[3584]159
160
[3471]161/**
[4836]162 *  if the player is hit, call this function
163 * @param weapon hit by this weapon
164 * @param loc ??
[3471]165*/
[3578]166void Player::hit (WorldEntity* weapon, Vector* loc)
[3471]167{
168}
169
170
[4592]171/**
[4836]172  *  Collision with another Entity has this effect
173  * @param other the other colider
174  * @param ownhitflags ??
175  * @param otherhitflags ??
[3471]176*/
177void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
178{
179}
180
181
182/**
[4836]183 *  draws the player after transforming him.
[3471]184*/
185void Player::draw ()
[4592]186{
[3471]187  glMatrixMode(GL_MODELVIEW);
[3526]188  glPushMatrix();
[3471]189  float matrix[4][4];
[4592]190
[3471]191  /* translate */
[4592]192  glTranslatef (this->getAbsCoor ().x,
193                this->getAbsCoor ().y,
194                this->getAbsCoor ().z);
[3471]195  /* rotate */
196  this->getAbsDir ().matrix (matrix);
197  glMultMatrixf((float*)matrix);
[4592]198
[3471]199  this->model->draw();
[3526]200  glPopMatrix();
[3750]201
[3877]202  this->weaponMan->draw();
[3471]203}
204
205
206/**
[4836]207 *  the function called for each passing timeSnap
208 * @param time The timespan passed since last update
[3471]209*/
[3584]210void Player::tick (float time)
[3471]211{
[4877]212  // player controlled movement
213  this->move(time);
[4592]214
[3877]215  this->weaponMan->tick(time);
[3584]216  // weapon system manipulation
[4877]217  this->weaponAction();
[3471]218}
219
[3584]220
[3471]221/**
[4836]222 *  action if player moves
223 * @param time the timeslice since the last frame
[3471]224*/
225void Player::move (float time)
226{
227  Vector accel(0.0, 0.0, 0.0);
228  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
229  /* calculate the direction in which the craft is heading  */
230  Vector direction (1.0, 0.0, 0.0);
231  //direction = this->absDirection.apply (direction);
232  Vector orthDirection (0.0, 0.0, 1.0);
233  //orthDirection = orthDirection.cross (direction);
234
[3966]235  if( this->bUp && this->getRelCoor().x < 20)
[3596]236    accel = accel+(direction*acceleration);
[3966]237  if( this->bDown && this->getRelCoor().x > -5)
[4412]238    accel = accel -(direction*acceleration);
[3966]239  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
[4592]240    accel = accel - (orthDirection*acceleration);
[3966]241  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
[4413]242    accel = accel + (orthDirection*acceleration);
[4878]243  if( this->bAscend ) { /* FIXME */ }
[4836]244  if( this->bDescend) {/* FIXME */} /* @todo up and down player movement */
[3471]245
246  Vector move = accel * time;
[3811]247  this->shiftCoor (move);
[3471]248}
[3584]249
250
251/**
[4878]252 * weapon manipulation by the player
[3584]253*/
[4877]254void Player::weaponAction()
[3584]255{
[3618]256  if( this->bFire)
[3584]257    {
[3875]258      this->weaponMan->fire();
[3584]259    }
[3877]260  if( this->bWeaponChange)
[3584]261    {
[3877]262      this->weaponMan->nextWeaponConf();
[3878]263      this->bWeaponChange = false;
[3584]264    }
265}
266
267/**
[4781]268 * @todo switch statement ??
269 */
[4404]270void Player::process(const Event &event)
271{
[4409]272  if( event.type == KeyMapper::PEV_UP)
273      this->bUp = event.bPressed;
274  else if( event.type == KeyMapper::PEV_DOWN)
275      this->bDown = event.bPressed;
276  else if( event.type == KeyMapper::PEV_RIGHT)
[4413]277      this->bRight= event.bPressed;
[4409]278  else if( event.type == KeyMapper::PEV_LEFT)
[4413]279      this->bLeft = event.bPressed;
[4412]280  else if( event.type == KeyMapper::PEV_FIRE1)
[4878]281      this->bFire = event.bPressed;
[4412]282  else if( event.type == KeyMapper::PEV_NEXT_WEAPON)
283      if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
[4404]284
285}
Note: See TracBrowser for help on using the repository browser.