Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

spawnEnemy und Templates für die 3 Grössen der Asteroiden geschrieben.

File size: 3.8 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 "core/CoreIncludes.h"
40
41namespace orxonox
42{
43    RegisterClass(Asteroids2DShip);
44
45    Asteroids2DShip::Asteroids2DShip(Context* context) : SpaceShip(context)
46    {
47        RegisterObject(Asteroids2DShip);
48
49        speed = 830;
50        isFireing = false;
51        damping = 10;
52        this->width = 1043;
53        this->height = 646;
54
55        timer.setTimer(3.5f, true, createExecutor(createFunctor(&Asteroids2DShip::showposition, this)));
56    }
57
58    //Use this function to display your position on the field -> to determine field width and height
59    void Asteroids2DShip::showposition()
60    {
61        Vector3 pos = this->getPosition();
62        orxout() << "x = "<< pos.x << " y = " << pos.y << " z = "<< pos.z << endl; 
63    }
64
65    void Asteroids2DShip::tick(float dt)
66    {
67        SUPER(Asteroids2DShip, tick, dt);
68        Vector3 pos = this->getPosition();
69
70        //haelt ship innerhalb des Kamerafensters, kommt oben bzw seitlich wieder raus. Man spawnt in (0,0)
71        if(pos.x > width/2)   pos.x = -width/2;
72        if(pos.x < -width/2)  pos.x = width/2;
73        if(pos.z > height/2)  pos.z = -height/2;
74        if(pos.z < -height/2) pos.z = height/2;
75
76        //2D movement, position should always = 0 on y-axis
77        if(pos.y!=0) pos.y = 0;
78        this->setPosition(pos);
79
80        //update level
81
82        //shoot?
83    }
84
85    void Asteroids2DShip::updateLevel()
86    {
87        if (getGame())
88            getGame()->levelUp();
89    }
90
91/*    void Asteroids2DShip::moveFrontBack(const Vector2& value)
92    {
93        //lastTimeFront = 0;
94        //desiredVelocity.y = value.y * speed * 42;
95        orxout() << "FrontBack" << endl;
96        SUPER(Asteroids2DShip, moveFrontBack, value);
97    }
98
99    void Asteroids2DShip::moveRightLeft(const Vector2& value)
100    {
101        //lastTimeLeft = 0;
102        //desiredVelocity.x = value.x * speed;
103        orxout() << "RightLeft" << endl;
104        SUPER(Asteroids2DShip, moveFrontBack, value);       
105    }
106 */
107    void Asteroids2DShip::boost(bool bBoost)
108    {
109        //getGame()->bEndGame = bBoost;
110    }
111
112    inline bool Asteroids2DShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
113    {
114
115        removeHealth(100);
116        this->death();
117        return false;
118    }
119
120    Asteroids2D* Asteroids2DShip::getGame()
121    {
122        if (game == nullptr)
123        {
124            for (Asteroids2D* race : ObjectList<Asteroids2D>())
125            {
126                game = race;
127            }
128        }
129        return game;
130    }
131
132    void Asteroids2DShip::death()
133    {
134        getGame()->costLife();
135        SpaceShip::death();
136    }
137}
Note: See TracBrowser for help on using the repository browser.