Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc @ 11620

Last change on this file since 11620 was 11620, checked in by pascscha, 6 years ago

XML Port

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