Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6442 was 6442, checked in by bensch, 20 years ago

Gui Shows weapons (simple)

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