Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Asteroiden werden generiert und bewegen sich, HUD muss noch angepasst werden, Punkte und Health und Leben anzeigen. Raumschiff kann noch nicht schiessen, evtl auch Schutzfunktion → nachdem ein Leben verloren wurde 2s Immunitaet?

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/*TODO: orientation/direction of the ship must be defined
30        implement shoot function ->or switch it on?
31        switch off boosting particles in the back of the ship
32
33/**
34    @file Asteroids2DShip.cc
35    @brief Implementation of the Asteroids2DShip class.
36*/
37
38#include "Asteroids2DShip.h"
39#include "Asteroids2DStone.h"
40#include "core/CoreIncludes.h"
41
42namespace orxonox
43{
44    RegisterClass(Asteroids2DShip);
45
46    Asteroids2DShip::Asteroids2DShip(Context* context) : SpaceShip(context)
47    {
48        RegisterObject(Asteroids2DShip);
49
50        speed = 830;
51        isFireing = false;
52        damping = 10;
53        this->width = 1043;
54        this->height = 646;
55
56        timer.setTimer(3.5f, true, createExecutor(createFunctor(&Asteroids2DShip::showposition, this)));
57    }
58
59    //Use this function to display your position on the field -> to determine field width and height
60    void Asteroids2DShip::showposition()
61    {
62        Vector3 pos = this->getPosition();
63        orxout() << "x = "<< pos.x << " y = " << pos.y << " z = "<< pos.z << endl; 
64    }
65
66    void Asteroids2DShip::tick(float dt)
67    {
68        SUPER(Asteroids2DShip, tick, dt);
69        Vector3 pos = this->getPosition();
70
71        //haelt ship innerhalb des Kamerafensters, kommt oben bzw seitlich wieder raus. Man spawnt in (0,0)
72        if(pos.x > width/2)   pos.x = -width/2;
73        if(pos.x < -width/2)  pos.x = width/2;
74        if(pos.z > height/2)  pos.z = -height/2;
75        if(pos.z < -height/2) pos.z = height/2;
76
77        //2D movement, position should always = 0 on y-axis
78        if(pos.y!=0) pos.y = 0;
79        this->setPosition(pos);
80
81        //update level
82
83        //shoot?
84    }
85
86    void Asteroids2DShip::updateLevel()
87    {
88        if (getGame())
89            getGame()->levelUp();
90    }
91
92    void Asteroids2DShip::boost(bool bBoost)
93    {
94        //getGame()->bEndGame = bBoost;
95    }
96
97    inline bool Asteroids2DShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
98    {
99        removeHealth(100);
100        getGame()->addPoints(10);
101        return false;
102    }
103
104    Asteroids2D* Asteroids2DShip::getGame()
105    {
106        if (game == nullptr)
107        {
108            for (Asteroids2D* race : ObjectList<Asteroids2D>())
109            {
110                game = race;
111            }
112        }
113        return game;
114    }
115
116    void Asteroids2DShip::death()
117    {
118        getGame()->costLife();
119        SpaceShip::death();
120    }
121}
Note: See TracBrowser for help on using the repository browser.