1 | #include "AsteroidsShip.h" |
---|
2 | |
---|
3 | #include "core/CoreIncludes.h" |
---|
4 | #include "core/XMLPort.h" |
---|
5 | #include "Asteroids.h" |
---|
6 | #include "graphics/Camera.h" |
---|
7 | #include "asteroids/AsteroidStone.h" |
---|
8 | #include "weapons/projectiles/Projectile.h" |
---|
9 | #include "asteroids/AsteroidsCenterpoint.h" |
---|
10 | |
---|
11 | |
---|
12 | namespace orxonox |
---|
13 | { |
---|
14 | //Constructor |
---|
15 | RegisterClass(AsteroidsShip); |
---|
16 | |
---|
17 | AsteroidsShip::AsteroidsShip(Context* context) : SpaceShip(context) |
---|
18 | { |
---|
19 | RegisterObject(AsteroidsShip); |
---|
20 | |
---|
21 | angle= 0.0f; |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | isFireing = false; |
---|
26 | damping = 0.90; |
---|
27 | |
---|
28 | lastTimeFront = 0; |
---|
29 | lastTimeLeft = 0; |
---|
30 | lastTime = 0; |
---|
31 | |
---|
32 | height = this->getGame()->center_->getFieldHeight(); |
---|
33 | width = this->getGame()->center_->getFieldWidth(); |
---|
34 | |
---|
35 | force.x =0; |
---|
36 | force.y =0; |
---|
37 | |
---|
38 | velocity.x = 0; |
---|
39 | velocity.y = 0; |
---|
40 | |
---|
41 | } |
---|
42 | |
---|
43 | //Destructor |
---|
44 | AsteroidsShip::~AsteroidsShip() |
---|
45 | { |
---|
46 | if (this->isInitialized()) |
---|
47 | this->cleanup(); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | //update coordinates and velocity |
---|
53 | void AsteroidsShip::tick(float dt) |
---|
54 | { |
---|
55 | //Movement computation beachte Beschleunigung? |
---|
56 | Vector3 pos = getPosition(); |
---|
57 | |
---|
58 | float speed = sqrt(velocity.x*velocity.x+ velocity.y*velocity.y); |
---|
59 | if(speed > maxspeed) |
---|
60 | { |
---|
61 | velocity.x *= maxspeed/speed; |
---|
62 | velocity.y *= mayspeed/speed; |
---|
63 | } |
---|
64 | |
---|
65 | pos.x += velocity.x*dt; |
---|
66 | pos.y += velocity.y*dt; |
---|
67 | |
---|
68 | |
---|
69 | //haelt ship innerhalb des Kamerafensters |
---|
70 | if(x>width) x=0; |
---|
71 | if(x<0) x=width; |
---|
72 | if(y>height) y=0; |
---|
73 | if(y<0) y=height); |
---|
74 | |
---|
75 | |
---|
76 | //Schiessen wenn geschossen wurde |
---|
77 | // shoot! |
---|
78 | /* |
---|
79 | if (isFireing) |
---|
80 | ControllableEntity::fire(0); |
---|
81 | */ |
---|
82 | |
---|
83 | //Execute movement |
---|
84 | if (this->hasLocalController()) |
---|
85 | { |
---|
86 | force.x += 1; |
---|
87 | force.y += 1; |
---|
88 | |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren |
---|
94 | Camera* camera = this->getCamera(); |
---|
95 | if (camera != nullptr) |
---|
96 | { |
---|
97 | camera->setPosition(Vector3(0,cameradistance, 0)); |
---|
98 | camera->setOrientation(Vector3::UNIT_Z, Degree(90)); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | // bring back on track! |
---|
104 | if(pos.y != 0) |
---|
105 | { |
---|
106 | pos.y = 0; |
---|
107 | } |
---|
108 | |
---|
109 | velocity.x *= damping; |
---|
110 | velocity.y *= damping; |
---|
111 | |
---|
112 | setPosition(pos); |
---|
113 | setOrientation(Vector3::UNIT_Y, Degree(270)); |
---|
114 | |
---|
115 | SUPER(AsteroidsShip, tick, dt); |
---|
116 | |
---|
117 | } |
---|
118 | |
---|
119 | void AsteroidsShip::moveFrontBack(const Vector2& value) |
---|
120 | { |
---|
121 | velocity.x += 1; |
---|
122 | } |
---|
123 | |
---|
124 | void AsteroidsShip::moveUpDown(const Vector2& value) |
---|
125 | { |
---|
126 | velocity.y +=1; |
---|
127 | |
---|
128 | } |
---|
129 | void AsteroidsShip::moveFrontLeftRight(const Vector2& value) |
---|
130 | { |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | Asteroids* AsteroidsShip::getGame() |
---|
135 | { |
---|
136 | if (game == nullptr) |
---|
137 | { |
---|
138 | for (Asteroids* asteroids : ObjectList<Asteroids>()) |
---|
139 | game = asteroids; |
---|
140 | } |
---|
141 | return game; |
---|
142 | } |
---|
143 | |
---|
144 | void AsteroidsShip::death() |
---|
145 | { |
---|
146 | getGame()->costLife(); |
---|
147 | SpaceShip::death(); |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | } |
---|