Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9802 was 9793, checked in by zifloria, 11 years ago

movement code update

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/**
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
39namespace orxonox
40{
41    RegisterClass(InvaderShip);
42
43    /**
44    @brief
45        Constructor. Registers and initializes the object.
46    */
47    InvaderShip::InvaderShip(Context* context) : SpaceShip(context)
48    {
49        RegisterObject(InvaderShip);
50
51        speed = 500;
52        isFireing = false;
53        damping = 10;
54    }
55
56    void InvaderShip::tick(float dt)
57    {
58        Vector3 pos = getPosition();
59
60        //Movement calculation
61        lastTimeFront += dt * damping;
62        lastTimeLeft += dt * damping;
63        lastTime += dt;
64
65        velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
66        velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
67
68        //Execute movement
69        if (this->hasLocalController())
70        {
71            float dist_y = velocity.y * dt;
72            if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
73                posforeward += dist_y;
74            else
75                velocity.y = 0;
76            // this->setVelocity(Vector3(1000 + velocity.y, 0, velocity.x));
77            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
78        }
79
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            // orxout() << "asbhajskjasjahg" << pos << endl;
90        }
91
92
93
94        // bring back on track!
95        if (pos.z > 42*2.5)
96            pos.z = 42*2.5;
97        else if (pos.z < -42*3)
98            pos.z = -42*3;
99        if(pos.y != 0)
100            pos.y = 0;
101        // if (camera != NULL)
102        // {
103        //     float x = camera->getWorldPosition().x;
104        //     if (pos.x > x + 20)
105        //         pos.x = x + 20;
106        //     else if (pos.x < x - 20)
107        //         pos.x = x - 20;
108        // }
109        // if (abs(posforeward) < 20)
110           
111
112        setPosition(pos);
113        setOrientation(Vector3::UNIT_Y, Degree(270));
114
115        // Level up!
116        if (pos.x > 30000)
117        {
118            updateLevel();
119            setPosition(Vector3(0, 0, 0)); // pos - Vector3(30000, 0, 0)
120        }
121
122        SUPER(InvaderShip, tick, dt);
123    }
124
125    void InvaderShip::updateLevel()
126    {
127        lastTime = 0;
128        //level++
129    }
130
131    void InvaderShip::moveFrontBack(const Vector2& value)
132    {
133        lastTimeLeft = 0;
134        desiredVelocity.x = -value.x * speed;
135    }
136
137    void InvaderShip::moveRightLeft(const Vector2& value)
138    {
139        lastTimeFront = 0;
140        desiredVelocity.y = value.y * speed * 42;
141    }
142    void InvaderShip::boost(bool bBoost)
143    {
144        isFireing = bBoost;
145    }
146}
Note: See TracBrowser for help on using the repository browser.