Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Slots are now PNodes

File size: 6.5 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/**
[4885]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:
[4953]48  Weapon* wpRight = new TestGun(0);
49  Weapon* wpLeft = new TestGun(1);
[4592]50
[4951]51  this->weaponMan->addWeapon(wpRight);
[4910]52//  this->weaponMan->addWeapon(wpLeft, WM_CONFIG1, WM_SLOT1);
53//  this->weaponMan->addWeapon(wpRight, WM_CONFIG2);
54//  this->weaponMan->addWeapon(wpLeft, WM_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:
[4953]82  Weapon* wpRight = new TestGun(0);
83  wpRight->setName("testGun Right");
84  Weapon* wpLeft = new TestGun(1);
85  wpLeft->setName("testGun Left");
[4592]86
[4953]87  this->weaponMan->addWeapon(wpLeft, 1, 0);
88  this->weaponMan->addWeapon(wpRight,1 ,1);
89  this->weaponMan->addWeapon(wpLeft, 3, 1);
90
91  this->weaponMan->changeWeaponConfig(0);
[4010]92}
[3583]93
[4780]94/**
95 * initializes a Player
96 */
97void Player::init()
98{
99  this->setClassID(CL_PLAYER, "Player");
[4404]100
[4951]101//  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
[4780]102  travelSpeed = 15.0;
103  velocity = new Vector();
104  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
105  bFire = false;
106  this->bWeaponChange = false;
107  acceleration = 10.0;
[4834]108
109
[4953]110  this->weaponMan = new WeaponManager(this);
111  this->weaponMan->setSlotPosition(0, Vector(-2.6, .1, -3.0));
112  this->weaponMan->setSlotPosition(1, Vector(-2.6, .1, 3.0));
113
[4780]114}
115
116
[3583]117/**
[4885]118 * loads the Settings of a Player from an XML-element.
[4780]119 * @param root the XML-element to load the Player's properties from
120 */
121void Player::loadParams(const TiXmlElement* root)
122{
123  static_cast<WorldEntity*>(this)->loadParams(root);
124
125
126
127}
128
129
130/**
[4885]131 * adds a weapon to the weapon list of player
[4836]132 * @param weapon to add
[3583]133*/
134void Player::addWeapon(Weapon* weapon)
135{
[3878]136  this->weaponMan->addWeapon(weapon);
[3471]137}
138
[3583]139
[3471]140/**
[4836]141 *  removes a weapon from the player
142 * @param weapon to remove
[3583]143*/
144void Player::removeWeapon(Weapon* weapon)
145{
[3878]146  this->weaponMan->removeWeapon(weapon);
[3583]147}
148
149
150/**
[4836]151 *  effect that occurs after the player is spawned
[3471]152*/
153void Player::postSpawn ()
154{
[3474]155  //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
[3471]156}
157
[3584]158
[3471]159/**
[4836]160 *  the action occuring if the player left the game
[3471]161*/
[3584]162void Player::leftWorld ()
163{}
[3471]164
[3584]165
166
[3471]167/**
[4836]168 *  if the player is hit, call this function
169 * @param weapon hit by this weapon
170 * @param loc ??
[3471]171*/
[3578]172void Player::hit (WorldEntity* weapon, Vector* loc)
[3471]173{
174}
175
176
[4592]177/**
[4836]178  *  Collision with another Entity has this effect
179  * @param other the other colider
180  * @param ownhitflags ??
181  * @param otherhitflags ??
[3471]182*/
183void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags)
184{
185}
186
187
188/**
[4836]189 *  draws the player after transforming him.
[3471]190*/
191void Player::draw ()
[4592]192{
[3471]193  glMatrixMode(GL_MODELVIEW);
[3526]194  glPushMatrix();
[3471]195  float matrix[4][4];
[4592]196
[3471]197  /* translate */
[4592]198  glTranslatef (this->getAbsCoor ().x,
199                this->getAbsCoor ().y,
200                this->getAbsCoor ().z);
[3471]201  /* rotate */
202  this->getAbsDir ().matrix (matrix);
203  glMultMatrixf((float*)matrix);
[4592]204
[3471]205  this->model->draw();
[3526]206  glPopMatrix();
[3750]207
[3877]208  this->weaponMan->draw();
[3471]209}
210
211
212/**
[4836]213 *  the function called for each passing timeSnap
214 * @param time The timespan passed since last update
[3471]215*/
[3584]216void Player::tick (float time)
[3471]217{
[4885]218  // player controlled movement
219  this->move(time);
[4592]220
[3877]221  this->weaponMan->tick(time);
[3584]222  // weapon system manipulation
[4885]223  this->weaponAction();
[3471]224}
225
[3584]226
[3471]227/**
[4836]228 *  action if player moves
229 * @param time the timeslice since the last frame
[3471]230*/
231void Player::move (float time)
232{
233  Vector accel(0.0, 0.0, 0.0);
234  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
235  /* calculate the direction in which the craft is heading  */
236  Vector direction (1.0, 0.0, 0.0);
237  //direction = this->absDirection.apply (direction);
238  Vector orthDirection (0.0, 0.0, 1.0);
239  //orthDirection = orthDirection.cross (direction);
240
[3966]241  if( this->bUp && this->getRelCoor().x < 20)
[3596]242    accel = accel+(direction*acceleration);
[3966]243  if( this->bDown && this->getRelCoor().x > -5)
[4412]244    accel = accel -(direction*acceleration);
[3966]245  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
[4592]246    accel = accel - (orthDirection*acceleration);
[3966]247  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
[4413]248    accel = accel + (orthDirection*acceleration);
[4885]249  if( this->bAscend ) { /* FIXME */ }
[4836]250  if( this->bDescend) {/* FIXME */} /* @todo up and down player movement */
[3471]251
252  Vector move = accel * time;
[3811]253  this->shiftCoor (move);
[3471]254}
[3584]255
256
257/**
[4885]258 * weapon manipulation by the player
[3584]259*/
[4885]260void Player::weaponAction()
[3584]261{
[3618]262  if( this->bFire)
[3584]263    {
[3875]264      this->weaponMan->fire();
[3584]265    }
[3877]266  if( this->bWeaponChange)
[3584]267    {
[3877]268      this->weaponMan->nextWeaponConf();
[3878]269      this->bWeaponChange = false;
[3584]270    }
271}
272
273/**
[4781]274 * @todo switch statement ??
275 */
[4404]276void Player::process(const Event &event)
277{
[4409]278  if( event.type == KeyMapper::PEV_UP)
279      this->bUp = event.bPressed;
280  else if( event.type == KeyMapper::PEV_DOWN)
281      this->bDown = event.bPressed;
282  else if( event.type == KeyMapper::PEV_RIGHT)
[4413]283      this->bRight= event.bPressed;
[4409]284  else if( event.type == KeyMapper::PEV_LEFT)
[4413]285      this->bLeft = event.bPressed;
[4412]286  else if( event.type == KeyMapper::PEV_FIRE1)
[4885]287      this->bFire = event.bPressed;
[4952]288  else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
289    this->weaponMan->nextWeaponConf();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
290  else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
291    this->weaponMan->previousWeaponConfig();
[4404]292}
Note: See TracBrowser for help on using the repository browser.