Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/world_entities/player.cc @ 6375

Last change on this file since 6375 was 6234, checked in by snellen, 19 years ago

playable.cc and space_ship.cc updated

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