Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11682 was 11635, checked in by merholzl, 7 years ago

small changes

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