Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.cc @ 11660

Last change on this file since 11660 was 11660, checked in by vyang, 6 years ago

Projektile fliegen in 2D Ebene, jedoch in eine falsche Richtung. Kommentare hinzugefuegt

File size: 3.7 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 *      Viviane Yang
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/*  TODO:
30
31/**
32    @file Asteroids2DShip.cc
33    @brief Implementation of the Asteroids2DShip class.
34*/
35
36#include "Asteroids2DShip.h"
37#include "Asteroids2DStone.h"
38#include "core/CoreIncludes.h"
39
40namespace orxonox
41{
42    RegisterClass(Asteroids2DShip);
43
44    Asteroids2DShip::Asteroids2DShip(Context* context) : SpaceShip(context)
45    {
46        RegisterObject(Asteroids2DShip);
47
48        speed = 830;
49        isFireing = false;
50        damping = 10;
51        this->width = 1043;
52        this->height = 646;
53
54        //timer.setTimer(3.5f, true, createExecutor(createFunctor(&Asteroids2DShip::showorientation, this)));
55    }
56
57    //Use this function to display your position on the field -> to determine field width and height
58    void Asteroids2DShip::showposition()
59    {
60        Vector3 pos = this->getPosition();
61        orxout() << "x = "<< pos.x << " y = " << pos.y << " z = "<< pos.z << endl; 
62    }
63
64    //Same thing for orientation
65    void Asteroids2DShip::showorientation()
66    {
67        Quaternion ort = this->getOrientation();
68        orxout() << "w = " << ort.w << " x = " << ort.x << " y = " << ort.y << "z = " << ort.z << endl;
69    }
70
71    void Asteroids2DShip::tick(float dt)
72    {
73        SUPER(Asteroids2DShip, tick, dt);
74        Vector3 pos = this->getPosition();
75
76        //ensure that the ship stays in playing field
77        if(pos.x > width/2)   pos.x = -width/2;
78        if(pos.x < -width/2)  pos.x = width/2;
79        if(pos.z > height/2)  pos.z = -height/2;
80        if(pos.z < -height/2) pos.z = height/2;
81
82        //2D movement, position should always = 0 on y-axis
83        if(pos.y!=0) pos.y = 0;
84        this->setPosition(pos);
85
86
87
88        //shoot?
89    }
90
91    void Asteroids2DShip::boost(bool bBoost)
92    {
93        isFireing = bBoost;
94    }
95
96    void Asteroids2DShip::updateLevel()
97    {
98        if (getGame())
99            getGame()->levelUp();
100    }
101
102    inline bool Asteroids2DShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
103    {
104
105        Asteroids2DStone* stone = orxonox_cast<Asteroids2DStone*>(otherObject);       
106        if(stone != nullptr && !bImmune)
107        {
108            removeHealth(100); 
109            this->getGame()->addPoints(10);
110
111            //The ship will be immune for 3 seconds after it has been hit by an asteroid
112            bImmune = true;
113            isimmune.setTimer(3.0f, false, createExecutor(createFunctor(&Asteroids2DShip::toggleImmune, this)));
114        }
115        return false;
116    }
117
118    Asteroids2D* Asteroids2DShip::getGame()
119    {
120        if (game == nullptr)
121        {
122            for (Asteroids2D* race : ObjectList<Asteroids2D>())
123            {
124                game = race;
125            }
126        }
127        return game;
128    }
129
130    void Asteroids2DShip::death()
131    {
132        getGame()->costLife();
133        SpaceShip::death();
134    }
135}
Note: See TracBrowser for help on using the repository browser.