1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.IO; |
---|
4 | using Jypeli; |
---|
5 | using Jypeli.Assets; |
---|
6 | using Jypeli.Controls; |
---|
7 | using Jypeli.Effects; |
---|
8 | using Jypeli.Widgets; |
---|
9 | using ALTK; |
---|
10 | using ALTK.GUI.Dialogs; |
---|
11 | |
---|
12 | public class YAG2DSS : PhysicsGame |
---|
13 | { |
---|
14 | ALTKHandler altkHandler; |
---|
15 | GameObject Kursori; |
---|
16 | |
---|
17 | List<PhysicsObject> Pelaaja = new List<PhysicsObject>(); |
---|
18 | List<PhysicsObject> Madonreika = new List<PhysicsObject>(); |
---|
19 | List<PhysicsObject> Minioni = new List<PhysicsObject>(); |
---|
20 | List<PhysicsObject> Asteroidi = new List<PhysicsObject>(); |
---|
21 | |
---|
22 | Timer MadonreikaAjastin; |
---|
23 | Timer Minioniajastin; |
---|
24 | Timer Minioninliikuttaja; |
---|
25 | Timer Automaattiammus; |
---|
26 | Timer MinioninAmmus; |
---|
27 | Timer Asteroidiajastin; |
---|
28 | Timer TuhoaAsteroidi; |
---|
29 | Timer EnergianLataaja; |
---|
30 | Timer Vaikeuttaja; |
---|
31 | Timer Konekivaari1; |
---|
32 | Timer Konekivaari2; |
---|
33 | Timer Triplefire1; |
---|
34 | Timer Triplefire2; |
---|
35 | |
---|
36 | ExplosionSystem PlayerHitES; |
---|
37 | ExplosionSystem PlayerDeathES; |
---|
38 | ExplosionSystem PlayerDeathESL; |
---|
39 | ExplosionSystem PlayerDeathES2; |
---|
40 | |
---|
41 | ExplosionSystem WormholeExplosionES; |
---|
42 | ExplosionSystem WormholeExplosionES2; |
---|
43 | |
---|
44 | ExplosionSystem MinionExplosionES; |
---|
45 | ExplosionSystem MinionExplosionES2; |
---|
46 | |
---|
47 | ExplosionSystem AsteroidExplosionES; |
---|
48 | ExplosionSystem AsteroidExplosionES2; |
---|
49 | |
---|
50 | double MadonreikaPosX = 0.0; |
---|
51 | double MadonreikaPosY = 0.0; |
---|
52 | |
---|
53 | int Pelaajan1Pisteet = 0; |
---|
54 | int Pelaajan2Pisteet = 0; |
---|
55 | |
---|
56 | |
---|
57 | double Pelaajan1Kerroin = 1.5; |
---|
58 | double Pelaajan2Kerroin = 1.5; |
---|
59 | |
---|
60 | public override void Begin() |
---|
61 | { |
---|
62 | #region Cursor handling |
---|
63 | Kursori = new GameObject(32, 32); |
---|
64 | Kursori.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "cursor.png")); |
---|
65 | Kursori.IsVisible = false; |
---|
66 | AnalogHandler handler = new AnalogHandler(HandleCursor); |
---|
67 | Mouse.ListenMovement(0.1, handler, ""); |
---|
68 | Add(Kursori); |
---|
69 | #endregion |
---|
70 | LuoKentta(); |
---|
71 | AsetaNappaimet(); |
---|
72 | LuoAjastin(); |
---|
73 | //LuoMadonreika(); |
---|
74 | //PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
75 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ShowExit, "Lopeta peli"); |
---|
76 | Explotions(); |
---|
77 | } |
---|
78 | |
---|
79 | void Explotions() |
---|
80 | { |
---|
81 | PlayerHitES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player_explosion.png")), 800); |
---|
82 | PlayerHitES.ScaleAmount = 0.0002; |
---|
83 | PlayerHitES.MaxRotationSpeed = 1000.0; |
---|
84 | PlayerHitES.BlendMode = BlendMode.Alpha; |
---|
85 | PlayerHitES.MinScale = 2.5; |
---|
86 | PlayerHitES.MaxScale = 5.0; |
---|
87 | PlayerHitES.Shape = Shape.Circle; |
---|
88 | PlayerHitES.MinRotationSpeed = 500.0; |
---|
89 | PlayerHitES.AlphaAmount = 1.0; |
---|
90 | PlayerHitES.MinAcceleration = 3.0; |
---|
91 | PlayerHitES.MaxAcceleration = 6.0; |
---|
92 | PlayerHitES.MinVelocity = 10.0; |
---|
93 | PlayerHitES.MaxVelocity = 20.0; |
---|
94 | PlayerHitES.MinLifetime = PlayerHitES.MinLifetime * 0.8; |
---|
95 | PlayerHitES.MaxLifetime = PlayerHitES.MaxLifetime * 0.8; |
---|
96 | Add(PlayerHitES); |
---|
97 | |
---|
98 | PlayerDeathES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player_explosion.png")), 8000); |
---|
99 | PlayerDeathES.ScaleAmount = 0.0002; |
---|
100 | PlayerDeathES.MaxRotationSpeed = 1000.0; |
---|
101 | PlayerDeathES.BlendMode = BlendMode.Alpha; |
---|
102 | PlayerDeathES.MinScale = 2.0; |
---|
103 | PlayerDeathES.MaxScale = 4.0; |
---|
104 | PlayerDeathES.Shape = Shape.Circle; |
---|
105 | PlayerDeathES.MinRotationSpeed = 500.0; |
---|
106 | PlayerDeathES.AlphaAmount = 1.0; |
---|
107 | PlayerDeathES.MinAcceleration = 3.0; |
---|
108 | PlayerDeathES.MaxAcceleration = 6.0; |
---|
109 | PlayerDeathES.MaxVelocity = 100.0; |
---|
110 | PlayerDeathES.MinLifetime = 5.9; |
---|
111 | PlayerDeathES.MaxLifetime = 6.0; |
---|
112 | Add(PlayerDeathES); |
---|
113 | |
---|
114 | PlayerDeathESL = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player_explosion.png")), 16000); |
---|
115 | PlayerDeathESL.ScaleAmount = 0.0002; |
---|
116 | PlayerDeathESL.MaxRotationSpeed = 1000.0; |
---|
117 | PlayerDeathESL.BlendMode = BlendMode.Alpha; |
---|
118 | PlayerDeathESL.MinScale = 1.5; |
---|
119 | PlayerDeathESL.MaxScale = 3.0; |
---|
120 | PlayerDeathESL.Shape = Shape.Circle; |
---|
121 | PlayerDeathESL.MinRotationSpeed = 500.0; |
---|
122 | PlayerDeathESL.AlphaAmount = 1.0; |
---|
123 | PlayerDeathESL.MinAcceleration = 1.5; |
---|
124 | PlayerDeathESL.MaxAcceleration = 3.0; |
---|
125 | PlayerDeathESL.MaxVelocity = 50.0; |
---|
126 | PlayerDeathESL.MinLifetime = 5.9; |
---|
127 | PlayerDeathESL.MaxLifetime = 6.0; |
---|
128 | Add(PlayerDeathESL); |
---|
129 | |
---|
130 | PlayerDeathES2 = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player_explosion.png")), 2800); |
---|
131 | PlayerDeathES2.ScaleAmount = 0.0002; |
---|
132 | PlayerDeathES2.MaxRotationSpeed = 1000.0; |
---|
133 | PlayerDeathES2.BlendMode = BlendMode.Alpha; |
---|
134 | PlayerDeathES2.MinScale = 64.0; |
---|
135 | PlayerDeathES2.MaxScale = 128.0; |
---|
136 | PlayerDeathES2.Shape = Shape.Circle; |
---|
137 | PlayerDeathES2.MinRotationSpeed = 500.0; |
---|
138 | PlayerDeathES2.AlphaAmount = 0.8; |
---|
139 | PlayerDeathES2.MinAcceleration = 0.75; |
---|
140 | PlayerDeathES2.MaxAcceleration = 0.75; |
---|
141 | PlayerDeathES2.MaxVelocity = 12.5; |
---|
142 | PlayerDeathES2.MinLifetime = 5.9; |
---|
143 | PlayerDeathES2.MaxLifetime = 6.0; |
---|
144 | Add(PlayerDeathES2); |
---|
145 | |
---|
146 | MinionExplosionES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_explosion.png")), 5000); |
---|
147 | MinionExplosionES.OuterParticleImage = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_explosion_2.png")); |
---|
148 | MinionExplosionES.ScaleAmount = 0.0002; |
---|
149 | MinionExplosionES.MaxRotationSpeed = 1250.0; |
---|
150 | MinionExplosionES.BlendMode = BlendMode.Alpha; |
---|
151 | MinionExplosionES.MinScale = 2.0; |
---|
152 | MinionExplosionES.MaxScale = 4.0; |
---|
153 | MinionExplosionES.Shape = Shape.Circle; |
---|
154 | MinionExplosionES.MinRotationSpeed = 500.0; |
---|
155 | MinionExplosionES.MinAcceleration = 12.0; |
---|
156 | MinionExplosionES.MaxAcceleration = 24.0; |
---|
157 | MinionExplosionES.MinVelocity = 18.00; |
---|
158 | MinionExplosionES.MaxVelocity = 30.00; |
---|
159 | MinionExplosionES.MaxLifetime = MinionExplosionES.MaxLifetime * 1.00; |
---|
160 | MinionExplosionES.MinLifetime = MinionExplosionES.MinLifetime * 1.00; |
---|
161 | Add(MinionExplosionES); |
---|
162 | |
---|
163 | MinionExplosionES2 = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_explosion.png")), 500); |
---|
164 | MinionExplosionES2.OuterParticleImage = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_explosion_2.png")); |
---|
165 | MinionExplosionES2.ScaleAmount = 0.0002; |
---|
166 | MinionExplosionES2.MaxRotationSpeed = 800.0; |
---|
167 | MinionExplosionES2.BlendMode = BlendMode.Alpha; |
---|
168 | MinionExplosionES2.MinScale = 16.0; |
---|
169 | MinionExplosionES2.MaxScale = 32.0; |
---|
170 | MinionExplosionES2.Shape = Shape.Circle; |
---|
171 | MinionExplosionES2.MinRotationSpeed = 250.0; |
---|
172 | MinionExplosionES2.AlphaAmount = 0.8; |
---|
173 | MinionExplosionES2.MinAcceleration = 3.0; |
---|
174 | MinionExplosionES2.MaxAcceleration = 6.0; |
---|
175 | MinionExplosionES2.MaxVelocity = 18.75; |
---|
176 | MinionExplosionES2.MaxLifetime = MinionExplosionES2.MaxLifetime * 0.65; |
---|
177 | MinionExplosionES2.MinLifetime = MinionExplosionES2.MinLifetime * 0.65; |
---|
178 | Add(MinionExplosionES2); |
---|
179 | |
---|
180 | AsteroidExplosionES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "asteroid_explosion.png")), 2000); |
---|
181 | AsteroidExplosionES.ScaleAmount = 0.0002; |
---|
182 | AsteroidExplosionES.MaxRotationSpeed = 800.0; |
---|
183 | AsteroidExplosionES.BlendMode = BlendMode.Alpha; |
---|
184 | AsteroidExplosionES.MinScale = 4.0; |
---|
185 | AsteroidExplosionES.MaxScale = 8.0; |
---|
186 | AsteroidExplosionES.Shape = Shape.Circle; |
---|
187 | AsteroidExplosionES.MinRotationSpeed = 350.0; |
---|
188 | AsteroidExplosionES.AlphaAmount = 0.8; |
---|
189 | AsteroidExplosionES.MinAcceleration = 6.0; |
---|
190 | AsteroidExplosionES.MaxAcceleration = 12.0; |
---|
191 | AsteroidExplosionES.MinVelocity = 36.75; |
---|
192 | AsteroidExplosionES.MaxVelocity = 55.25; |
---|
193 | AsteroidExplosionES.MaxLifetime = AsteroidExplosionES.MaxLifetime * 0.425; |
---|
194 | AsteroidExplosionES.MinLifetime = AsteroidExplosionES.MinLifetime * 0.425; |
---|
195 | Add(AsteroidExplosionES); |
---|
196 | |
---|
197 | AsteroidExplosionES2 = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "asteroid_explosion.png")), 800); |
---|
198 | AsteroidExplosionES2.ScaleAmount = 0.0002; |
---|
199 | AsteroidExplosionES2.MaxRotationSpeed = 800.0; |
---|
200 | AsteroidExplosionES2.BlendMode = BlendMode.Alpha; |
---|
201 | AsteroidExplosionES2.MinScale = 10.0; |
---|
202 | AsteroidExplosionES2.MaxScale = 18.0; |
---|
203 | AsteroidExplosionES2.Shape = Shape.Circle; |
---|
204 | AsteroidExplosionES2.MinRotationSpeed = 350.0; |
---|
205 | AsteroidExplosionES2.AlphaAmount = 0.8; |
---|
206 | AsteroidExplosionES2.MinAcceleration = 1.5; |
---|
207 | AsteroidExplosionES2.MaxAcceleration = 3.0; |
---|
208 | AsteroidExplosionES2.MinVelocity = 8.75; |
---|
209 | AsteroidExplosionES2.MaxVelocity = 20.25; |
---|
210 | AsteroidExplosionES2.MaxLifetime = AsteroidExplosionES2.MaxLifetime * 1.8; |
---|
211 | AsteroidExplosionES2.MinLifetime = AsteroidExplosionES2.MinLifetime * 1.8; |
---|
212 | Add(AsteroidExplosionES2); |
---|
213 | |
---|
214 | WormholeExplosionES = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole_explosion.png")), 5000); |
---|
215 | WormholeExplosionES.OuterParticleImage = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole_explosion_2.png")); |
---|
216 | WormholeExplosionES.ScaleAmount = 0.0002; |
---|
217 | WormholeExplosionES.MaxRotationSpeed = 1000.0; |
---|
218 | WormholeExplosionES.BlendMode = BlendMode.Alpha; |
---|
219 | WormholeExplosionES.MinScale = 1.5; |
---|
220 | WormholeExplosionES.MaxScale = 5.0; |
---|
221 | WormholeExplosionES.Shape = Shape.Circle; |
---|
222 | WormholeExplosionES.MinRotationSpeed = 500.0; |
---|
223 | WormholeExplosionES.AlphaAmount = 0.5; |
---|
224 | WormholeExplosionES.MinAcceleration = 6.0; |
---|
225 | WormholeExplosionES.MaxAcceleration = 12.0; |
---|
226 | WormholeExplosionES.MaxVelocity = 125.0; |
---|
227 | Add(WormholeExplosionES); |
---|
228 | |
---|
229 | WormholeExplosionES2 = new ExplosionSystem(Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole_explosion.png")), 5000); |
---|
230 | WormholeExplosionES2.OuterParticleImage = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole_explosion_2.png")); |
---|
231 | WormholeExplosionES2.ScaleAmount = 0.0002; |
---|
232 | WormholeExplosionES2.MaxRotationSpeed = 1000.0; |
---|
233 | WormholeExplosionES2.BlendMode = BlendMode.Alpha; |
---|
234 | WormholeExplosionES2.MinScale = 16.0; |
---|
235 | WormholeExplosionES2.MaxScale = 32.0; |
---|
236 | WormholeExplosionES2.Shape = Shape.Circle; |
---|
237 | WormholeExplosionES2.MinRotationSpeed = 500.0; |
---|
238 | WormholeExplosionES2.AlphaAmount = 0.5; |
---|
239 | WormholeExplosionES2.MinAcceleration = 6.0; |
---|
240 | WormholeExplosionES2.MaxAcceleration = 12.0; |
---|
241 | WormholeExplosionES2.MaxVelocity = 85.0; |
---|
242 | Add(WormholeExplosionES2); |
---|
243 | } |
---|
244 | |
---|
245 | void LuoKentta() |
---|
246 | { |
---|
247 | PhysicsObject vasenReuna = Level.CreateLeftBorder(); |
---|
248 | vasenReuna.CollisionIgnoreGroup = 3; |
---|
249 | vasenReuna.IsVisible = false; |
---|
250 | PhysicsObject oikeaReuna = Level.CreateRightBorder(); |
---|
251 | oikeaReuna.IsVisible = false; |
---|
252 | oikeaReuna.CollisionIgnoreGroup = 3; |
---|
253 | PhysicsObject ylaReuna = Level.CreateTopBorder(); |
---|
254 | ylaReuna.IsVisible = false; |
---|
255 | ylaReuna.CollisionIgnoreGroup = 3; |
---|
256 | PhysicsObject alaReuna = Level.CreateBottomBorder(); |
---|
257 | alaReuna.IsVisible = false; |
---|
258 | alaReuna.CollisionIgnoreGroup = 3; |
---|
259 | |
---|
260 | Level.BackgroundColor = Color.Black; |
---|
261 | |
---|
262 | Camera.ZoomToLevel(); |
---|
263 | |
---|
264 | LuoPelaaja(300); |
---|
265 | Pelaaja[0].Tag = 11; |
---|
266 | Pelaaja[0].CollisionIgnoreGroup = 1; |
---|
267 | LuoPelaaja(-300); |
---|
268 | Pelaaja[1].CollisionIgnoreGroup = 2; |
---|
269 | Pelaaja[1].Tag = 12; |
---|
270 | } |
---|
271 | |
---|
272 | void LuoPelaaja(double x) |
---|
273 | { |
---|
274 | PhysicsObject pelaaja = new PhysicsObject(20, 20); |
---|
275 | |
---|
276 | pelaaja.X = x; |
---|
277 | pelaaja.Y = -250; |
---|
278 | pelaaja.Restitution = 0.5; |
---|
279 | pelaaja.AngularDamping = 0.1; |
---|
280 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees + 90); |
---|
281 | pelaaja.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "player.png")); |
---|
282 | Pelaaja.Add(pelaaja); |
---|
283 | Add(Pelaaja[Pelaaja.Count - 1]); |
---|
284 | } |
---|
285 | |
---|
286 | void LuoAjastin() |
---|
287 | { |
---|
288 | MadonreikaAjastin = new Timer(); |
---|
289 | MadonreikaAjastin.Interval = 5; |
---|
290 | MadonreikaAjastin.Timeout += new Action(NaytaAnimaatio); |
---|
291 | MadonreikaAjastin.Start(); |
---|
292 | |
---|
293 | Minioniajastin = new Timer(); |
---|
294 | Minioniajastin.Interval = 20; |
---|
295 | Minioniajastin.Timeout += new Action(Minioniajastin_Timeout); |
---|
296 | Minioniajastin.Start(); |
---|
297 | |
---|
298 | Minioninliikuttaja = new Timer(); |
---|
299 | Minioninliikuttaja.Interval = 0.1; // ei pienene |
---|
300 | Minioninliikuttaja.Timeout += new Action(Minioninliikuttaja_Timeout); |
---|
301 | Minioninliikuttaja.Start(); |
---|
302 | |
---|
303 | Automaattiammus = new Timer(); |
---|
304 | Automaattiammus.Interval = 0.2; // ei pienene |
---|
305 | Automaattiammus.Timeout += new Action(Automaattiammus_Timeout); |
---|
306 | Automaattiammus.Start(); |
---|
307 | |
---|
308 | MinioninAmmus = new Timer(); |
---|
309 | MinioninAmmus.Interval = 1.0; |
---|
310 | MinioninAmmus.Timeout += new Action(MinioninAmmus_Timeout); |
---|
311 | MinioninAmmus.Start(); |
---|
312 | |
---|
313 | Asteroidiajastin = new Timer(); |
---|
314 | Asteroidiajastin.Interval = RandomGen.NextDouble (5, 12); |
---|
315 | Asteroidiajastin.Timeout += new Action(Asteroidiajastin_Timeout); |
---|
316 | Asteroidiajastin.Start(); |
---|
317 | |
---|
318 | TuhoaAsteroidi = new Timer(); |
---|
319 | TuhoaAsteroidi.Interval = 30.0; |
---|
320 | TuhoaAsteroidi.Timeout += new Action(TuhoaAsteroidi_Timeout); |
---|
321 | TuhoaAsteroidi.Start(); |
---|
322 | |
---|
323 | Vaikeuttaja = new Timer(); |
---|
324 | Vaikeuttaja.Interval = 5.0; |
---|
325 | Vaikeuttaja.Timeout += new Action(Vaikeuttaja_Timeout); |
---|
326 | Vaikeuttaja.Start(); |
---|
327 | |
---|
328 | EnergianLataaja = new Timer(); |
---|
329 | EnergianLataaja.Interval = 5.0; |
---|
330 | EnergianLataaja.Timeout += new Action(EnergianLataaja_Timeout); |
---|
331 | EnergianLataaja.Start(); |
---|
332 | |
---|
333 | Konekivaari1 = new Timer(); |
---|
334 | Konekivaari1.Interval = 0.05; |
---|
335 | Konekivaari1.Timeout += new Action(Konekivaari1_Timeout); |
---|
336 | |
---|
337 | Konekivaari2 = new Timer(); |
---|
338 | Konekivaari2.Interval = 0.05; |
---|
339 | Konekivaari2.Timeout += new Action(Konekivaari2_Timeout); |
---|
340 | |
---|
341 | Triplefire1 = new Timer(); |
---|
342 | Triplefire1.Interval = 0.2; |
---|
343 | } |
---|
344 | |
---|
345 | void Konekivaari1_Timeout() |
---|
346 | { |
---|
347 | if (Keyboard.GetKeyState(Key.RightShift) == ButtonState.Down) |
---|
348 | LuoPelaajanAmmus(0); |
---|
349 | } |
---|
350 | |
---|
351 | |
---|
352 | void Konekivaari2_Timeout() |
---|
353 | { |
---|
354 | if (Keyboard.GetKeyState(Key.LeftShift) == ButtonState.Down) |
---|
355 | LuoPelaajanAmmus(1); |
---|
356 | } |
---|
357 | |
---|
358 | void Vaikeuttaja_Timeout() |
---|
359 | { |
---|
360 | MadonreikaAjastin.Interval = MadonreikaAjastin.Interval * 0.9; |
---|
361 | Minioniajastin.Interval = Minioniajastin.Interval * 0.9; |
---|
362 | Asteroidiajastin.Interval = Asteroidiajastin.Interval * 0.9; |
---|
363 | MinioninAmmus.Interval = MinioninAmmus.Interval * 0.95; |
---|
364 | Vaikeuttaja.Interval = Vaikeuttaja.Interval * 1.2; |
---|
365 | } |
---|
366 | |
---|
367 | void EnergianLataaja_Timeout() |
---|
368 | { |
---|
369 | if (ALTKHandler.HealthBars[0].Value < 100 && |
---|
370 | !Pelaaja[0].IsDestroyed) |
---|
371 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value + 1; |
---|
372 | |
---|
373 | if (ALTKHandler.HealthBars[1].Value < 100 && |
---|
374 | !Pelaaja[1].IsDestroyed) |
---|
375 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value + 1; |
---|
376 | } |
---|
377 | |
---|
378 | void TuhoaAsteroidi_Timeout() |
---|
379 | { |
---|
380 | Timer.SingleShot(0.0, AsteroidinTuhoaja); |
---|
381 | } |
---|
382 | |
---|
383 | void Asteroidiajastin_Timeout() |
---|
384 | { |
---|
385 | Timer.SingleShot(0.0, LuoAsteroidi); |
---|
386 | } |
---|
387 | |
---|
388 | void LuoPelaajanAmmus(int pelaajaID) |
---|
389 | { |
---|
390 | if (Pelaaja[pelaajaID].IsDestroyed) |
---|
391 | { |
---|
392 | return; |
---|
393 | } |
---|
394 | Projectile PelaajanAmmus = new Projectile(4.0, 4.0, Color.Green); |
---|
395 | |
---|
396 | PelaajanAmmus.Shape = Shape.Rectangle; |
---|
397 | |
---|
398 | PelaajanAmmus.Angle = Pelaaja[pelaajaID].Angle; |
---|
399 | PelaajanAmmus.Width = 12; |
---|
400 | PelaajanAmmus.Height = 3; |
---|
401 | PelaajanAmmus.Position = Pelaaja[pelaajaID].Position; |
---|
402 | |
---|
403 | Vector jotain = Vector.FromLengthAndAngle(25.0, Pelaaja[pelaajaID].Angle); |
---|
404 | PelaajanAmmus.Position = PelaajanAmmus.Position + jotain; |
---|
405 | PelaajanAmmus.Mass = 1; |
---|
406 | |
---|
407 | AddCollisionHandler(PelaajanAmmus, PelaajanAmmuksenTuhoaja); |
---|
408 | |
---|
409 | PelaajanAmmus.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "playerProjectile.png")); |
---|
410 | |
---|
411 | if (pelaajaID == 0) |
---|
412 | { |
---|
413 | PelaajanAmmus.Tag = 1; |
---|
414 | PelaajanAmmus.CollisionIgnoreGroup = 1; |
---|
415 | } |
---|
416 | else |
---|
417 | { |
---|
418 | PelaajanAmmus.Tag = 2; |
---|
419 | PelaajanAmmus.CollisionIgnoreGroup = 2; |
---|
420 | } |
---|
421 | PelaajanAmmus.CollisionIgnoreGroup = 100; |
---|
422 | Add(PelaajanAmmus); |
---|
423 | Vector Pelaajanammus = jotain * 40; |
---|
424 | PelaajanAmmus.Hit(Pelaajanammus); |
---|
425 | ALTKHandler.SoundPlayer.PlaySound(0); |
---|
426 | } |
---|
427 | |
---|
428 | void PelaajanAmmuksenTuhoaja(PhysicsObject PelaajanAmmus, PhysicsObject kohde) |
---|
429 | { |
---|
430 | PelaajanAmmus.Destroy(); |
---|
431 | |
---|
432 | try |
---|
433 | { |
---|
434 | int tagi = (int)kohde.Tag; |
---|
435 | int ammuksenTagi = (int)PelaajanAmmus.Tag; |
---|
436 | |
---|
437 | if (tagi == 5) |
---|
438 | { |
---|
439 | MinionExplosionES.AddEffect(kohde.Position, 800); |
---|
440 | MinionExplosionES2.AddEffect(kohde.Position, 100); |
---|
441 | ALTKHandler.StaticAnimHandler.AddStaticAnim(17, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
442 | ALTKHandler.StaticAnimHandler.AddStaticAnim(18, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
443 | kohde.Destroy(); |
---|
444 | if (ammuksenTagi == 1) |
---|
445 | { |
---|
446 | LisaaPisteita(0, Convert.ToInt32(10 * Pelaajan1Kerroin)); |
---|
447 | } |
---|
448 | else |
---|
449 | { |
---|
450 | LisaaPisteita(1, Convert.ToInt32(10 * Pelaajan2Kerroin)); |
---|
451 | } |
---|
452 | } |
---|
453 | else if (tagi == 1337) |
---|
454 | { |
---|
455 | kohde.MaxVelocity = kohde.MaxVelocity - 1.0; |
---|
456 | |
---|
457 | WormholeExplosionES.AddEffect(PelaajanAmmus.Position, 150); |
---|
458 | WormholeExplosionES2.AddEffect(PelaajanAmmus.Position, 5); |
---|
459 | |
---|
460 | if (ammuksenTagi == 1) |
---|
461 | { |
---|
462 | LisaaPisteita(0, Convert.ToInt32 (2 * Pelaajan1Kerroin)); |
---|
463 | } |
---|
464 | else |
---|
465 | { |
---|
466 | LisaaPisteita(1, Convert.ToInt32(2 * Pelaajan2Kerroin)); |
---|
467 | } |
---|
468 | |
---|
469 | if (kohde.MaxVelocity < 1) |
---|
470 | { |
---|
471 | WormholeExplosionES.AddEffect(kohde.Position, 500); |
---|
472 | WormholeExplosionES2.AddEffect(kohde.Position, 150); |
---|
473 | ALTKHandler.StaticAnimHandler.AddStaticAnim(15, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
474 | kohde.Destroy(); |
---|
475 | if (ammuksenTagi == 1) |
---|
476 | { |
---|
477 | LisaaPisteita(0, Convert.ToInt32(13 * Pelaajan1Kerroin)); |
---|
478 | } |
---|
479 | else |
---|
480 | { |
---|
481 | LisaaPisteita(1, Convert.ToInt32(13 * Pelaajan2Kerroin)); |
---|
482 | } |
---|
483 | } |
---|
484 | } |
---|
485 | else if (tagi == 123) |
---|
486 | { |
---|
487 | kohde.Mass = (Math.Abs((kohde.Left - kohde.Right) * (kohde.Top - kohde.Bottom))) / 20; |
---|
488 | kohde.Size = kohde.Size * 0.84; |
---|
489 | |
---|
490 | AsteroidHitEffect(PelaajanAmmus.Position); |
---|
491 | |
---|
492 | if (ammuksenTagi == 1) |
---|
493 | { |
---|
494 | LisaaPisteita(0, Convert.ToInt32((1 / kohde.Mass) * 5 * Pelaajan1Kerroin)); |
---|
495 | |
---|
496 | if (kohde.Mass < (Math.Abs((kohde.Left - kohde.Right) * (kohde.Top - kohde.Bottom))) / 20) |
---|
497 | { |
---|
498 | TuhoaAsteroidiEfekti(kohde.Position); |
---|
499 | LisaaKerrointa(0, 0.5); |
---|
500 | } |
---|
501 | } |
---|
502 | else |
---|
503 | { |
---|
504 | LisaaPisteita(1, Convert.ToInt32((1 / kohde.Mass) * 5 * Pelaajan2Kerroin)); |
---|
505 | |
---|
506 | if (kohde.Mass < (Math.Abs((kohde.Left - kohde.Right) * (kohde.Top - kohde.Bottom))) / 20) |
---|
507 | { |
---|
508 | TuhoaAsteroidiEfekti(kohde.Position); |
---|
509 | LisaaKerrointa(1, 0.5); |
---|
510 | } |
---|
511 | } |
---|
512 | } |
---|
513 | else if (tagi == 11) |
---|
514 | { |
---|
515 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 5; |
---|
516 | if (ALTKHandler.HealthBars[0].Value < 1) |
---|
517 | { |
---|
518 | PelaajanTuhoaja(); |
---|
519 | } |
---|
520 | } |
---|
521 | else if (tagi == 12) |
---|
522 | { |
---|
523 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 5; |
---|
524 | PelaajanTuhoaja(); |
---|
525 | |
---|
526 | } |
---|
527 | else if (tagi == 8) |
---|
528 | { |
---|
529 | MinionExplosionES.AddEffect(kohde.Position, 200); |
---|
530 | kohde.Destroy(); |
---|
531 | } |
---|
532 | |
---|
533 | } |
---|
534 | catch |
---|
535 | { |
---|
536 | } |
---|
537 | } |
---|
538 | |
---|
539 | void MinioninTuhoaja(PhysicsObject minioni, PhysicsObject kohde) |
---|
540 | { |
---|
541 | try |
---|
542 | { |
---|
543 | int tagi = (int)kohde.Tag; |
---|
544 | if (tagi == 11) |
---|
545 | { |
---|
546 | MinionExplosionES.AddEffect(kohde.Position, 800); |
---|
547 | MinionExplosionES2.AddEffect(kohde.Position, 100); |
---|
548 | ALTKHandler.StaticAnimHandler.AddStaticAnim(17, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
549 | ALTKHandler.StaticAnimHandler.AddStaticAnim(18, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
550 | |
---|
551 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
552 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 20; |
---|
553 | minioni.Destroy(); |
---|
554 | PelaajanTuhoaja(); |
---|
555 | LisaaPisteita(0, Convert.ToInt32 ( 10 * Pelaajan1Kerroin)); |
---|
556 | } |
---|
557 | |
---|
558 | if (tagi == 12) |
---|
559 | { |
---|
560 | MinionExplosionES.AddEffect(kohde.Position, 800); |
---|
561 | MinionExplosionES2.AddEffect(kohde.Position, 100); |
---|
562 | ALTKHandler.StaticAnimHandler.AddStaticAnim(17, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
563 | ALTKHandler.StaticAnimHandler.AddStaticAnim(18, ALTKHandler.AdjustJypeliVectorToXna(kohde.X, kohde.Y)); |
---|
564 | |
---|
565 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
566 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 20; |
---|
567 | minioni.Destroy(); |
---|
568 | PelaajanTuhoaja(); |
---|
569 | LisaaPisteita(1, Convert.ToInt32 ( 10 * Pelaajan2Kerroin)); |
---|
570 | } |
---|
571 | |
---|
572 | } |
---|
573 | catch |
---|
574 | { |
---|
575 | } |
---|
576 | } |
---|
577 | |
---|
578 | void AsteroidiTormaa(PhysicsObject asteroidi, PhysicsObject kohde) |
---|
579 | { |
---|
580 | try |
---|
581 | { |
---|
582 | int tagi = (int)kohde.Tag; |
---|
583 | if (tagi == 1) |
---|
584 | { |
---|
585 | kohde.Destroy(); |
---|
586 | AsteroidHitEffect(asteroidi.Position); |
---|
587 | asteroidi.Mass = (Math.Abs((asteroidi.Left - asteroidi.Right) * (asteroidi.Top - asteroidi.Bottom))) / 20; |
---|
588 | asteroidi.Size = asteroidi.Size * 0.86; |
---|
589 | LisaaPisteita(0, Convert.ToInt32((1 / asteroidi.Mass) * 5 * Pelaajan1Kerroin)); |
---|
590 | if (asteroidi.Mass < 20) |
---|
591 | { |
---|
592 | TuhoaAsteroidiEfekti(asteroidi.Position); |
---|
593 | asteroidi.Destroy(); |
---|
594 | LisaaKerrointa(0, 0.5); |
---|
595 | } |
---|
596 | } |
---|
597 | else if (tagi == 2) |
---|
598 | { |
---|
599 | kohde.Destroy(); |
---|
600 | AsteroidHitEffect(asteroidi.Position); |
---|
601 | asteroidi.Mass = (Math.Abs((asteroidi.Left - asteroidi.Right) * (asteroidi.Top - asteroidi.Bottom))) / 20; |
---|
602 | asteroidi.Size = asteroidi.Size * 0.86; |
---|
603 | LisaaPisteita(1, Convert.ToInt32((1 / asteroidi.Mass) * 5 * Pelaajan2Kerroin)); |
---|
604 | if (asteroidi.Mass < 20) |
---|
605 | { |
---|
606 | TuhoaAsteroidiEfekti(asteroidi.Position); |
---|
607 | asteroidi.Destroy(); |
---|
608 | LisaaKerrointa(1, 0.5); |
---|
609 | } |
---|
610 | |
---|
611 | } |
---|
612 | |
---|
613 | else if (tagi == 11) |
---|
614 | { |
---|
615 | ALTKHandler.HealthBars[0].Value = Convert.ToInt32(Convert.ToDouble(ALTKHandler.HealthBars[0].Value) * (1 - ((asteroidi.Mass / 360.0)))); |
---|
616 | PelaajanTuhoaja(); |
---|
617 | } |
---|
618 | else if (tagi == 12) |
---|
619 | { |
---|
620 | ALTKHandler.HealthBars[1].Value = Convert.ToInt32(Convert.ToDouble(ALTKHandler.HealthBars[1].Value) * (1 - ((asteroidi.Mass / 360.0)))); |
---|
621 | PelaajanTuhoaja(); |
---|
622 | } |
---|
623 | } |
---|
624 | catch |
---|
625 | { |
---|
626 | } |
---|
627 | } |
---|
628 | |
---|
629 | private void AsteroidHitEffect(Vector position) |
---|
630 | { |
---|
631 | AsteroidExplosionES.AddEffect(position, 200); |
---|
632 | ALTKHandler.StaticAnimHandler.AddStaticAnim(19, |
---|
633 | ALTKHandler.AdjustJypeliVectorToXna(position.X, position.Y)); |
---|
634 | } |
---|
635 | |
---|
636 | private void TuhoaAsteroidiEfekti(Vector paikka) |
---|
637 | { |
---|
638 | AsteroidExplosionES.AddEffect(paikka, 400); |
---|
639 | AsteroidExplosionES2.AddEffect(paikka, 200); |
---|
640 | ALTKHandler.StaticAnimHandler.AddStaticAnim(20, |
---|
641 | ALTKHandler.AdjustJypeliVectorToXna(paikka.X, paikka.Y)); |
---|
642 | } |
---|
643 | |
---|
644 | void Minioninliikuttaja_Timeout() |
---|
645 | { |
---|
646 | for (int minionID = 0; minionID < Minioni.Count; minionID++) |
---|
647 | { |
---|
648 | double etäisyys1 = 100000.0; |
---|
649 | double etäisyys2 = 100000.0; |
---|
650 | if (!Pelaaja[0].IsDestroyed) |
---|
651 | { |
---|
652 | double x1 = Math.Abs(Pelaaja[0].X - Minioni[minionID].X); |
---|
653 | double y1 = Math.Abs(Pelaaja[0].Y - Minioni[minionID].Y); |
---|
654 | etäisyys1 = Math.Sqrt(x1 + y1); |
---|
655 | } |
---|
656 | |
---|
657 | if (!Pelaaja[1].IsDestroyed) |
---|
658 | { |
---|
659 | double x2 = Math.Abs(Pelaaja[1].X - Minioni[minionID].X); |
---|
660 | double y2 = Math.Abs(Pelaaja[1].Y - Minioni[minionID].Y); |
---|
661 | etäisyys2 = Math.Sqrt(x2 + y2); |
---|
662 | } |
---|
663 | if (etäisyys1 > etäisyys2) |
---|
664 | { |
---|
665 | MinioninLiike(Minioni[minionID], 1); |
---|
666 | } |
---|
667 | else |
---|
668 | { |
---|
669 | MinioninLiike(Minioni[minionID], 0); |
---|
670 | } |
---|
671 | } |
---|
672 | } |
---|
673 | |
---|
674 | void Minioniajastin_Timeout() |
---|
675 | { |
---|
676 | Timer.SingleShot (2, AjaLuoMinioni); |
---|
677 | } |
---|
678 | |
---|
679 | void Automaattiammus_Timeout() |
---|
680 | { |
---|
681 | if (Keyboard.GetKeyState(Key.RightShift) == ButtonState.Down) |
---|
682 | { |
---|
683 | Timer.SingleShot(0, AjaLuoPelaajan1Ammus); |
---|
684 | } |
---|
685 | |
---|
686 | if (Keyboard.GetKeyState(Key.LeftShift) == ButtonState.Down) |
---|
687 | { |
---|
688 | Timer.SingleShot(0, AjaLuoPelaajan2Ammus); |
---|
689 | } |
---|
690 | } |
---|
691 | |
---|
692 | void MinioninAmmus_Timeout() |
---|
693 | { |
---|
694 | Timer.SingleShot(RandomGen.NextDouble(0.5, 2), AjaLuoMinioninAmmus); |
---|
695 | } |
---|
696 | |
---|
697 | void AjaLuoPelaajan1Ammus() |
---|
698 | { |
---|
699 | LuoPelaajanAmmus(0); |
---|
700 | } |
---|
701 | |
---|
702 | void AjaLuoPelaajan2Ammus() |
---|
703 | { |
---|
704 | LuoPelaajanAmmus(1); |
---|
705 | } |
---|
706 | |
---|
707 | void AjaLuoMinioninAmmus() |
---|
708 | { |
---|
709 | for (int mId = 0; mId < Minioni.Count; mId++) |
---|
710 | { |
---|
711 | if (!Minioni[mId].IsDestroyed) |
---|
712 | { |
---|
713 | int jtn = RandomGen.NextInt(10000); |
---|
714 | if (jtn > 5000) |
---|
715 | { |
---|
716 | LuoMinioninAmmus(mId); |
---|
717 | } |
---|
718 | } |
---|
719 | } |
---|
720 | } |
---|
721 | |
---|
722 | void AjaLuoMinioni() |
---|
723 | { |
---|
724 | for (int Madonreikaa = 0; Madonreikaa < Madonreika.Count; Madonreikaa++) |
---|
725 | { |
---|
726 | if (!Madonreika[Madonreikaa].IsDestroyed) |
---|
727 | LuoMinioni(Madonreikaa); |
---|
728 | } |
---|
729 | } |
---|
730 | |
---|
731 | void NaytaAnimaatio() |
---|
732 | { |
---|
733 | int arvo = RandomGen.NextInt(4); |
---|
734 | |
---|
735 | double x = 0.0; |
---|
736 | double y = 0.0; |
---|
737 | |
---|
738 | // yläreuna |
---|
739 | if (arvo == 0) |
---|
740 | { |
---|
741 | x = RandomGen.NextDouble(Level.Left + 30, Level.Right - 30); |
---|
742 | y = RandomGen.NextDouble(Level.Top - 30, Level.Top - 300); |
---|
743 | } |
---|
744 | // alareuna |
---|
745 | else if (arvo == 1) |
---|
746 | { |
---|
747 | x = RandomGen.NextDouble(Level.Left + 30, Level.Right - 30); |
---|
748 | y = RandomGen.NextDouble(Level.Bottom + 30, Level.Bottom + 300); |
---|
749 | } |
---|
750 | // vasen reuna |
---|
751 | else if (arvo == 2) |
---|
752 | { |
---|
753 | x = RandomGen.NextDouble(Level.Left + 30, Level.Left + 300); |
---|
754 | y = RandomGen.NextDouble(Level.Bottom + 30, Level.Top - 30); |
---|
755 | } |
---|
756 | // oikea reuna |
---|
757 | else |
---|
758 | { |
---|
759 | x = RandomGen.NextDouble(Level.Right - 30, Level.Right - 300); |
---|
760 | y = RandomGen.NextDouble(Level.Bottom + 30, Level.Top - 30); |
---|
761 | } |
---|
762 | |
---|
763 | MadonreikaPosX = x; |
---|
764 | MadonreikaPosY = y; |
---|
765 | |
---|
766 | ALTKHandler.StaticAnimHandler.AddStaticAnim(16, ALTKHandler.AdjustJypeliVectorToXna(x, y)); |
---|
767 | |
---|
768 | Timer.SingleShot(2, LuoMadonreika); |
---|
769 | } |
---|
770 | |
---|
771 | void LuoMadonreika() |
---|
772 | { |
---|
773 | PhysicsObject madonreika = PhysicsObject.CreateStaticObject(50, 50); |
---|
774 | |
---|
775 | madonreika.X = MadonreikaPosX; |
---|
776 | madonreika.Y = MadonreikaPosY; |
---|
777 | madonreika.CollisionIgnoreGroup = 5; |
---|
778 | madonreika.MaxVelocity = 15.0; |
---|
779 | madonreika.Tag = 1337; |
---|
780 | madonreika.Shape = Shape.Circle; |
---|
781 | madonreika.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "wormhole.png")); |
---|
782 | Madonreika.Add(madonreika); |
---|
783 | AddCollisionHandler(madonreika, MadonreikaTormaa); |
---|
784 | Add(madonreika, -3); |
---|
785 | madonreika.AngularVelocity = 1; |
---|
786 | LuoMinioni(Madonreika.Count - 1); |
---|
787 | |
---|
788 | ALTKHandler.SoundPlayer.PlaySound(2); |
---|
789 | } |
---|
790 | |
---|
791 | void AsteroidinTuhoaja() |
---|
792 | { |
---|
793 | for (int asteroidiId = 0; asteroidiId < Asteroidi.Count; asteroidiId++) |
---|
794 | { |
---|
795 | if (Math.Abs(Asteroidi[asteroidiId].X) > 500.0 || |
---|
796 | Math.Abs(Asteroidi[asteroidiId].Y) > 500.0) |
---|
797 | { |
---|
798 | Asteroidi[asteroidiId].Destroy(); |
---|
799 | |
---|
800 | Asteroidi.RemoveAt(asteroidiId); |
---|
801 | asteroidiId--; |
---|
802 | } |
---|
803 | } |
---|
804 | } |
---|
805 | |
---|
806 | void LuoAsteroidi() |
---|
807 | { |
---|
808 | int arvo = RandomGen.NextInt(4); |
---|
809 | |
---|
810 | double x = 0.0; |
---|
811 | double y = 0.0; |
---|
812 | |
---|
813 | // yläreuna |
---|
814 | if (arvo == 0) |
---|
815 | { |
---|
816 | x = RandomGen.NextDouble(Level.Left -60, Level.Right + 60); |
---|
817 | y = Level.Top + 60; |
---|
818 | } |
---|
819 | // alareuna |
---|
820 | else if (arvo == 1) |
---|
821 | { |
---|
822 | x = RandomGen.NextDouble(Level.Left - 60, Level.Right + 60); |
---|
823 | y = Level.Bottom - 60; |
---|
824 | } |
---|
825 | // vasen reuna |
---|
826 | else if (arvo == 2) |
---|
827 | { |
---|
828 | x = Level.Left - 60; |
---|
829 | y = RandomGen.NextDouble(Level.Bottom - 60, Level.Top + 60); |
---|
830 | } |
---|
831 | // oikea reuna |
---|
832 | else |
---|
833 | { |
---|
834 | x = Level.Right + 60; |
---|
835 | y = RandomGen.NextDouble(Level.Bottom - 60, Level.Top + 60); |
---|
836 | } |
---|
837 | PhysicsObject asteroidi = new PhysicsObject (RandomGen.NextDouble (10, 60), RandomGen.NextDouble(10, 60)); |
---|
838 | asteroidi.Shape = Shape.Circle; |
---|
839 | asteroidi.X = x; |
---|
840 | asteroidi.Y = y; |
---|
841 | asteroidi.Mass = (Math.Abs((asteroidi.Left - asteroidi.Right) * (asteroidi.Top - asteroidi.Bottom))) / 20; |
---|
842 | asteroidi.Tag = 123; |
---|
843 | |
---|
844 | Vector suunta = -asteroidi.Position; |
---|
845 | Vector origo = Vector.FromLengthAndAngle(RandomGen.NextDouble(2000, 4000), suunta.Angle); |
---|
846 | Vector ohi = new Vector (RandomGen.NextDouble(-3000.0, 3000.0), RandomGen.NextDouble(-3000.0, 3000.0)); |
---|
847 | Vector hit = origo + ohi; |
---|
848 | |
---|
849 | Asteroidi.Add(asteroidi); |
---|
850 | Add(Asteroidi[Asteroidi.Count -1], 0); |
---|
851 | asteroidi.CollisionIgnoreGroup = 3; |
---|
852 | AddCollisionHandler(Asteroidi[Asteroidi.Count - 1], AsteroidiTormaa); |
---|
853 | asteroidi.Hit(hit); |
---|
854 | asteroidi.AngularVelocity = RandomGen.NextDouble (4, -4); |
---|
855 | |
---|
856 | } |
---|
857 | |
---|
858 | void LuoMinioni(int madonreikaID) |
---|
859 | { |
---|
860 | PhysicsObject minioni = new PhysicsObject(20, 20); |
---|
861 | |
---|
862 | minioni.X = Madonreika[madonreikaID].X; |
---|
863 | minioni.Y = Madonreika[madonreikaID].Y; |
---|
864 | minioni.CollisionIgnoreGroup = 5; |
---|
865 | minioni.Shape = Shape.Triangle; |
---|
866 | minioni.Color = Color.Red; |
---|
867 | minioni.Angle = (Pelaaja[1].Position - minioni.Position).Angle; |
---|
868 | minioni.Hit(Vector.FromLengthAndAngle(100, minioni.Angle)); |
---|
869 | minioni.MaxVelocity = 100.0; |
---|
870 | minioni.AngularDamping = 0.1; |
---|
871 | minioni.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minion_ship.png")); |
---|
872 | minioni.Tag = 5; |
---|
873 | AddCollisionHandler(minioni, MinioninTuhoaja); |
---|
874 | Minioni.Add(minioni); |
---|
875 | Add(Minioni[Minioni.Count - 1]); |
---|
876 | MinioninLiike(Minioni[Minioni.Count - 1], 0); |
---|
877 | } |
---|
878 | |
---|
879 | void MadonreikaTormaa (PhysicsObject madonreika, PhysicsObject kohde) |
---|
880 | { |
---|
881 | try |
---|
882 | { |
---|
883 | int tagi = (int)kohde.Tag; |
---|
884 | |
---|
885 | if (tagi == 1) |
---|
886 | { |
---|
887 | LisaaPisteita(0, Convert.ToInt32 ( 2 * Pelaajan1Kerroin)); |
---|
888 | } |
---|
889 | if (tagi == 2) |
---|
890 | { |
---|
891 | LisaaPisteita(1, Convert.ToInt32 ( 2 * Pelaajan2Kerroin)); |
---|
892 | } |
---|
893 | if (tagi == 11) |
---|
894 | { |
---|
895 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 17; |
---|
896 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
897 | PelaajanTuhoaja(); |
---|
898 | } |
---|
899 | else if (tagi == 12) |
---|
900 | { |
---|
901 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 17; |
---|
902 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
903 | PelaajanTuhoaja(); |
---|
904 | } |
---|
905 | } |
---|
906 | catch |
---|
907 | { |
---|
908 | } |
---|
909 | } |
---|
910 | |
---|
911 | void LuoMinioninAmmus(int minioniID) |
---|
912 | { |
---|
913 | Projectile minioninAmmus = new Projectile(4.0, 4.0, Color.Yellow); |
---|
914 | minioninAmmus.Angle = Minioni[minioniID].Angle; |
---|
915 | minioninAmmus.Shape = Shape.Rectangle; |
---|
916 | minioninAmmus.Width = 8.0; |
---|
917 | minioninAmmus.Height = 2.0; |
---|
918 | Vector a = Vector.FromLengthAndAngle(25.0, Minioni[minioniID].Angle); |
---|
919 | minioninAmmus.Position = Minioni[minioniID].Position + a; |
---|
920 | minioninAmmus.Image = Image.FromStream(File.OpenRead(ALTKConstants.TexturePath + "minionProjectile.png")); |
---|
921 | AddCollisionHandler(minioninAmmus, MinioninAmmuksenTuhoaja); |
---|
922 | minioninAmmus.Tag = 8; |
---|
923 | minioninAmmus.CollisionIgnoreGroup = 5; |
---|
924 | Add(minioninAmmus); |
---|
925 | minioninAmmus.Mass = 0.5; |
---|
926 | Vector b = Vector.FromLengthAndAngle(250.0, Minioni[minioniID].Angle); |
---|
927 | minioninAmmus.Hit(b); |
---|
928 | ALTKHandler.SoundPlayer.PlaySound(3); |
---|
929 | } |
---|
930 | |
---|
931 | void PelaajanTuhoaja() |
---|
932 | { |
---|
933 | if (ALTKHandler.HealthBars[0].Value < 1 && !Pelaaja[0].IsDestroyed) |
---|
934 | { |
---|
935 | ALTKHandler.StaticAnimHandler.AddStaticAnim(21, |
---|
936 | ALTKHandler.AdjustJypeliVectorToXna(Pelaaja[0].X, Pelaaja[0].Y)); |
---|
937 | |
---|
938 | PlayerDeathES.AddEffect(Pelaaja[0].Position, 2000); |
---|
939 | PlayerDeathESL.AddEffect(Pelaaja[0].Position, 4000); |
---|
940 | PlayerDeathES2.AddEffect(Pelaaja[0].Position, 1400); |
---|
941 | |
---|
942 | Pelaaja[0].Destroy(); |
---|
943 | } |
---|
944 | |
---|
945 | if (ALTKHandler.HealthBars[1].Value < 1 && !Pelaaja[1].IsDestroyed) |
---|
946 | { |
---|
947 | ALTKHandler.StaticAnimHandler.AddStaticAnim(21, |
---|
948 | ALTKHandler.AdjustJypeliVectorToXna(Pelaaja[1].X, Pelaaja[1].Y)); |
---|
949 | |
---|
950 | PlayerDeathES.AddEffect(Pelaaja[1].Position, 2000); |
---|
951 | PlayerDeathESL.AddEffect(Pelaaja[1].Position, 4000); |
---|
952 | PlayerDeathES2.AddEffect(Pelaaja[1].Position, 1400); |
---|
953 | |
---|
954 | Pelaaja[1].Destroy(); |
---|
955 | } |
---|
956 | |
---|
957 | } |
---|
958 | |
---|
959 | void MinioninAmmuksenTuhoaja(PhysicsObject minioninAmmus, PhysicsObject kohde) |
---|
960 | { |
---|
961 | minioninAmmus.Destroy(); |
---|
962 | |
---|
963 | try |
---|
964 | { |
---|
965 | int tagi = (int)kohde.Tag; |
---|
966 | if (tagi == 11) |
---|
967 | { |
---|
968 | ALTKHandler.HealthBars[0].Value = ALTKHandler.HealthBars[0].Value - 10 ; |
---|
969 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
970 | PelaajanTuhoaja(); |
---|
971 | } |
---|
972 | else if (tagi == 12) |
---|
973 | { |
---|
974 | ALTKHandler.HealthBars[1].Value = ALTKHandler.HealthBars[1].Value - 10; |
---|
975 | PlayerHitES.AddEffect(kohde.Position, 150); |
---|
976 | PelaajanTuhoaja(); |
---|
977 | } |
---|
978 | else if (tagi == 1 || |
---|
979 | tagi == 2) |
---|
980 | { |
---|
981 | MinionExplosionES.AddEffect(kohde.Position, 200); |
---|
982 | kohde.Destroy(); |
---|
983 | } |
---|
984 | |
---|
985 | } |
---|
986 | catch |
---|
987 | { |
---|
988 | } |
---|
989 | } |
---|
990 | |
---|
991 | void MinioninLiike(PhysicsObject minioni, int pelaaja) |
---|
992 | { |
---|
993 | minioni.Angle = (Pelaaja[pelaaja].Position - minioni.Position).Angle; |
---|
994 | Vector q = Vector.FromLengthAndAngle(5.0, minioni.Angle); |
---|
995 | minioni.Hit(q); |
---|
996 | return; |
---|
997 | } |
---|
998 | |
---|
999 | void LisaaPisteita(int pelaajaID, int pistemaara) |
---|
1000 | { |
---|
1001 | if (pelaajaID == 0) |
---|
1002 | Pelaajan1Pisteet = Pelaajan1Pisteet + pistemaara; |
---|
1003 | |
---|
1004 | if (pelaajaID == 1) |
---|
1005 | Pelaajan2Pisteet = Pelaajan2Pisteet + pistemaara; |
---|
1006 | } |
---|
1007 | |
---|
1008 | void LisaaKerrointa(int pelaajaID, double kerroin) |
---|
1009 | { |
---|
1010 | if (pelaajaID == 0) |
---|
1011 | Pelaajan1Kerroin = Pelaajan1Kerroin + kerroin; |
---|
1012 | if (pelaajaID == 1) |
---|
1013 | Pelaajan2Kerroin = Pelaajan2Kerroin + kerroin; |
---|
1014 | } |
---|
1015 | |
---|
1016 | void AsetaNappaimet() |
---|
1017 | { |
---|
1018 | Keyboard.Listen(Key.Up, ButtonState.Down, AlkuKiihdytys, null, Pelaaja[0]); |
---|
1019 | Keyboard.Listen(Key.Up, ButtonState.Down, Kiihdyta, null, Pelaaja[0]); |
---|
1020 | Keyboard.Listen(Key.Down, ButtonState.Down, Hidasta, null, Pelaaja[0]); |
---|
1021 | Keyboard.Listen(Key.Left, ButtonState.Down, kaannaVasemmalle, null, Pelaaja[0]); |
---|
1022 | Keyboard.Listen(Key.Right, ButtonState.Down, kaannaOikealle, null, Pelaaja[0]); |
---|
1023 | Keyboard.Listen(Key.RightShift, ButtonState.Pressed, LuoPelaajanAmmus, null, 0); |
---|
1024 | |
---|
1025 | Keyboard.Listen(Key.W, ButtonState.Down, AlkuKiihdytys, null, Pelaaja[1]); |
---|
1026 | Keyboard.Listen(Key.W, ButtonState.Down, Kiihdyta, null, Pelaaja[1]); |
---|
1027 | Keyboard.Listen(Key.S, ButtonState.Down, Hidasta, null, Pelaaja[1]); |
---|
1028 | Keyboard.Listen(Key.A, ButtonState.Down, kaannaVasemmalle, null, Pelaaja[1]); |
---|
1029 | Keyboard.Listen(Key.D, ButtonState.Down, kaannaOikealle, null, Pelaaja[1]); |
---|
1030 | Keyboard.Listen(Key.LeftShift, ButtonState.Pressed, LuoPelaajanAmmus, null, 1); |
---|
1031 | |
---|
1032 | Keyboard.Listen(Key.F11, ButtonState.Pressed, Reset, null); |
---|
1033 | } |
---|
1034 | |
---|
1035 | void AlkuKiihdytys(PhysicsObject pelaaja) |
---|
1036 | { |
---|
1037 | if (pelaaja.Velocity.Magnitude < 7) |
---|
1038 | { |
---|
1039 | Vector o = Vector.FromLengthAndAngle(50.0, pelaaja.Angle); |
---|
1040 | pelaaja.Hit(o); |
---|
1041 | ALTKHandler.SoundPlayer.PlaySound(1); |
---|
1042 | } |
---|
1043 | } |
---|
1044 | |
---|
1045 | void Kiihdyta(PhysicsObject pelaaja) |
---|
1046 | { |
---|
1047 | Vector z = Vector.FromLengthAndAngle(5.0, pelaaja.Angle); |
---|
1048 | pelaaja.Hit(z); |
---|
1049 | |
---|
1050 | ALTKHandler.StaticAnimHandler.AddStaticAnim("ENGINE_SMOKE", |
---|
1051 | ALTKHandler.AdjustJypeliVectorToXna(pelaaja.Position.X, pelaaja.Position.Y)); |
---|
1052 | } |
---|
1053 | |
---|
1054 | void Hidasta(PhysicsObject pelaaja) |
---|
1055 | { |
---|
1056 | pelaaja.Velocity = new Vector(pelaaja.Velocity.X * 0.95, pelaaja.Velocity.Y * 0.95); |
---|
1057 | } |
---|
1058 | |
---|
1059 | void kaannaVasemmalle(PhysicsObject pelaaja) |
---|
1060 | { |
---|
1061 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees + 4); |
---|
1062 | } |
---|
1063 | |
---|
1064 | void kaannaOikealle(PhysicsObject pelaaja) |
---|
1065 | { |
---|
1066 | pelaaja.Angle = Angle.FromDegrees(pelaaja.Angle.Degrees - 4); |
---|
1067 | } |
---|
1068 | |
---|
1069 | void PowerUps(PhysicsObject PowerUp, PhysicsObject kohde) |
---|
1070 | { |
---|
1071 | int arvo = RandomGen.NextInt(10); |
---|
1072 | int pelaaja = (int)kohde.Tag; |
---|
1073 | |
---|
1074 | if (arvo == 1) |
---|
1075 | { |
---|
1076 | //Energiaboosti |
---|
1077 | PhysicsObject Energia10 = PhysicsObject.CreateStaticObject (25, 25, Shape.Hexagon); |
---|
1078 | Energia10.Color = Color.Green; |
---|
1079 | Energia10.CollisionIgnoreGroup = 5; |
---|
1080 | Add(Energia10); |
---|
1081 | if (pelaaja == 11) |
---|
1082 | { |
---|
1083 | if (ALTKHandler.HealthBars[0].Value < 80) |
---|
1084 | { |
---|
1085 | ALTKHandler.HealthBars[0].Value = Convert.ToInt32(ALTKHandler.HealthBars[0].Value + 20); |
---|
1086 | Energia10.Destroy(); |
---|
1087 | } |
---|
1088 | else |
---|
1089 | { |
---|
1090 | ALTKHandler.HealthBars[0].Value = 100; |
---|
1091 | } |
---|
1092 | Energia10.Destroy(); |
---|
1093 | } |
---|
1094 | else if (pelaaja == 22) |
---|
1095 | { |
---|
1096 | if (ALTKHandler.HealthBars[1].Value < 80) |
---|
1097 | { |
---|
1098 | ALTKHandler.HealthBars[1].Value = Convert.ToInt32(ALTKHandler.HealthBars[1].Value + 20); |
---|
1099 | } |
---|
1100 | else |
---|
1101 | { |
---|
1102 | ALTKHandler.HealthBars[1].Value = 100; |
---|
1103 | } |
---|
1104 | Energia10.Destroy(); |
---|
1105 | } |
---|
1106 | |
---|
1107 | } |
---|
1108 | else if (arvo == 3) |
---|
1109 | { |
---|
1110 | //Konekivääri |
---|
1111 | PhysicsObject Konekivaari = PhysicsObject.CreateStaticObject(25, 25); |
---|
1112 | Konekivaari.Color = Color.Blue; |
---|
1113 | Add(Konekivaari); |
---|
1114 | |
---|
1115 | if (pelaaja == 11) |
---|
1116 | { |
---|
1117 | Konekivaari1.Start(200); |
---|
1118 | Konekivaari.Destroy(); |
---|
1119 | } |
---|
1120 | else if (pelaaja == 12) |
---|
1121 | { |
---|
1122 | Konekivaari1.Start(200); |
---|
1123 | Konekivaari.Destroy(); |
---|
1124 | } |
---|
1125 | |
---|
1126 | } |
---|
1127 | else if (arvo == 4) |
---|
1128 | { |
---|
1129 | //Triplefire |
---|
1130 | PhysicsObject TripleFire = PhysicsObject.CreateStaticObject(25, 25, Shape.Triangle); |
---|
1131 | TripleFire.Color = Color.Red; |
---|
1132 | Add(TripleFire); |
---|
1133 | |
---|
1134 | if (pelaaja == 11) |
---|
1135 | { |
---|
1136 | Triplefire1.Start(50); |
---|
1137 | TripleFire.Destroy(); |
---|
1138 | } |
---|
1139 | else if (pelaaja == 22) |
---|
1140 | { |
---|
1141 | Triplefire2.Start(50); |
---|
1142 | TripleFire.Destroy(); |
---|
1143 | } |
---|
1144 | } |
---|
1145 | else if (arvo == 5) |
---|
1146 | { |
---|
1147 | //Full restore |
---|
1148 | } |
---|
1149 | else |
---|
1150 | { |
---|
1151 | } |
---|
1152 | } |
---|
1153 | |
---|
1154 | void Reset() |
---|
1155 | { |
---|
1156 | ClearAll(); |
---|
1157 | Asteroidi.Clear(); |
---|
1158 | Minioni.Clear(); |
---|
1159 | Pelaaja.Clear(); |
---|
1160 | Madonreika.Clear(); |
---|
1161 | Begin(); |
---|
1162 | ALTKHandler.HealthBars[0].Value = 100; |
---|
1163 | ALTKHandler.HealthBars[1].Value = 100; |
---|
1164 | } |
---|
1165 | |
---|
1166 | #region XNA / ALTK-Based Code |
---|
1167 | |
---|
1168 | private void HandleCursor(AnalogState analogState) |
---|
1169 | { |
---|
1170 | Kursori.AbsolutePosition = new Vector(Kursori.Position.X + analogState.MouseMovement.X, Kursori.Position.Y + analogState.MouseMovement.Y); |
---|
1171 | } |
---|
1172 | |
---|
1173 | protected override void Initialize() |
---|
1174 | { |
---|
1175 | base.Initialize(); |
---|
1176 | |
---|
1177 | InitALTK(); |
---|
1178 | } |
---|
1179 | |
---|
1180 | protected override void Update(Microsoft.Xna.Framework.GameTime gameTime) |
---|
1181 | { |
---|
1182 | base.Update(gameTime); |
---|
1183 | |
---|
1184 | ALTKHandler.ScoreDisplayers[0].Value = Pelaajan1Pisteet; |
---|
1185 | ALTKHandler.ScoreDisplayers[1].Value = Pelaajan2Pisteet; |
---|
1186 | |
---|
1187 | ALTKHandler.ScoreRatioDisplayers[0].Value = Pelaajan1Kerroin; |
---|
1188 | ALTKHandler.ScoreRatioDisplayers[1].Value = Pelaajan2Kerroin; |
---|
1189 | |
---|
1190 | if (Kursori.Position.X > ALTKConstants.WindowWidth / 2.0) |
---|
1191 | Kursori.MoveTo(new Vector(ALTKConstants.WindowWidth / 2.0, Kursori.Position.Y), 1000000.0); |
---|
1192 | else if (Kursori.Position.X < ALTKConstants.WindowWidth / -2.0) |
---|
1193 | Kursori.MoveTo(new Vector(ALTKConstants.WindowWidth / -2.0, Kursori.Position.Y), 1000000.0); |
---|
1194 | |
---|
1195 | if (Kursori.Position.Y > ALTKConstants.WindowHeight / 2.0) |
---|
1196 | Kursori.MoveTo(new Vector(Kursori.Position.X, ALTKConstants.WindowHeight / 2.0), 1000000.0); |
---|
1197 | else if (Kursori.Position.Y < ALTKConstants.WindowHeight / -2.0) |
---|
1198 | Kursori.MoveTo(new Vector(Kursori.Position.X, ALTKConstants.WindowHeight / -2.0), 1000000.0); |
---|
1199 | |
---|
1200 | ALTK.Cursor.SecPosX = Convert.ToInt32((ALTKConstants.WindowWidth / 2) + Kursori.Position.X * 1.12); |
---|
1201 | ALTK.Cursor.SecPosY = Convert.ToInt32(ALTK.ALTKConstants.WindowHeight - ((ALTKConstants.WindowHeight / 2) + Kursori.Position.Y * 1.12)); |
---|
1202 | |
---|
1203 | if (ALTK.GameHandler.DoUpdate) |
---|
1204 | { |
---|
1205 | } |
---|
1206 | else |
---|
1207 | { |
---|
1208 | //PhysicsEnabled = false; |
---|
1209 | } |
---|
1210 | } |
---|
1211 | |
---|
1212 | /// <summary> |
---|
1213 | /// Initializes the ALTKEngine components used by the game. -Rampastring |
---|
1214 | /// </summary> |
---|
1215 | private void InitALTK() |
---|
1216 | { |
---|
1217 | ALTKConstants.WindowWidth = this.Window.ClientBounds.Width; |
---|
1218 | ALTKConstants.WindowHeight = this.Window.ClientBounds.Height; |
---|
1219 | |
---|
1220 | if (ALTKConstants.WindowHeight / ALTKConstants.WindowWidth < 0.9) |
---|
1221 | { |
---|
1222 | ALTKConstants.JypeliToXNARatioY = Convert.ToDouble(ALTKConstants.WindowHeight) / Convert.ToDouble(ALTKConstants.JYDefaultResY); |
---|
1223 | ALTKConstants.JypeliToXNARatioX = ALTKConstants.JypeliToXNARatioY; |
---|
1224 | } |
---|
1225 | else // if (ALTKConstants.WindowHeight > ALTKConstants.WindowWidth) |
---|
1226 | { |
---|
1227 | ALTKConstants.JypeliToXNARatioX = Convert.ToDouble(ALTKConstants.WindowWidth) / Convert.ToDouble(ALTKConstants.JYDefaultResX); |
---|
1228 | ALTKConstants.JypeliToXNARatioY = ALTKConstants.JypeliToXNARatioX; |
---|
1229 | } |
---|
1230 | |
---|
1231 | ALTKConstants.StaticAnimRatioY = Convert.ToDouble(ALTKConstants.WindowHeight) / ALTKConstants.StaticAnimDevelopResY; |
---|
1232 | ALTKConstants.StaticAnimRatioX = Convert.ToDouble(ALTKConstants.WindowWidth) / ALTKConstants.StaticAnimDevelopResX; |
---|
1233 | |
---|
1234 | if (ALTKConstants.StaticAnimRatioY > ALTKConstants.StaticAnimRatioX) |
---|
1235 | ALTKConstants.StaticAnimRatioY = ALTKConstants.StaticAnimRatioX; |
---|
1236 | else |
---|
1237 | ALTKConstants.StaticAnimRatioX = ALTKConstants.StaticAnimRatioY; |
---|
1238 | |
---|
1239 | altkHandler = new ALTKHandler(this); |
---|
1240 | altkHandler.Initialize(); |
---|
1241 | this.Components.Add(altkHandler); |
---|
1242 | |
---|
1243 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARS_1", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1244 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARS_2", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1245 | |
---|
1246 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1247 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY_BLUE", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1248 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY_RED", new Microsoft.Xna.Framework.Vector2(200, 100)); |
---|
1249 | ALTKHandler.StaticAnimHandler.AddStaticAnim("GALAXY_WHITE", new Microsoft.Xna.Framework.Vector2(0, 0)); |
---|
1250 | |
---|
1251 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE", new Microsoft.Xna.Framework.Vector2(200, -250)); |
---|
1252 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE_BLUE", new Microsoft.Xna.Framework.Vector2(400, 250)); |
---|
1253 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE_RED", new Microsoft.Xna.Framework.Vector2(-350, -200)); |
---|
1254 | ALTKHandler.StaticAnimHandler.AddStaticAnim("STARSMOKE_WHITE", new Microsoft.Xna.Framework.Vector2(-300, 250)); |
---|
1255 | |
---|
1256 | } |
---|
1257 | |
---|
1258 | private void ShowExit() |
---|
1259 | { |
---|
1260 | //this.StopAll(); |
---|
1261 | if (!ALTKHandler.ExitWindow.Enabled) |
---|
1262 | { |
---|
1263 | ALTKHandler.ExitWindow.Enabled = true; |
---|
1264 | ALTKHandler.ExitWindow.Visible = true; |
---|
1265 | |
---|
1266 | Kursori.IsVisible = true; |
---|
1267 | } |
---|
1268 | } |
---|
1269 | |
---|
1270 | #endregion |
---|
1271 | } |
---|