Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DStone.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: 4.1 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 *      Samuel Riedel
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28/**
29    @file Asteroids2DStone.cc
30    @brief Implementation of the Asteroids2DStone class.
31*/
32
33#include "Asteroids2DStone.h"
34#include "Asteroids2D.h"
35#include "Asteroids2DShip.h"
36#include "core/CoreIncludes.h"
37#include "util/Math.h"
38
39namespace orxonox
40{
41    RegisterClass(Asteroids2DStone);
42
43    Asteroids2DStone::Asteroids2DStone(Context* context) : Pawn(context)
44    {
45        RegisterObject(Asteroids2DStone);
46        this->size = rand()%3+1;
47        this->width = 1043;
48        this->height = 646;
49        this->setPosition(randomPosition(this->width, this->height));
50        this->setCollisionTypeStr("dynamic");
51        this->setVelocity(randomVelocity(MAX_SPEED));
52    }
53
54    Asteroids2DStone::Asteroids2DStone(Context* c, int sze, Vector3 pos) : Pawn(c)
55    {
56        RegisterObject(Asteroids2DStone);
57        this->size = sze;
58        this->width = 1043;
59        this->height = 646;
60        this->setPosition(pos);
61        this->setCollisionTypeStr("dynamic");
62        this->setVelocity(randomVelocity(MAX_SPEED));
63    }
64
65    Vector3 Asteroids2DStone::randomPosition(float maxwidth, float maxheight)
66    {
67        Vector3 pos;
68        pos.x = rnd(-maxwidth/2, maxwidth/2);
69        pos.y = 0;
70        pos.z = rnd(-maxheight/2, maxheight/2);
71        return pos;
72    }
73
74    Vector3 Asteroids2DStone::randomVelocity(float maxspeed)
75    {
76        Vector3 vel;
77        vel.x = rnd(maxspeed);
78        vel.y = 0;
79        vel.z = rnd(maxspeed);
80        return vel;
81    }
82
83
84    void Asteroids2DStone::tick(float dt)
85    {
86        SUPER(Asteroids2DStone, tick, dt);
87        Vector3 pos = this->getPosition();
88
89        if(pos.x >= width/2){
90            pos.x = -width/2;
91        }else if(pos.x <= -width/2){
92            pos.x = -width/2;
93        }else if(pos.z >= height/2){
94            pos.z = -height/2;
95        }else if(pos.z <= -height/2){
96            pos.z = -width/2;
97        }
98
99        this->setPosition(pos);
100
101    }
102
103    inline bool Asteroids2DStone::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
104    {
105        if(orxonox_cast<Asteroids2DShip*>(otherObject))
106        {
107            this->split();
108        }
109        return false;
110    }
111
112    void Asteroids2DStone::split()
113    {
114        if(size == 1)
115        {
116            this->death();
117
118        }else if(size == 2){
119            Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 1, this->getPosition());
120            newStone1->addTemplate("stone1");
121            Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 1, this->getPosition());
122            newStone2->addTemplate("stone1");
123        }else{
124            Asteroids2DStone* newStone1 = new Asteroids2DStone(this->getContext(), 2, this->getPosition());
125            newStone1->addTemplate("stone1");
126            Asteroids2DStone* newStone2 = new Asteroids2DStone(this->getContext(), 2, this->getPosition());
127            newStone2->addTemplate("stone1");
128        }
129    }
130
131
132
133
134    //Overload kill function to generate 2 asteriods
135    /*void Asteroids2DStone::kill()
136    {
137        this->damage(this->health)
138        if(this->size < 1)
139        {
140            this->death();
141        }else{
142            size -= 1;
143
144        }
145
146
147    }*/
148
149
150}
Note: See TracBrowser for help on using the repository browser.