Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/src/modules/asteroids2D/Asteroids2DShip.cc @ 12112

Last change on this file since 12112 was 11781, checked in by landauf, 7 years ago

eol-style native (no changes in code)

  • Property svn:eol-style set to native
File size: 3.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 *      Viviane Yang
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/*  TODO:
30
31    @file Asteroids2DShip.cc
32    @brief Implementation of the Asteroids2DShip class.
33*/
34
35#include "Asteroids2DShip.h"
36#include "Asteroids2DStone.h"
37#include "Asteroids2D.h"
38#include "core/CoreIncludes.h"
39
40namespace orxonox
41{
42    RegisterClass(Asteroids2DShip);
43
44    Asteroids2DShip::Asteroids2DShip(Context* context) : SpaceShip(context)
45    {
46        RegisterObject(Asteroids2DShip);
47
48        this->bImmune = false;
49        this->width = 1043;
50        this->height = 646;
51
52        //timer.setTimer(3.5f, true, createExecutor(createFunctor(&Asteroids2DShip::showorientation, this)));
53    }
54
55    //Use this function to display your position on the field -> to determine field width and height
56    void Asteroids2DShip::showposition()
57    {
58        Vector3 pos = this->getPosition();
59        orxout() << "x = "<< pos.x << " y = " << pos.y << " z = "<< pos.z << endl; 
60    }
61
62    //Same thing for orientation
63    void Asteroids2DShip::showorientation()
64    {
65        Quaternion ort = this->getOrientation();
66        orxout() << "w = " << ort.w << " x = " << ort.x << " y = " << ort.y << "z = " << ort.z << endl;
67    }
68
69    void Asteroids2DShip::tick(float dt)
70    {
71        SUPER(Asteroids2DShip, tick, dt);
72        Vector3 pos = this->getPosition();
73
74        //ensure that the ship stays in playing field
75        if(pos.x > width/2)   pos.x = -width/2;
76        if(pos.x < -width/2)  pos.x = width/2;
77        if(pos.z > height/2)  pos.z = -height/2;
78        if(pos.z < -height/2) pos.z = height/2;
79
80        //2D movement, position should always = 0 on y-axis
81        if(pos.y!=0) pos.y = 0;
82        this->setPosition(pos);
83
84
85        //if you hit an asteroid, the ship will turn -> you need to reorientate the ship
86        Quaternion ort = this->getOrientation();
87        ort.x = 0;
88        ort.z = 0;
89        this->setOrientation(ort);
90    }
91
92    void Asteroids2DShip::boost(bool bBoost)
93    {
94    }
95
96    void Asteroids2DShip::updateLevel()
97    {
98        if (getGame())
99            getGame()->levelUp();
100    }
101
102    inline bool Asteroids2DShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
103    {
104
105        Asteroids2DStone* stone = orxonox_cast<Asteroids2DStone*>(otherObject);       
106        if(stone != nullptr && !bImmune)
107        {
108            removeHealth(100); 
109            this->getGame()->addPoints(10);
110
111            //The ship will be immune for 3 seconds after it has been hit by an asteroid
112            bImmune = true;
113            isimmune.setTimer(3.0f, false, createExecutor(createFunctor(&Asteroids2DShip::toggleImmune, this)));
114        }
115        return false;
116    }
117
118    Asteroids2D* Asteroids2DShip::getGame()
119    {
120        if (game == nullptr)
121        {
122            for (Asteroids2D* race : ObjectList<Asteroids2D>())
123            {
124                game = race;
125            }
126        }
127        return game;
128    }
129
130    void Asteroids2DShip::death()
131    {
132        getGame()->costLife();
133        SpaceShip::death();
134    }
135}
Note: See TracBrowser for help on using the repository browser.