1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | public class kill_everypody_GAME : PhysicsGame |
---|
10 | { |
---|
11 | const double nopeus = 200; |
---|
12 | const double hyppyNopeus = 750; |
---|
13 | const int RUUDUN_KOKO = 40; |
---|
14 | |
---|
15 | PlatformCharacter pelaaja1; |
---|
16 | bool voikoPelaajaAmpua = true; |
---|
17 | Image DragonJonnenKuva = LoadImage("DragonJonne"); |
---|
18 | Image VihunKuva = LoadImage("Vihu"); |
---|
19 | Image[] seisomisanimaatio = LoadImages("Trollface"); |
---|
20 | Image[] kävelykuvat = LoadImages("Trollface", "Trollface2"); |
---|
21 | Image[] hyokkausanimaatio = LoadImages("Trollfaceampuu"); |
---|
22 | |
---|
23 | Image esKuva = LoadImage("es"); |
---|
24 | Image ammusKuva = LoadImage("Panos"); |
---|
25 | Timer lataaEnergiaaAjastin = new Timer(); |
---|
26 | DoubleMeter energia; |
---|
27 | DoubleMeter elamat; |
---|
28 | IntMeter esLaskuri; |
---|
29 | Vector? maaliAlue; |
---|
30 | |
---|
31 | SoundEffect laaserAani = LoadSoundEffect("maali"); |
---|
32 | int nykyinenKentta = 1; |
---|
33 | |
---|
34 | |
---|
35 | public override void Begin() |
---|
36 | |
---|
37 | |
---|
38 | { |
---|
39 | AloitaKentta(nykyinenKentta); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | void AloitaKentta(int kentanNro) |
---|
44 | { |
---|
45 | ClearAll(); |
---|
46 | Gravity = new Vector(0, -1000); |
---|
47 | |
---|
48 | LisaaLaskuri(); |
---|
49 | LuoKentta("kentta" + kentanNro); |
---|
50 | LisaaNappaimet(); |
---|
51 | |
---|
52 | LisaaEnergiaPalkki(); |
---|
53 | LisaaElamaPalkki(); |
---|
54 | |
---|
55 | lataaEnergiaaAjastin = new Timer(); |
---|
56 | lataaEnergiaaAjastin.Interval = 0.2; |
---|
57 | lataaEnergiaaAjastin.Timeout += delegate { energia.Value += 1; }; |
---|
58 | lataaEnergiaaAjastin.Start(); |
---|
59 | |
---|
60 | Camera.Follow(pelaaja1); |
---|
61 | Camera.ZoomFactor = 1.2; |
---|
62 | Camera.StayInLevel = true; |
---|
63 | |
---|
64 | nykyinenKentta = kentanNro; |
---|
65 | } |
---|
66 | |
---|
67 | void SeuraavaKentta() |
---|
68 | { |
---|
69 | if (nykyinenKentta < 4) |
---|
70 | { |
---|
71 | AloitaKentta(nykyinenKentta + 1); |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | VoititPelin(); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | void VoititPelin() |
---|
80 | { |
---|
81 | ClearAll(); |
---|
82 | Label teksti = new Label("Voitit pelin"); |
---|
83 | Add(teksti); |
---|
84 | |
---|
85 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, null); |
---|
86 | } |
---|
87 | |
---|
88 | void LisaaEnergiaPalkki() |
---|
89 | { |
---|
90 | energia = new DoubleMeter(100, 0, 100); |
---|
91 | energia.LowerLimit += delegate { voikoPelaajaAmpua = false; }; |
---|
92 | energia.AddTrigger(20, TriggerDirection.Up, delegate(double d) { voikoPelaajaAmpua = true; }); |
---|
93 | ProgressBar energiaPalkki = new ProgressBar(200, 35); |
---|
94 | energiaPalkki.Position = new Vector(Screen.Right - 150, Screen.Top - 50); |
---|
95 | energiaPalkki.Color = Color.Blue; |
---|
96 | energiaPalkki.BarColor = Color.Violet; |
---|
97 | energiaPalkki.BindTo(energia); |
---|
98 | Add(energiaPalkki); |
---|
99 | |
---|
100 | } |
---|
101 | void LisaaElamaPalkki() |
---|
102 | { |
---|
103 | elamat = new DoubleMeter(10, 0, 10); |
---|
104 | elamat.LowerLimit += delegate { ClearAll(); AloitaKentta(nykyinenKentta); }; |
---|
105 | |
---|
106 | ProgressBar ElamaPalkki = new ProgressBar(200, 35); |
---|
107 | ElamaPalkki.Position = new Vector(Screen.Right - 150, Screen.Top - 10); |
---|
108 | ElamaPalkki.Color = Color.Blue; |
---|
109 | ElamaPalkki.BarColor = Color.Red; |
---|
110 | ElamaPalkki.BindTo(elamat); |
---|
111 | Add(ElamaPalkki); |
---|
112 | } |
---|
113 | void LuoKentta(string kentanNimi) |
---|
114 | { |
---|
115 | |
---|
116 | TileMap kentta = TileMap.FromLevelAsset(kentanNimi); |
---|
117 | kentta.SetTileMethod('#', LisaaTaso); |
---|
118 | |
---|
119 | kentta.SetTileMethod('M', LisaaMaali); |
---|
120 | kentta.SetTileMethod('O', LisaaDragonJonne); |
---|
121 | kentta.SetTileMethod('*', LisaaTahti); |
---|
122 | kentta.SetTileMethod('N', LisaaPelaaja); |
---|
123 | kentta.SetTileMethod('V', LisaaVihu); |
---|
124 | |
---|
125 | maaliAlue = null; |
---|
126 | |
---|
127 | kentta.Execute(RUUDUN_KOKO, RUUDUN_KOKO); |
---|
128 | Level.CreateBorders(); |
---|
129 | Level.Background.Image = LoadImage("Tausta"); |
---|
130 | Level.Background.FitToLevel(); |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | void LisaaMaali(Vector paikka, double leveys, double korkeys) |
---|
135 | { |
---|
136 | maaliAlue = paikka; |
---|
137 | |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | void LisaaDragonJonne(Vector paikka, double leveys, double korkeys) |
---|
142 | { |
---|
143 | |
---|
144 | DragonJonne DragonJonne = new DragonJonne(leveys * 6.9, korkeys * 6.5, 80); |
---|
145 | //DragonJonne.IgnoresCollisionResponse = true; |
---|
146 | DragonJonne.Restitution = 10.0; |
---|
147 | DragonJonne.IgnoresGravity = true; |
---|
148 | DragonJonne.Position = paikka; |
---|
149 | //vihu.Color = Color.Red; |
---|
150 | DragonJonne.Image = DragonJonnenKuva; |
---|
151 | DragonJonne.Tag = "DragonJonne"; |
---|
152 | DragonJonne.Shape = Shape.Circle; |
---|
153 | Add(DragonJonne); |
---|
154 | |
---|
155 | |
---|
156 | if (maaliAlue != null) |
---|
157 | { |
---|
158 | DragonJonne.MoveTo((Vector)maaliAlue, nopeus - 50, JonneVoittaa); |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | Timer ajastin = new Timer(); |
---|
163 | ajastin.Interval = 2.0; |
---|
164 | ajastin.Timeout += delegate { DragonJonne.Hit(RandomGen.NextVector(200.0, 300.0)); }; |
---|
165 | ajastin.Start(); |
---|
166 | |
---|
167 | DragonJonne.Elamat.LowerLimit += VoititPelin; |
---|
168 | } |
---|
169 | |
---|
170 | GameObject palkinPaikka = new GameObject(50, 50); |
---|
171 | palkinPaikka.Position = new Vector(0, 150); |
---|
172 | palkinPaikka.IsVisible = false; |
---|
173 | //Add(palkinPaikka); |
---|
174 | DragonJonne.Add(palkinPaikka); |
---|
175 | |
---|
176 | ProgressBar DragonJonnenElamat = new ProgressBar(70, 30); |
---|
177 | DragonJonnenElamat.IsVisible = true; |
---|
178 | DragonJonnenElamat.BindTo(DragonJonne.Elamat); |
---|
179 | palkinPaikka.Add(DragonJonnenElamat); |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | } |
---|
184 | |
---|
185 | |
---|
186 | void JonneVoittaa() |
---|
187 | { |
---|
188 | |
---|
189 | MessageDisplay.Add("JONNE WON!"); pelaaja1.Destroy(); |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | void LisaaVihu(Vector paikka, double leveys, double korkeus) |
---|
196 | { |
---|
197 | |
---|
198 | Vihu vihu = new Vihu(leveys * 1.5, korkeus * 1.5, 5); |
---|
199 | vihu.Position = paikka; |
---|
200 | //vihu.Color = Color.Red; |
---|
201 | vihu.Image = VihunKuva; |
---|
202 | vihu.MirrorImage(); |
---|
203 | vihu.Tag = "Vihu"; |
---|
204 | Add(vihu); |
---|
205 | |
---|
206 | PlatformWandererBrain Aivot = new PlatformWandererBrain(); |
---|
207 | Aivot.Speed = nopeus - 50; |
---|
208 | vihu.Brain = Aivot; |
---|
209 | |
---|
210 | GameObject palkinPaikka = new GameObject(50, 50); |
---|
211 | palkinPaikka.Position = new Vector(0, 50); |
---|
212 | palkinPaikka.IsVisible = false; |
---|
213 | //Add(palkinPaikka); |
---|
214 | vihu.Add(palkinPaikka); |
---|
215 | |
---|
216 | ProgressBar vihunElamat = new ProgressBar(70, 30); |
---|
217 | vihunElamat.IsVisible = true; |
---|
218 | vihunElamat.BindTo(vihu.Elamat); |
---|
219 | palkinPaikka.Add(vihunElamat); |
---|
220 | |
---|
221 | |
---|
222 | } |
---|
223 | void LisaaLaskuri() |
---|
224 | { |
---|
225 | esLaskuri = new IntMeter(0, 0, 6); |
---|
226 | esLaskuri.UpperLimit += SeuraavaKentta; |
---|
227 | |
---|
228 | Label pisteNaytto = new Label(); |
---|
229 | pisteNaytto.Left = Screen.Left + 50; |
---|
230 | pisteNaytto.Top = Screen.Top - 50; |
---|
231 | pisteNaytto.TextColor = Color.White; |
---|
232 | pisteNaytto.Color = Color.Black; |
---|
233 | |
---|
234 | pisteNaytto.BindTo(esLaskuri); |
---|
235 | Add(pisteNaytto); |
---|
236 | } |
---|
237 | |
---|
238 | void LisaaTaso(Vector paikka, double leveys, double korkeus) |
---|
239 | { |
---|
240 | PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
241 | taso.Position = paikka; |
---|
242 | taso.Color = Color.Green; |
---|
243 | Add(taso); |
---|
244 | } |
---|
245 | |
---|
246 | void LisaaTahti(Vector paikka, double leveys, double korkeus) |
---|
247 | { |
---|
248 | PhysicsObject tahti = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
249 | tahti.IgnoresCollisionResponse = true; |
---|
250 | tahti.Position = paikka; |
---|
251 | tahti.Image = esKuva; |
---|
252 | tahti.Tag = "es"; |
---|
253 | Add(tahti); |
---|
254 | } |
---|
255 | |
---|
256 | void LisaaPelaaja(Vector paikka, double leveys, double korkeus) |
---|
257 | { |
---|
258 | pelaaja1 = new PlatformCharacter(leveys, korkeus); |
---|
259 | pelaaja1.Position = paikka; |
---|
260 | pelaaja1.Mass = 4.0; |
---|
261 | pelaaja1.AnimWalk = new Animation(kävelykuvat); |
---|
262 | pelaaja1.AnimIdle = new Animation(seisomisanimaatio); |
---|
263 | AddCollisionHandler(pelaaja1, "es", TormaaTahteen); |
---|
264 | AddCollisionHandler(pelaaja1, "Vihu", TormaaVihuun); |
---|
265 | AddCollisionHandler(pelaaja1, "DragonJonne", TormaaVihuun); |
---|
266 | |
---|
267 | //pelaaja1 on PlatformCharacter-tyyppinen |
---|
268 | pelaaja1.Weapon = new AssaultRifle(30, 10); |
---|
269 | |
---|
270 | //Ammusten määrä aluksi: |
---|
271 | pelaaja1.Weapon.Ammo.Value = 5000; |
---|
272 | pelaaja1.Weapon.FireRate = 5000; |
---|
273 | pelaaja1.Weapon.IsVisible = false; |
---|
274 | //Mitä tapahtuu kun ammus osuu johonkin? |
---|
275 | pelaaja1.Weapon.ProjectileCollision = AmmusOsui; |
---|
276 | |
---|
277 | Add(pelaaja1); |
---|
278 | } |
---|
279 | |
---|
280 | void TormaaVihuun(PhysicsObject pelaaja, PhysicsObject vihu) |
---|
281 | { |
---|
282 | elamat.Value -= 3; |
---|
283 | } |
---|
284 | |
---|
285 | |
---|
286 | void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde) |
---|
287 | { |
---|
288 | ammus.Destroy(); |
---|
289 | |
---|
290 | if (kohde is Vihu) |
---|
291 | { |
---|
292 | ((Vihu)kohde).Elamat.Value -= 0.2; |
---|
293 | } |
---|
294 | |
---|
295 | if (kohde is DragonJonne) |
---|
296 | { |
---|
297 | ((DragonJonne)kohde).Elamat.Value -= 0.2; |
---|
298 | } |
---|
299 | } |
---|
300 | |
---|
301 | |
---|
302 | void AmmuAseella(PlatformCharacter pelaaja) |
---|
303 | { |
---|
304 | if (!voikoPelaajaAmpua) return; |
---|
305 | PhysicsObject ammus = pelaaja.Weapon.Shoot(); |
---|
306 | pelaaja1.PlayAnimation(new Animation(hyokkausanimaatio)); |
---|
307 | energia.Value--; |
---|
308 | |
---|
309 | if (ammus != null) |
---|
310 | { |
---|
311 | ammus.Width *= 2; |
---|
312 | ammus.Image = ammusKuva; |
---|
313 | ammus.MaximumLifetime = TimeSpan.FromSeconds(1.0); |
---|
314 | } |
---|
315 | } |
---|
316 | |
---|
317 | void AloitaPeli() |
---|
318 | { |
---|
319 | } |
---|
320 | |
---|
321 | |
---|
322 | |
---|
323 | void LisaaNappaimet() |
---|
324 | { |
---|
325 | Keyboard.Listen(Key.Space, ButtonState.Down, AmmuAseella, "Ammu", pelaaja1); |
---|
326 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
327 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
328 | |
---|
329 | Keyboard.Listen(Key.Left, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, -nopeus); |
---|
330 | Keyboard.Listen(Key.Right, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, nopeus); |
---|
331 | Keyboard.Listen(Key.Up, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus); |
---|
332 | Keyboard.Listen(Key.R, ButtonState.Pressed, AloitaPeli, "Aloittaa pelin uudelleen"); |
---|
333 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
334 | |
---|
335 | ControllerOne.Listen(Button.DPadLeft, ButtonState.Down, Liikuta, "Pelaaja liikkuu vasemmalle", pelaaja1, -nopeus); |
---|
336 | ControllerOne.Listen(Button.DPadRight, ButtonState.Down, Liikuta, "Pelaaja liikkuu oikealle", pelaaja1, nopeus); |
---|
337 | ControllerOne.Listen(Button.A, ButtonState.Pressed, Hyppaa, "Pelaaja hyppää", pelaaja1, hyppyNopeus); |
---|
338 | |
---|
339 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
340 | } |
---|
341 | |
---|
342 | void Liikuta(PlatformCharacter hahmo, double nopeus) |
---|
343 | { |
---|
344 | if (maaliAlue != null) |
---|
345 | { |
---|
346 | if (hahmo.Position.X >= maaliAlue.Value.X) |
---|
347 | { |
---|
348 | SeuraavaKentta(); |
---|
349 | } |
---|
350 | } |
---|
351 | hahmo.Walk(nopeus); |
---|
352 | } |
---|
353 | |
---|
354 | void Hyppaa(PlatformCharacter hahmo, double nopeus) |
---|
355 | { |
---|
356 | hahmo.Jump(nopeus); |
---|
357 | } |
---|
358 | |
---|
359 | void TormaaTahteen(PhysicsObject hahmo, PhysicsObject tahti) |
---|
360 | { |
---|
361 | MessageDisplay.Add("Keräsit es energia juoman!"); |
---|
362 | esLaskuri.AddValue(1); |
---|
363 | tahti.Destroy(); |
---|
364 | } |
---|
365 | |
---|
366 | |
---|
367 | } |
---|
368 | |
---|
369 | public class Vihu : PlatformCharacter |
---|
370 | { |
---|
371 | DoubleMeter elamat; |
---|
372 | public DoubleMeter Elamat { get { return elamat; } } |
---|
373 | public Vihu(double leveys, double korkeus, int elamia) |
---|
374 | : base(leveys, korkeus) |
---|
375 | { |
---|
376 | elamat = new DoubleMeter(elamia, 0, elamia); |
---|
377 | elamat.LowerLimit += delegate { this.Destroy(); }; |
---|
378 | } |
---|
379 | |
---|
380 | |
---|
381 | |
---|
382 | |
---|
383 | } |
---|
384 | |
---|
385 | public class DragonJonne : PhysicsObject |
---|
386 | { |
---|
387 | DoubleMeter elamat; |
---|
388 | public DoubleMeter Elamat { get { return elamat; } } |
---|
389 | public DragonJonne(double leveys, double korkeus, int elamia) |
---|
390 | : base(leveys, korkeus) |
---|
391 | |
---|
392 | { |
---|
393 | elamat = new DoubleMeter(elamia, 0, elamia); |
---|
394 | elamat.LowerLimit += delegate { this.Destroy(); }; |
---|
395 | } |
---|
396 | |
---|
397 | |
---|
398 | |
---|
399 | |
---|
400 | } |
---|