Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/invaders/src/modules/invader/InvaderShip.cc @ 9874

Last change on this file since 9874 was 9874, checked in by zifloria, 10 years ago

best game eva

File size: 5.0 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/**
30    @file InvaderShip.cc
31    @brief Implementation of the InvaderShip class.
32*/
33
34#include "InvaderShip.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "Invader.h"
39
40namespace orxonox
41{
42    RegisterClass(InvaderShip);
43
44    InvaderShip::InvaderShip(Context* context) : SpaceShip(context)
45    {
46        RegisterObject(InvaderShip);
47
48        speed = 500;
49        isFireing = false;
50        damping = 10;
51    }
52
53    void InvaderShip::tick(float dt)
54    {
55        Vector3 pos = getPosition();
56
57        //Movement calculation
58        lastTimeFront += dt * damping;
59        lastTimeLeft += dt * damping;
60        lastTime += dt;
61
62        velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
63        velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
64
65        //Execute movement
66        if (this->hasLocalController())
67        {
68            float dist_y = velocity.y * dt;
69            float dist_x = velocity.x * dt;
70            if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
71                posforeward += dist_y;
72            else
73                velocity.y = 0;
74            if (pos.z + dist_x > 42*2.5 || pos.z + dist_x < -42*3)
75                velocity.x = 0;
76            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
77        }
78
79        // shoot!
80        if (isFireing)
81            ControllableEntity::fire(0);
82
83        // Camera
84        Camera* camera = this->getCamera();
85        if (camera != NULL)
86        {
87            camera->setPosition(Vector3(-pos.z, -posforeward, 0));
88            camera->setOrientation(Vector3::UNIT_Z, Degree(90));
89        }
90
91
92
93        // bring back on track!
94        if(pos.y != 0)
95            pos.y = 0;
96
97        setPosition(pos);
98        setOrientation(Vector3::UNIT_Y, Degree(270));
99
100        // Level up!
101        if (pos.x > 42000)
102        {
103            updateLevel();
104            setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)
105        }
106
107        SUPER(InvaderShip, tick, dt);
108    }
109
110    void InvaderShip::updateLevel()
111    {
112        lastTime = 0;
113        if (getGame())
114            getGame()->levelUp();
115    }
116
117    void InvaderShip::moveFrontBack(const Vector2& value)
118    {
119        lastTimeLeft = 0;
120        desiredVelocity.x = -value.x * speed;
121    }
122
123    void InvaderShip::moveRightLeft(const Vector2& value)
124    {
125        lastTimeFront = 0;
126        desiredVelocity.y = value.y * speed * 42;
127    }
128    void InvaderShip::boost(bool bBoost)
129    {
130        isFireing = bBoost;
131        // restart if game ended
132        if (getGame())
133            if (getGame()->bEndGame)
134                getGame()->start();
135    }
136    inline bool InvaderShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
137    {
138        // orxout() << "touch!!! " << endl; //<< otherObject << " at " << contactPoint;
139        WeakPtr<InvaderEnemy> enemy = orxonox_cast<InvaderEnemy*>(otherObject);
140        WeakPtr<Projectile> shot = orxonox_cast<Projectile*>(otherObject);
141        // ensure that this gets only called once per enemy.
142        if (enemy != NULL && lastEnemy != enemy)
143        {
144            lastEnemy = enemy;
145
146            removeHealth(20);
147            if (getGame())
148            {
149                getGame()->multiplier = 1;                   
150            }
151        }
152        // was shot, decrease multiplier
153        else if (shot != NULL  && lastShot != shot)
154        {
155            if (getGame() && orxonox_cast<InvaderEnemy*>(shot->getShooter()) != NULL)
156            {
157                if (getGame()->multiplier > 1)
158                {
159                    lastShot = shot;
160                    getGame()->multiplier -= 1;     
161                }
162            }
163        }
164        return false;
165        // SUPER(InvaderShip, collidesAgainst, otherObject, contactPoint);
166    }
167
168    WeakPtr<Invader> InvaderShip::getGame()
169    {
170        if (game == NULL)
171        {
172            for (ObjectList<Invader>::iterator it = ObjectList<Invader>::begin(); it != ObjectList<Invader>::end(); ++it)
173                game = *it;
174        }
175        return game;
176    }
177
178    void InvaderShip::death()
179    {
180        getGame()->costLife();
181        SpaceShip::death();
182    }
183}
Note: See TracBrowser for help on using the repository browser.