Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Merge_HS18/src/modules/flappyorx/FlappyOrxShip.cc @ 12219

Last change on this file since 12219 was 12180, checked in by merholzl, 6 years ago

World Map merging

  • Property svn:eol-style set to native
File size: 5.0 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 *      FLeo Merholz
24 *      Pascal Schärli
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30/**
31    @file FlappyOrxShip.cc
32    @brief Implementation of the FlappyOrxShip class.
33*/
34
35#include "FlappyOrxShip.h"
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "graphics/Camera.h"
39#include "graphics/ParticleSpawner.h"
40#include "worldentities/pawns/SpaceShip.h"
41#include <math.h> 
42#include <ctime>
43
44namespace orxonox
45{
46    RegisterClass(FlappyOrxShip);
47
48    FlappyOrxShip::FlappyOrxShip(Context* context) : SpaceShip(context)
49    {
50        RegisterObject(FlappyOrxShip);
51
52        isFlapping = false;
53        isDead = true;
54        velocity = 0;
55        speed = 0;
56        upwardThrust = 0;
57        gravity = 0;
58        particleLifespan = 0.1;
59        particleAge = 0;
60        deathTime = 0;
61
62        particlespawner_ = NULL;
63       
64    }
65
66    void FlappyOrxShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
67    {   
68        SUPER(FlappyOrxShip, XMLPort, xmlelement, mode);
69        XMLPortParam(FlappyOrxShip,"speedBase", setSpeedBase, getSpeedBase, xmlelement,mode);
70        XMLPortParam(FlappyOrxShip,"speedIncrease", setSpeedIncrease, getSpeedIncrease, xmlelement,mode);
71        XMLPortParam(FlappyOrxShip,"tubeDistanceBase", setTubeDistanceBase, getTubeDistanceBase, xmlelement,mode);
72        XMLPortParam(FlappyOrxShip,"tubeDistanceIncrease", setTubeDistanceIncrease, getTubeDistanceIncrease, xmlelement,mode);
73
74        XMLPortParam(FlappyOrxShip,"upwardThrust", setUpwardthrust, getUpwardthrust, xmlelement,mode);
75        XMLPortParam(FlappyOrxShip,"gravity", setGravity, getGravity, xmlelement,mode);
76    }
77
78    void FlappyOrxShip::tick(float dt)
79    {
80        SUPER(FlappyOrxShip, tick, dt);
81
82
83        particleAge+=dt;
84        //the particle spawner that generates the fire from the backpack when pressed
85        if (particlespawner_ == NULL) {
86            for (WorldEntity* object : this->getAttachedObjects())
87            {
88                if (object->isA(Class(ParticleSpawner)))
89                particlespawner_ = (ParticleSpawner*) object;
90            }
91        }
92        else if(particleAge>particleLifespan){
93            particlespawner_->setLifetime(1);
94        }
95
96
97        //Execute movement
98        if (this->hasLocalController())
99        {
100            if(getHealth()<0){
101                setHealth(1);
102                getGame()->death();
103                death();   
104            }
105            Vector3 pos = getPosition();
106
107            getGame()->updatePlayerPos(pos.x);
108           
109
110            if(not isDead){
111                velocity += gravity*dt;
112                if(isFlapping){
113                    isFlapping = false;
114                    if(pos.z > -150)
115                        velocity = -upwardThrust;
116                }
117
118                pos += Vector3(speed, 0, velocity) * dt;
119            }
120           
121                       
122            // Camera
123            Camera* camera = this->getCamera();
124            if (camera != nullptr)
125            {
126                camera->setPosition(pos.x,-100,0);
127                camera->setOrientation(Vector3::UNIT_Z, Degree(0));
128
129            }
130
131           
132            setPosition(pos);
133            setOrientation(Vector3::UNIT_Y, Degree(270-velocity/10));
134
135            if(pos.z > 150){
136                getGame()->death();
137                death();
138            }
139           
140        }
141    }
142
143    time_t FlappyOrxShip::timeUntilRespawn(){
144        return 2-time(0)+deathTime;
145    }
146
147    void FlappyOrxShip::boost(bool boost){
148
149        if(not isDead){
150            particleAge = 0;
151        } 
152   
153        if(isDead&&timeUntilRespawn()<=0){
154            isDead = false;
155            getGame()->setDead(false);
156        }
157        isFlapping=boost;
158    }
159
160 
161    FlappyOrx* FlappyOrxShip::getGame()
162    {
163        if (game == nullptr)
164        {
165            for (FlappyOrx* flappyOrx : ObjectList<FlappyOrx>())
166                game = flappyOrx;
167        }
168        return game;
169    }
170
171    void FlappyOrxShip::death()
172    {
173        isDead = true;
174
175        deathTime = time(0);
176        Vector3 pos = getPosition();
177        pos.x = 0;
178        pos.z = 0;
179        pos.y = 0;
180        velocity = 0;
181        setPosition(pos);
182    }
183}
Note: See TracBrowser for help on using the repository browser.