Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/player.cc @ 10767

Last change on this file since 10767 was 10764, checked in by bknecht, 17 years ago

hud is slowly cooler

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