Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

best game eva

File size: 5.0 KB
RevLine 
[9725]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"
[9829]38#include "Invader.h"
[9725]39
40namespace orxonox
41{
42    RegisterClass(InvaderShip);
43
44    InvaderShip::InvaderShip(Context* context) : SpaceShip(context)
45    {
46        RegisterObject(InvaderShip);
47
48        speed = 500;
[9744]49        isFireing = false;
[9725]50        damping = 10;
51    }
52
53    void InvaderShip::tick(float dt)
54    {
[9793]55        Vector3 pos = getPosition();
[9744]56
[9793]57        //Movement calculation
[9725]58        lastTimeFront += dt * damping;
59        lastTimeLeft += dt * damping;
[9793]60        lastTime += dt;
61
[9725]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
[9793]65        //Execute movement
66        if (this->hasLocalController())
67        {
68            float dist_y = velocity.y * dt;
[9828]69            float dist_x = velocity.x * dt;
[9793]70            if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
71                posforeward += dist_y;
72            else
73                velocity.y = 0;
[9828]74            if (pos.z + dist_x > 42*2.5 || pos.z + dist_x < -42*3)
75                velocity.x = 0;
[9793]76            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
77        }
78
[9868]79        // shoot!
[9725]80        if (isFireing)
81            ControllableEntity::fire(0);
82
[9793]83        // Camera
84        Camera* camera = this->getCamera();
85        if (camera != NULL)
[9777]86        {
[9793]87            camera->setPosition(Vector3(-pos.z, -posforeward, 0));
88            camera->setOrientation(Vector3::UNIT_Z, Degree(90));
[9777]89        }
[9744]90
[9793]91
92
93        // bring back on track!
94        if(pos.y != 0)
95            pos.y = 0;
[9777]96
[9793]97        setPosition(pos);
98        setOrientation(Vector3::UNIT_Y, Degree(270));
[9744]99
[9793]100        // Level up!
[9828]101        if (pos.x > 42000)
[9793]102        {
103            updateLevel();
[9828]104            setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)
[9793]105        }
[9744]106
[9725]107        SUPER(InvaderShip, tick, dt);
108    }
109
[9793]110    void InvaderShip::updateLevel()
111    {
112        lastTime = 0;
[9829]113        if (getGame())
114            getGame()->levelUp();
[9793]115    }
[9777]116
[9725]117    void InvaderShip::moveFrontBack(const Vector2& value)
118    {
[9793]119        lastTimeLeft = 0;
120        desiredVelocity.x = -value.x * speed;
[9725]121    }
122
123    void InvaderShip::moveRightLeft(const Vector2& value)
124    {
[9793]125        lastTimeFront = 0;
126        desiredVelocity.y = value.y * speed * 42;
[9725]127    }
128    void InvaderShip::boost(bool bBoost)
129    {
130        isFireing = bBoost;
[9868]131        // restart if game ended
132        if (getGame())
133            if (getGame()->bEndGame)
134                getGame()->start();
[9725]135    }
[9828]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);
[9874]140        WeakPtr<Projectile> shot = orxonox_cast<Projectile*>(otherObject);
[9868]141        // ensure that this gets only called once per enemy.
[9828]142        if (enemy != NULL && lastEnemy != enemy)
143        {
144            lastEnemy = enemy;
[9868]145
[9828]146            removeHealth(20);
[9868]147            if (getGame())
[9828]148            {
[9874]149                getGame()->multiplier = 1;                   
[9828]150            }
151        }
[9874]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        }
[9828]164        return false;
165        // SUPER(InvaderShip, collidesAgainst, otherObject, contactPoint);
166    }
[9829]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    }
[9874]177
178    void InvaderShip::death()
179    {
180        getGame()->costLife();
181        SpaceShip::death();
182    }
[9725]183}
Note: See TracBrowser for help on using the repository browser.