Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.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: 4.3 KB
Line 
1/*   ORXONOX - the hottest 3D action shooter ever to exist
2 *                    > www.orxonox.net <
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Viviane Yang
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28
29
30/**
31    @file Asteroids2DStone.cc
32
33    @brief Implementation of the Asteroids2DStone class.
34
35    TO DO: 
36    - instead of moving over the boarders of the playing field, modify the tick function so that the stones bounce back
37    - when to split? It does not work if you override kill() function...->damage() function?
38*/ 
39
40#include "Asteroids2DStone.h"
41#include "Asteroids2D.h"
42#include "Asteroids2DShip.h"
43#include "core/CoreIncludes.h"
44#include "util/Math.h"
45
46namespace orxonox
47{
48    RegisterClass(Asteroids2DStone);
49
50    Asteroids2DStone::Asteroids2DStone(Context* context) : Pawn(context)
51    {
52        RegisterObject(Asteroids2DStone);
53        this->size = rand()%3+1;
54        this->width = 1043;
55        this->height = 646;
56        this->setPosition(randomPosition(this->width, this->height));
57        this->setCollisionTypeStr("dynamic");
58        this->setVelocity(randomVelocity(MAX_SPEED));
59    }
60
61    Asteroids2DStone::Asteroids2DStone(Context* c, int sze, Vector3 pos) : Pawn(c)
62    {
63        RegisterObject(Asteroids2DStone);
64        this->size = sze;
65        this->width = 1043;
66        this->height = 646;
67        this->setPosition(pos);
68        this->setCollisionTypeStr("dynamic");
69        this->setVelocity(randomVelocity(MAX_SPEED));
70    }
71
72    Vector3 Asteroids2DStone::randomPosition(float maxwidth, float maxheight)
73    {
74        Vector3 pos;
75        pos.x = rnd(-maxwidth/2, maxwidth/2);
76        pos.y = 0;
77        pos.z = rnd(-maxheight/2, maxheight/2);
78        return pos;
79    }
80
81    Vector3 Asteroids2DStone::randomVelocity(float maxspeed)
82    {
83        Vector3 vel;
84        vel.x = rnd(maxspeed);
85        vel.y = 0;
86        vel.z = rnd(maxspeed);
87        return vel;
88    }
89
90
91    void Asteroids2DStone::tick(float dt)
92    {
93        SUPER(Asteroids2DStone, tick, dt);
94        Vector3 pos = this->getPosition();
95
96
97        if(pos.x >= width/2){
98            pos.x = -width/2;
99        }else if(pos.x <= -width/2){
100            pos.x = -width/2;
101        }else if(pos.z >= height/2){
102            pos.z = -height/2;
103        }else if(pos.z <= -height/2){
104            pos.z = -width/2;
105        }
106
107        this->setPosition(pos);
108
109    }
110
111    inline bool Asteroids2DStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
112    {
113        orxout() << "AsteroidStone getroffen" << endl;
114        if(orxonox_cast<Asteroids2DShip*>(otherObject))
115        {
116            orxout() << "getroffen von Ship" << endl;
117            split();
118        }
119        return false;
120    }
121
122    void Asteroids2DStone::split()
123    {
124        orxout() << "split" << endl;
125        if(size == 1)
126        {
127            this->death();
128
129        }else if(size == 2){
130
131
132            //Templates can be found in data/levels/templates/asteroidsAsteroids2D.oxt
133            Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 1, this->getPosition());
134            newStone1->addTemplate("stone1");
135            Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 1, this->getPosition());
136            newStone2->addTemplate("stone1");
137           
138        }else{
139            Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 2, this->getPosition());
140            newStone1->addTemplate("stone1");
141            Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 2, this->getPosition());
142            newStone2->addTemplate("stone1");
143        }
144    }
145
146}
Note: See TracBrowser for help on using the repository browser.