Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: connected the weapon system to the input_node structure

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