Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9869 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 2.5 KB
Line 
1/*
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: Silvan Nellen
13   co-programmer: Benjamin Knecht
14*/
15
16#include "player.h"
17#include "playable.h"
18
19#include "event_handler.h"
20
21#include "state.h"
22#include "util/hud.h"
23
24#include "debug.h"
25
26ObjectListDefinition(Player);
27/**
28 * creates a new Player
29*/
30Player::Player()
31{
32  //  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
33  this->registerObject(this, Player::_objectList);
34
35  PRINTF(4)("PLAYER INIT\n");
36
37  this->playable = NULL;
38  this->_hud.setVisibility(true);
39
40  this->subscribeEvent(ES_GAME, KeyMapper::PEV_CHANGE_SHIP);
41}
42
43
44/**
45 *  destructs the player, deletes alocated memory
46 */
47Player::~Player ()
48{
49  this->setPlayable(NULL);
50}
51
52
53bool Player::setPlayable(Playable* playable)
54{
55  if (this->playable == playable)
56    return false;
57
58  // get out of the current Playable
59  if (this->playable != NULL)
60  {
61    PRINTF(4)("Player gets ejected from Playable\n");
62    this->_hud.setEnergyWidget(NULL);
63    this->_hud.setWeaponManager(NULL);
64
65    Playable* ejectedPlayable = this->playable;
66
67    this->playable = NULL;
68    ejectedPlayable->setPlayer(NULL);
69  }
70
71  if (playable != NULL)
72  {
73    PRINTF(4)("Enter new Playable\n");
74    this->playable = playable;
75    this->_hud.setEnergyWidget(this->playable->getHealthWidget());
76    this->_hud.setWeaponManager(&this->playable->getWeaponManager());
77
78    this->playable->setPlayer(this);
79    return true;
80  }
81
82  if ( playable == NULL )
83    this->playable = NULL;
84
85  return true;
86}
87
88bool Player::eject()
89{
90  return this->setPlayable(NULL);
91}
92
93
94void Player::weaponConfigChanged()
95{
96  this->_hud.updateWeaponManager();
97}
98
99
100void Player::enterNewPlayable()
101{
102  /// FIXME this should be in the ObjectManager
103  for (ObjectList<Playable>::const_iterator node = Playable::objectList().begin();
104       node != Playable::objectList().end();
105       ++node)
106  {
107    if (this->playable != (*node) &&
108        ((*node)->getAbsCoor() - this->playable->getAbsCoor()).len() < ((*node)->getEnterRadius()))
109    {
110
111      this->setPlayable(*(node));
112
113      break;
114    }
115  }
116}
117
118
119void Player::process(const Event &event)
120{
121  if (event.type == KeyMapper::PEV_CHANGE_SHIP && event.bPressed)
122  {
123    this->enterNewPlayable();
124  }
125
126  if (likely(this->playable != NULL))
127    this->playable->process(event);
128}
129
Note: See TracBrowser for help on using the repository browser.