Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/miniprojects/src/orxonox/objects/gametypes/Pong.cc @ 2825

Last change on this file since 2825 was 2825, checked in by landauf, 15 years ago

eol-style:native

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "Pong.h"
31
32#include "core/CoreIncludes.h"
33#include "core/ConfigValueIncludes.h"
34#include "core/Executor.h"
35#include "objects/worldentities/Model.h"
36#include "objects/worldentities/PongCenterpoint.h"
37#include "objects/worldentities/PongBall.h"
38#include "objects/worldentities/PongBat.h"
39#include "objects/infos/PlayerInfo.h"
40
41namespace orxonox
42{
43    CreateUnloadableFactory(Pong);
44
45    Pong::Pong(BaseObject* creator) : Deathmatch(creator)
46    {
47        RegisterObject(Pong);
48
49        this->center_ = 0;
50        this->ball_ = 0;
51        this->bat_[0] = 0;
52        this->bat_[1] = 0;
53
54        this->bForceSpawn_ = true;
55
56        this->starttimer_.setTimer(1.0, false, this, createExecutor(createFunctor(&Pong::startBall)));
57        this->starttimer_.stopTimer();
58    }
59
60    void Pong::start()
61    {
62        if (this->center_)
63        {
64            if (!this->ball_)
65            {
66                this->ball_ = new PongBall(this->center_);
67                this->ball_->addTemplate(this->center_->getBalltemplate());
68            }
69
70            this->center_->attach(this->ball_);
71            this->ball_->setPosition(0, 0, 0);
72            this->ball_->setFieldDimension(this->center_->getFieldDimension());
73            this->ball_->setSpeed(0);
74            this->ball_->setBatLength(this->center_->getBatLength());
75
76            if (!this->bat_[0])
77            {
78                this->bat_[0] = new PongBat(this->center_);
79                this->bat_[0]->addTemplate(this->center_->getBattemplate());
80            }
81            if (!this->bat_[1])
82            {
83                this->bat_[1] = new PongBat(this->center_);
84                this->bat_[1]->addTemplate(this->center_->getBattemplate());
85            }
86
87            this->center_->attach(this->bat_[0]);
88            this->center_->attach(this->bat_[1]);
89            this->bat_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
90            this->bat_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0);
91            this->bat_[0]->yaw(Degree(-90));
92            this->bat_[1]->yaw(Degree(90));
93            this->bat_[0]->setSpeed(this->center_->getBatSpeed());
94            this->bat_[1]->setSpeed(this->center_->getBatSpeed());
95            this->bat_[0]->setFieldHeight(this->center_->getFieldDimension().y);
96            this->bat_[1]->setFieldHeight(this->center_->getFieldDimension().y);
97            this->bat_[0]->setLength(this->center_->getBatLength());
98            this->bat_[1]->setLength(this->center_->getBatLength());
99
100            this->ball_->setBats(this->bat_);
101        }
102        else
103        {
104            COUT(1) << "Error: No Centerpoint specified." << std::endl;
105        }
106
107        this->starttimer_.startTimer();
108
109        Deathmatch::start();
110    }
111
112    void Pong::end()
113    {
114        if (this->ball_)
115        {
116            delete this->ball_;
117            this->ball_ = 0;
118        }
119
120        Deathmatch::end();
121    }
122
123    void Pong::spawnPlayer(PlayerInfo* player)
124    {
125        if (!this->bat_[0]->getPlayer())
126        {
127            player->startControl(this->bat_[0]);
128            this->players_[player].state_ = PlayerState::Alive;
129        }
130        else if (!this->bat_[1]->getPlayer())
131        {
132            player->startControl(this->bat_[1]);
133            this->players_[player].state_ = PlayerState::Alive;
134        }
135    }
136
137    void Pong::playerScored(PlayerInfo* player)
138    {
139        Deathmatch::playerScored(player);
140
141        if (this->ball_)
142        {
143            this->ball_->setPosition(Vector3::ZERO);
144            this->ball_->setVelocity(Vector3::ZERO);
145            this->ball_->setSpeed(0);
146        }
147
148        if (this->bat_[0] && this->bat_[1])
149        {
150            this->bat_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
151            this->bat_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0);
152        }
153
154        this->starttimer_.startTimer();
155    }
156
157    void Pong::startBall()
158    {
159        if (this->ball_ && this->center_)
160            this->ball_->setSpeed(this->center_->getBallSpeed());
161    }
162}
Note: See TracBrowser for help on using the repository browser.