Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: widget war

File size: 2.2 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{
[4780]34  this->init();
[6222]35
36  EventHandler::getInstance()->subscribe(this, ES_GAME, SDLK_l);
[3471]37}
38
[4975]39
[4010]40/**
[4975]41 *  destructs the player, deletes alocated memory
42 */
43Player::~Player ()
44{
45}
46
[5395]47
[4975]48/**
[4780]49 * initializes a Player
50 */
51void Player::init()
52{
[5037]53//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
[4780]54  this->setClassID(CL_PLAYER, "Player");
[5144]55
[5300]56  PRINTF(4)("PLAYER INIT\n");
[4834]57
[5915]58  this->controllable = NULL;
[6438]59  this->hud = new Hud();
[4780]60}
61
62
[5915]63bool Player::setControllable(Playable* controllable)
[4780]64{
[5915]65  if(controllable != NULL && controllable->subscribePlayer(this))
[5435]66  {
[5915]67      this->controllable = controllable;
68      return true;
[5751]69  }
[5915]70  else
71    return false;
[3471]72}
[3584]73
[5915]74bool Player::disconnectControllable()
75 {
76   if(this->controllable == NULL) return true;
[3584]77
[5915]78   if(this->controllable->unsubscribePlayer(this))
79   {
80     this->controllable = NULL;
81     return true;
82   }
83   else
84     return false;
85 }
[3584]86
[5915]87 void Player::process(const Event &event)
88 {
[6222]89   if (event.type == SDLK_l && event.bPressed)
90   {
91     /// FIXME this should be in the ObjectManager
92     const std::list<BaseObject*>* objectList = ClassList::getList(CL_PLAYABLE);
93     if (objectList != NULL)
94     {
95       list<BaseObject*>::const_iterator node;
96       for (node = objectList->begin(); node != objectList->end(); node++)
97         if (this->controllable != (*node) && (dynamic_cast<PNode*>(*node)->getAbsCoor() - this->controllable->getAbsCoor()).len() < 10.0)
98       {
[6438]99
[6222]100         this->disconnectControllable();
101         this->setControllable(dynamic_cast<Playable*>(*node));
102
103         break;
104       }
105     }
106   }
107
[5915]108   if (likely(this->controllable != NULL))
109     this->controllable->process(event);
110 }
[5751]111
Note: See TracBrowser for help on using the repository browser.