Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

MoveUpDown

File size: 3.3 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
42namespace orxonox
43{
44    RegisterClass(FlappyOrxShip);
45
46    FlappyOrxShip::FlappyOrxShip(Context* context) : SpaceShip(context)
47    {
48        RegisterObject(FlappyOrxShip);
49
50        UpwardThrust = 250;
51        speed = 50;
52        gravity = 20;
53    }
54
55    void FlappyOrxShip::tick(float dt)
56    {  //Execute movement
57        if (this->hasLocalController())
58        {
59           
60            Vector3 pos = getPosition();
61            velocity.y += gravity;
62            if(isFlapping){
63                isFlapping = false;
64                velocity.y = -UpwardThrust;
65            }
66
67           
68            pos += Vector3(speed + velocity.x, 0, velocity.y) * dt;
69           
70            if(pos.z < -150 || pos.z > 150){
71                pos.z=0;
72                velocity.y = 0;
73            }
74           
75            // restart if game ended
76            if (getGame())
77                if (getGame()->bEndGame)
78                {
79                    getGame()->start();
80                    return;
81                }
82           
83            // Camera
84            Camera* camera = this->getCamera();
85            if (camera != nullptr)
86            {
87                camera->setPosition(Vector3(-pos.z, -pos.y, 0));
88                camera->setOrientation(Vector3::UNIT_Z, Degree(90));
89            }
90
91
92
93            setPosition(pos);
94            setOrientation(Vector3::UNIT_Y, Degree(270));
95           
96        }
97
98        SUPER(FlappyOrxShip, tick, dt);
99    }
100
101    void FlappyOrxShip::updateLevel()
102    {
103        if (getGame())
104            getGame()->levelUp();
105    }
106
107    void FlappyOrxShip::moveFrontBack(const Vector2& value)
108    {
109
110    }
111
112    void FlappyOrxShip::moveRightLeft(const Vector2& value){}
113
114    void FlappyOrxShip::boost(bool boost){
115        isFlapping=boost;
116    }
117
118    void FlappyOrxShip::rotateRoll(const Vector2& value)
119    {
120        if (getGame())
121            if (getGame()->bEndGame)
122                getGame()->end();
123    }
124
125    FlappyOrx* FlappyOrxShip::getGame()
126    {
127        if (game == nullptr)
128        {
129            for (FlappyOrx* flappyOrx : ObjectList<FlappyOrx>())
130                game = flappyOrx;
131        }
132        return game;
133    }
134
135    void FlappyOrxShip::death()
136    {
137
138    }
139}
Note: See TracBrowser for help on using the repository browser.