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 | direction= 0.0f; |
---|
22 | |
---|
23 | isFireing = false; |
---|
24 | damping = 0.90; |
---|
25 | |
---|
26 | lastTimeFront = 0; |
---|
27 | lastTimeLeft = 0; |
---|
28 | lastTime = 0; |
---|
29 | |
---|
30 | height = 600; |
---|
31 | width = 1000; |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | //update coordinates and velocity |
---|
36 | void AsteroidsShip::tick(float dt) |
---|
37 | { |
---|
38 | orxout() << "ich ticke!"<< endl; |
---|
39 | SUPER(AsteroidsShip, tick, dt); |
---|
40 | |
---|
41 | //Movement computation beachte Beschleunigung? |
---|
42 | Vector3 pos = getPosition(); |
---|
43 | Vector3 vel = getVelocity(); |
---|
44 | |
---|
45 | float speed = sqrt(vel.x*vel.x+ vel.z*velo.z); |
---|
46 | |
---|
47 | |
---|
48 | //Daempfung falls das spaceship zu schnell wird |
---|
49 | if(speed > maxspeed) |
---|
50 | { |
---|
51 | vel.x *= maxspeed/speed; |
---|
52 | vel.z *= mayspeed/speed; |
---|
53 | } |
---|
54 | |
---|
55 | if(moveUpPressed_) |
---|
56 | { |
---|
57 | //Gas geben |
---|
58 | vel.x += 1; |
---|
59 | vel.z += 1; |
---|
60 | |
---|
61 | }else if(moveDownPressed_){ |
---|
62 | //Bremsen |
---|
63 | vel.x += 1; |
---|
64 | vel.z += 1; |
---|
65 | }else if(moveLeftPressed_){ |
---|
66 | //rotate left |
---|
67 | }else if (moveRightPressed_){ |
---|
68 | //rotateright |
---|
69 | } |
---|
70 | |
---|
71 | setVelocity(vel); |
---|
72 | |
---|
73 | pos.x += vel.x*dt; |
---|
74 | pos.z += vel.z*dt; |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | //haelt ship innerhalb des Kamerafensters, kommt oben bzw seitlich wieder raus. Man spawnt in (0,0) |
---|
79 | if(pos.x > width/2) pos.x = -width/2; |
---|
80 | if(pos.x < -width/2) pos.x = width/2; |
---|
81 | if(pos.z > height/2) pos.z = -height/2; |
---|
82 | if(pos.z < -height/2) pos.z = height/2; |
---|
83 | |
---|
84 | |
---|
85 | //Schiessen wenn geschossen wurde |
---|
86 | // shoot! |
---|
87 | |
---|
88 | if (isFireing) |
---|
89 | ControllableEntity::fire(0); |
---|
90 | |
---|
91 | |
---|
92 | // bring back on track! |
---|
93 | if(pos.y != 0) |
---|
94 | { |
---|
95 | pos.y = 0; |
---|
96 | } |
---|
97 | |
---|
98 | //Reibung? |
---|
99 | vel.x *= damping; |
---|
100 | vel.y *= damping; |
---|
101 | |
---|
102 | |
---|
103 | setPosition(pos); |
---|
104 | setOrientation(Vector3::UNIT_Y, Degree(direction)); |
---|
105 | |
---|
106 | // Reset key variables |
---|
107 | moveUpPressed_ = false; |
---|
108 | moveDownPressed_ = false; |
---|
109 | moveLeftPressed_ = false; |
---|
110 | moveDownPressed_ = false; |
---|
111 | |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | void AsteroidsShip::moveFrontBack(const Vector2& value) |
---|
116 | { |
---|
117 | if (value.x > 0) |
---|
118 | { |
---|
119 | moveUpPressed_ = true; |
---|
120 | moveDownPressed_ = false |
---|
121 | if(moveUpPressed_) |
---|
122 | { |
---|
123 | orxout() << "up" << endl; |
---|
124 | } |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | moveUpPressed_ = false; |
---|
129 | moveDownPressed_ = true; |
---|
130 | if(moveDownPressed_) |
---|
131 | { |
---|
132 | orxout() << "down" << endl; |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | void AsteroidsShip::moveRightLeft(const Vector2& value) |
---|
138 | { |
---|
139 | if (value.x > 0) |
---|
140 | { |
---|
141 | moveLeftPressed_ = false; |
---|
142 | moveRightPressed_ = true; |
---|
143 | } |
---|
144 | if(moveRightPressed_) |
---|
145 | { |
---|
146 | orxout() << "right" << endl; |
---|
147 | } |
---|
148 | |
---|
149 | else |
---|
150 | { |
---|
151 | moveLeftPressed_ = true; |
---|
152 | moveRightPressed_ = false; |
---|
153 | if(moveLeftPressed_) |
---|
154 | { |
---|
155 | orxout() << "left" << endl; |
---|
156 | } |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
161 | Asteroids* AsteroidsShip::getGame() |
---|
162 | { |
---|
163 | if (game == nullptr) |
---|
164 | { |
---|
165 | for (Asteroids* asteroids : ObjectList<Asteroids>()) |
---|
166 | game = asteroids; |
---|
167 | } |
---|
168 | return game; |
---|
169 | } |
---|
170 | |
---|
171 | void AsteroidsShip::death() |
---|
172 | { |
---|
173 | getGame()->costLife(); |
---|
174 | SpaceShip::death(); |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | } |
---|