Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: Energy→Health

File size: 2.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
19#include "event_handler.h"
20
21
22#include "class_list.h"
23#include "state.h"
24#include "util/hud.h"
25
26using namespace std;
27
28
29/**
30 * creates a new Player
31*/
32Player::Player()
33{
34//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
35  this->setClassID(CL_PLAYER, "Player");
36
37  PRINTF(4)("PLAYER INIT\n");
38
39  this->controllable = NULL;
40  this->hud.show();
41
42  EventHandler::getInstance()->subscribe(this, ES_GAME, SDLK_l);
43}
44
45
46/**
47 *  destructs the player, deletes alocated memory
48 */
49Player::~Player ()
50{
51
52}
53
54
55bool Player::setControllable(Playable* controllable)
56{
57  if(controllable != NULL && controllable->subscribePlayer(this))
58  {
59      this->controllable = controllable;
60      this->hud.setEnergyWidget(this->controllable->getHealthWidget());
61      this->hud.setWeaponManager(this->controllable->getWeaponManager());
62      return true;
63  }
64  else
65    return false;
66}
67
68bool Player::disconnectControllable()
69 {
70   if(this->controllable == NULL) return true;
71
72   if(this->controllable->unsubscribePlayer(this))
73   {
74     this->controllable = NULL;
75     this->hud.setEnergyWidget(NULL);
76     this->hud.setWeaponManager(NULL);
77     return true;
78   }
79   else
80     return false;
81 }
82
83 void Player::weaponConfigChanged()
84 {
85   this->hud.updateWeaponManager();
86 }
87
88 void Player::process(const Event &event)
89 {
90   if (event.type == SDLK_l && event.bPressed)
91   {
92     /// FIXME this should be in the ObjectManager
93     const std::list<BaseObject*>* objectList = ClassList::getList(CL_PLAYABLE);
94     if (objectList != NULL)
95     {
96       list<BaseObject*>::const_iterator node;
97       for (node = objectList->begin(); node != objectList->end(); node++)
98         if (this->controllable != (*node) && (dynamic_cast<PNode*>(*node)->getAbsCoor() - this->controllable->getAbsCoor()).len() < 10.0)
99       {
100
101         this->disconnectControllable();
102         this->setControllable(dynamic_cast<Playable*>(*node));
103
104         break;
105       }
106     }
107   }
108
109   if (likely(this->controllable != NULL))
110     this->controllable->process(event);
111 }
112
Note: See TracBrowser for help on using the repository browser.