Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11561 was 11554, checked in by pascscha, 7 years ago

Increasing difficulty

File size: 4.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
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "FlappyOrx.h"
39#include "graphics/Camera.h"
40#include "weapons/projectiles/Projectile.h"
41#include <math.h> 
42
43namespace orxonox
44{
45    RegisterClass(FlappyOrxShip);
46
47    FlappyOrxShip::FlappyOrxShip(Context* context) : SpaceShip(context)
48    {
49        RegisterObject(FlappyOrxShip);
50
51        this->UpwardThrust = 1;
52        this->speed = 1;
53        this->gravity = 1;
54       
55    }
56
57   
58    void FlappyOrxShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
59        {   
60            SUPER(FlappyOrxShip, XMLPort, xmlelement, mode);
61            XMLPortParam(FlappyOrxShip, "speed", setSpeed, getSpeed, xmlelement, mode);
62            XMLPortParam(FlappyOrxShip, "UpwardThrust", setUpwardThrust, getUpwardThrust, xmlelement, mode);
63            XMLPortParam(FlappyOrxShip, "gravity", setGravity, getGravity, xmlelement, mode);
64    }
65
66    void FlappyOrxShip::tick(float dt)
67    {
68        SUPER(FlappyOrxShip, tick, dt);
69        //Execute movement
70        if (this->hasLocalController())
71        {
72            if(getHealth()<0){
73                setHealth(1);
74                getGame()->death();
75                death();   
76            }
77            Vector3 pos = getPosition();
78
79            getGame()->updatePlayerPos(pos.x);
80           
81
82            velocity.y += gravity*dt;
83            if(isFlapping){
84                isFlapping = false;
85                if(pos.z > -150)
86                    velocity.y = -UpwardThrust;
87            }
88
89            pos += Vector3(speed + velocity.x, 0, velocity.y) * dt;
90           
91
92           
93            // Camera
94            Camera* camera = this->getCamera();
95            if (camera != nullptr)
96            {
97                //camera->setPosition(Vector3(-pos.z, -pos.y, 0));
98                camera->setPosition(pos.x,-100,0);
99                camera->setOrientation(Vector3::UNIT_Z, Degree(0));
100
101            }
102
103           
104            setPosition(pos);
105            setOrientation(Vector3::UNIT_Y, Degree(270-velocity.y/10));
106
107            if(pos.z > 150){
108                getGame()->death();
109                death();
110            }
111           
112        }
113    }
114
115    void FlappyOrxShip::updateLevel()
116    {
117        if (getGame())
118            getGame()->levelUp();
119    }
120
121    void FlappyOrxShip::moveFrontBack(const Vector2& value)
122    {
123
124    }
125
126    void FlappyOrxShip::moveRightLeft(const Vector2& value){}
127
128    void FlappyOrxShip::boost(bool boost){
129        isFlapping=boost;
130    }
131
132    void FlappyOrxShip::rotateRoll(const Vector2& value)
133    {
134        if (getGame())
135            if (getGame()->bEndGame)
136                getGame()->end();
137    }
138
139    FlappyOrx* FlappyOrxShip::getGame()
140    {
141        if (game == nullptr)
142        {
143            for (FlappyOrx* flappyOrx : ObjectList<FlappyOrx>())
144                game = flappyOrx;
145        }
146        return game;
147    }
148
149    void FlappyOrxShip::death()
150    {
151        Vector3 pos = getPosition();
152        pos.x = 0;
153        pos.z = 0;
154        pos.y = 0;
155        velocity.y = 0;
156        setPosition(pos);
157        usleep(1000u);
158    }
159}
Note: See TracBrowser for help on using the repository browser.