Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/christmas_branche/src/world_entities/player.cc @ 6215

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

christmas: changing the ship

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