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 | using System.IO; |
---|
9 | |
---|
10 | public class UltimateAdventure : PhysicsGame |
---|
11 | { |
---|
12 | double nopeus = 200; |
---|
13 | const double JumpSpeed = 750; |
---|
14 | const int RUUDUN_KOKO = 40; |
---|
15 | IntMeter Pommit = new IntMeter(50); |
---|
16 | Double Painovoima = -1000; |
---|
17 | DoubleMeter DrownTime = new DoubleMeter (0.5); |
---|
18 | bool saapiiskata = true; |
---|
19 | bool saapommittaa = true; |
---|
20 | bool NinjaIsRaged = false; |
---|
21 | PushButton TextureButton; |
---|
22 | PushButton FullScreenButton; |
---|
23 | DoubleMeter aani = new DoubleMeter(0, 0, 1); |
---|
24 | private IntMeter OxygenMeter; |
---|
25 | List<string> destroybleThings = new List<string>(new string[]{ "PhysicsBlock", "moonstone", "turret", "snake", "silmamob","wizard","Ninja"}); |
---|
26 | |
---|
27 | PlatformCharacter pelaaja1; |
---|
28 | IntMeter elamaLaskuri; |
---|
29 | |
---|
30 | Image tahtiKuva = LoadImage("tahti"); |
---|
31 | Image Bpimage = LoadImage("stoneplatform"); |
---|
32 | Image silmamobimage = LoadImage("silmamob"); |
---|
33 | Image veripartikkeli = LoadImage("veripartikkeli"); |
---|
34 | Image playerhealth = LoadImage("playerhealth"); |
---|
35 | Image Bomb = LoadImage("bomb"); |
---|
36 | Image Arrow = LoadImage("Arrow"); |
---|
37 | Image PhysicBlockImage = LoadImage("PhysicBlockTexture"); |
---|
38 | Image TurretImage = LoadImage("TurretTextureV1"); |
---|
39 | Image Snake = LoadImage("snake"); |
---|
40 | Image Player = LoadImage("PlayerV2"); |
---|
41 | Image SpeedShoeImage = LoadImage("SpeedShoe"); |
---|
42 | //Image MoonstoneImage = LoadImage("Moonstone"); |
---|
43 | Image WizardrWand = LoadImage("WizardingWandV3"); |
---|
44 | Image LogoImage = LoadImage("LogoV1"); |
---|
45 | Image NinjaImage = LoadImage("Ninja"); |
---|
46 | Image Ninjathings = LoadImage("NinjaThings"); |
---|
47 | Image WizParticle = LoadImage("WizardingParticle"); |
---|
48 | Image AchivementBottom = LoadImage("AchivementBottom"); |
---|
49 | //Image marsstone = LoadImage("marsstone"); |
---|
50 | Image OxygenBottleImage = LoadImage("OxygenBottle"); |
---|
51 | Image NinjaStarImage = LoadImage("Shurigen"); |
---|
52 | Image Empty = LoadImage("Empty"); |
---|
53 | Image LittleGreenMan = LoadImage("LittleGreenManV2"); |
---|
54 | |
---|
55 | SoundEffect maaliAani = LoadSoundEffect("maali"); |
---|
56 | SoundEffect WizardZap = LoadSoundEffect("WizardZap"); |
---|
57 | Animation Ruoskanimaatio; |
---|
58 | Animation Snakiitio; |
---|
59 | |
---|
60 | GameObject Logo; |
---|
61 | |
---|
62 | double aanenvoimakkuus = 0.1; |
---|
63 | |
---|
64 | public override void Begin() |
---|
65 | { |
---|
66 | Snakiitio = LoadAnimation("SnakeV2"); |
---|
67 | Ruoskanimaatio = LoadAnimation("ruoska"); |
---|
68 | DataSave tulos = null; |
---|
69 | tulos = DataStorage.Load<DataSave>(tulos, "Options.xml"); |
---|
70 | SmoothTextures = tulos.IsSmoothTex; |
---|
71 | IsFullScreen = tulos.FullScreen; |
---|
72 | aani.Value = tulos.Volume; |
---|
73 | LuoAlkuValikko(); |
---|
74 | |
---|
75 | |
---|
76 | } |
---|
77 | |
---|
78 | void LuoAlkuValikko() |
---|
79 | { |
---|
80 | ClearAll(); |
---|
81 | LuoLogo(); |
---|
82 | MultiSelectWindow alkuValikko = new MultiSelectWindow("UltimateAdventure", "Aloita peli", "Options", "Avaa valittu kenttä","Trophies","Lopeta"); |
---|
83 | |
---|
84 | alkuValikko.AddItemHandler(0, AloitaPeli); |
---|
85 | alkuValikko.AddItemHandler(1, MenuOptions); |
---|
86 | alkuValikko.AddItemHandler(2, SelectLevel); |
---|
87 | alkuValikko.AddItemHandler(3, Achivement); |
---|
88 | alkuValikko.AddItemHandler(4, Exit); |
---|
89 | |
---|
90 | Add(alkuValikko); |
---|
91 | } |
---|
92 | void LuoPeliValikko() |
---|
93 | { |
---|
94 | MultiSelectWindow Pelivalikko = new MultiSelectWindow(" ", "Jatka peliä", "Options", "Lopeta"); |
---|
95 | |
---|
96 | //Pelivalikko.AddItemHandler(0, AloitaPeli); |
---|
97 | Pelivalikko.AddItemHandler(1, PeliOptions); |
---|
98 | Pelivalikko.AddItemHandler(2, Exit); |
---|
99 | |
---|
100 | Add(Pelivalikko); |
---|
101 | } |
---|
102 | |
---|
103 | void LuoLogo() |
---|
104 | { |
---|
105 | Logo = new GameObject(1000,120); |
---|
106 | Logo.Y = Level.Top-100; |
---|
107 | Logo.Image = LogoImage; |
---|
108 | Add(Logo); |
---|
109 | |
---|
110 | Label teksti = new Label("Beta"); |
---|
111 | teksti.X = Screen.Right - 470; |
---|
112 | teksti.Y = Screen.Top - 300; |
---|
113 | teksti.TextScale *= 1.5; |
---|
114 | teksti.TextColor = Color.Black; |
---|
115 | Add(teksti); |
---|
116 | } |
---|
117 | void AloitaPeli() |
---|
118 | { |
---|
119 | StartLevel("kentta1"); |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | void Achivement() |
---|
124 | { |
---|
125 | GameObject Achivementbottom = new GameObject(300,70); |
---|
126 | int Acloop = 0; |
---|
127 | while (Acloop < 11) |
---|
128 | { |
---|
129 | Achivementbottom.Y = Level.Top - 100 * Acloop; |
---|
130 | Acloop = Acloop + 1; |
---|
131 | } |
---|
132 | Achivementbottom.Image = AchivementBottom; |
---|
133 | Add(Achivementbottom); |
---|
134 | BackButton(); |
---|
135 | Logo.Destroy(); |
---|
136 | IsMouseVisible = true; |
---|
137 | } |
---|
138 | void StartLevel(String LevelName) |
---|
139 | { |
---|
140 | ClearAll(); |
---|
141 | Gravity = new Vector(0, Painovoima); |
---|
142 | |
---|
143 | AddLevel(LevelName); |
---|
144 | LisaaNappaimet(); |
---|
145 | LuoElamaLaskuri(); |
---|
146 | CreateOxygenMeter(); |
---|
147 | Camera.Follow(pelaaja1); |
---|
148 | Camera.ZoomFactor = 2.8; |
---|
149 | Camera.StayInLevel = true; |
---|
150 | |
---|
151 | Label PommienMaara = new Label(Pommit); |
---|
152 | PommienMaara.X = Screen.Right - 150; |
---|
153 | PommienMaara.Y = Screen.Top - 150; |
---|
154 | Add(PommienMaara); |
---|
155 | |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | void MenuOptions() |
---|
160 | { |
---|
161 | Options(); |
---|
162 | BackButton(); |
---|
163 | } |
---|
164 | void Options() |
---|
165 | { |
---|
166 | Mouse.IsCursorVisible = true; |
---|
167 | Slider liukusaadin = LuoSlider(); |
---|
168 | Add(liukusaadin); |
---|
169 | TeeTextureButton(); |
---|
170 | TeeFullScreenButton(); |
---|
171 | } |
---|
172 | |
---|
173 | void SelectLevel() |
---|
174 | { |
---|
175 | InputWindow AskWindow = new InputWindow("What level you want to play."); |
---|
176 | AskWindow.TextEntered += ProcessInput; |
---|
177 | Add(AskWindow); |
---|
178 | BackButton(); |
---|
179 | } |
---|
180 | |
---|
181 | void ProcessInput(InputWindow window) |
---|
182 | { |
---|
183 | string answer = window.InputBox.Text; |
---|
184 | if (answer == null || answer == "") return; |
---|
185 | FileStream stream = null; |
---|
186 | bool success = true; |
---|
187 | try |
---|
188 | { |
---|
189 | stream = File.Open("Content\\" + answer+".xnb", FileMode.Open); |
---|
190 | } |
---|
191 | catch (FileNotFoundException f) |
---|
192 | { |
---|
193 | success = false; |
---|
194 | } |
---|
195 | finally |
---|
196 | { |
---|
197 | if(stream != null) |
---|
198 | stream.Close(); |
---|
199 | } |
---|
200 | if (success) |
---|
201 | StartLevel(answer); |
---|
202 | else |
---|
203 | SelectLevel(); |
---|
204 | } |
---|
205 | |
---|
206 | |
---|
207 | void PeliOptions() |
---|
208 | { |
---|
209 | Options(); |
---|
210 | TeeSuljePeliOptions(); |
---|
211 | } |
---|
212 | void TeeTextureButton() |
---|
213 | { |
---|
214 | TextureButton = new PushButton("" + SmoothTextures); |
---|
215 | TextureButton.Y = -100; |
---|
216 | TextureButton.Clicked += PaivitaTextureButton; |
---|
217 | TextureButton.Tag = "Options"; |
---|
218 | |
---|
219 | Add(TextureButton); |
---|
220 | } |
---|
221 | void PaivitaTextureButton() |
---|
222 | { |
---|
223 | SmoothTextures = !SmoothTextures; |
---|
224 | TextureButton.Text = "" + SmoothTextures; |
---|
225 | } |
---|
226 | |
---|
227 | void TeeFullScreenButton() |
---|
228 | { |
---|
229 | FullScreenButton = new PushButton("" + IsFullScreen); |
---|
230 | FullScreenButton.Y = -150; |
---|
231 | FullScreenButton.Clicked += PaivitaFullScreen; |
---|
232 | FullScreenButton.Tag = "Options"; |
---|
233 | |
---|
234 | Add(FullScreenButton); |
---|
235 | } |
---|
236 | |
---|
237 | void PaivitaFullScreen() |
---|
238 | { |
---|
239 | if (IsFullScreen = false); |
---|
240 | IsFullScreen = !IsFullScreen; |
---|
241 | FullScreenButton.Text = "" + IsFullScreen; |
---|
242 | } |
---|
243 | |
---|
244 | Slider LuoSlider() |
---|
245 | { |
---|
246 | |
---|
247 | aani.Changed += MuutaAanenvoimakuutta; |
---|
248 | |
---|
249 | Slider liukusaadin = new Slider(200, 20); |
---|
250 | liukusaadin.BindTo(aani); |
---|
251 | liukusaadin.Tag = "Options"; |
---|
252 | liukusaadin.X = 0; |
---|
253 | liukusaadin.Y = 0; |
---|
254 | |
---|
255 | liukusaadin.Color = Color.GreenYellow; |
---|
256 | liukusaadin.Knob.Image = tahtiKuva; |
---|
257 | liukusaadin.Track.Color = Color.Black; |
---|
258 | liukusaadin.BorderColor = Color.LightBlue; |
---|
259 | |
---|
260 | return liukusaadin; |
---|
261 | |
---|
262 | } |
---|
263 | void BackButton() |
---|
264 | { |
---|
265 | PushButton BackNappain = new PushButton("Back"); |
---|
266 | BackNappain.Y = -300; |
---|
267 | BackNappain.Clicked += SaveOptions; |
---|
268 | BackNappain.Clicked += LuoAlkuValikko; |
---|
269 | |
---|
270 | Add(BackNappain); |
---|
271 | } |
---|
272 | |
---|
273 | void SaveOptions() |
---|
274 | { |
---|
275 | DataSave save = new DataSave(); |
---|
276 | save.IsSmoothTex = SmoothTextures; |
---|
277 | save.Volume = aani.Value; |
---|
278 | DataStorage.Save<DataSave>(save, "Options.xml"); |
---|
279 | |
---|
280 | |
---|
281 | } |
---|
282 | void TeeSuljePeliOptions() |
---|
283 | { |
---|
284 | PushButton SuljePeliOptions = new PushButton("Back"); |
---|
285 | SuljePeliOptions.Y = -300; |
---|
286 | SuljePeliOptions.Tag = "Options"; |
---|
287 | SuljePeliOptions.Clicked += SaveOptions; |
---|
288 | SuljePeliOptions.Clicked += JatkaPelia; |
---|
289 | |
---|
290 | Add(SuljePeliOptions); |
---|
291 | } |
---|
292 | |
---|
293 | void JatkaPelia() |
---|
294 | { |
---|
295 | List<GameObject> Oliot = GetObjectsWithTag("Options"); |
---|
296 | foreach (GameObject item in Oliot) |
---|
297 | { |
---|
298 | item.Destroy(); |
---|
299 | } |
---|
300 | IsMouseVisible = false; |
---|
301 | } |
---|
302 | void MuutaAanenvoimakuutta(double vanhaArvo, double uusiArvo) |
---|
303 | { |
---|
304 | aanenvoimakkuus = uusiArvo; |
---|
305 | MessageDisplay.Add(aanenvoimakkuus.ToString()); |
---|
306 | } |
---|
307 | |
---|
308 | void AddLevel(String LevelName) |
---|
309 | { |
---|
310 | TileMap level = TileMap.FromLevelAsset(LevelName); |
---|
311 | level.SetTileMethod('#', LisaaSolid); |
---|
312 | level.SetTileMethod('&', LisaaBp); |
---|
313 | level.SetTileMethod('*', LisaaHealt); |
---|
314 | level.SetTileMethod('o', LisaaPelaaja); |
---|
315 | level.SetTileMethod('0', LisaaSilmamob); |
---|
316 | level.SetTileMethod('5', LisaaSnakemob); |
---|
317 | level.SetTileMethod('>', LisaaTurret); |
---|
318 | level.SetTileMethod('☂', PhysicBlock); |
---|
319 | level.SetTileMethod('7', LisaaSpeedBoots); |
---|
320 | level.SetTileMethod('O', LisaaPommipakkaus); |
---|
321 | level.SetTileMethod('U', Water); |
---|
322 | level.SetTileMethod('W', Wizard); |
---|
323 | level.SetTileMethod('C', Moonstone); |
---|
324 | level.SetTileMethod('N', Ninja); |
---|
325 | level.SetTileMethod('H', OxygenBottle); |
---|
326 | level.SetTileMethod('L', LisaaLGM); |
---|
327 | level.Execute(RUUDUN_KOKO, RUUDUN_KOKO); |
---|
328 | Level.CreateBorders(); |
---|
329 | Level.Background.CreateGradient(Color.SkyBlue, Color.SkyBlue); |
---|
330 | } |
---|
331 | |
---|
332 | void LisaaSolid(Vector paikka, double leveys, double korkeus) |
---|
333 | { |
---|
334 | PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
335 | taso.Position = paikka; |
---|
336 | taso.Color = RandomGen.NextColor(); |
---|
337 | Add(taso); |
---|
338 | } |
---|
339 | |
---|
340 | void LisaaBp(Vector paikka, double leveys, double korkeus) |
---|
341 | { |
---|
342 | PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
343 | taso.Position = paikka; |
---|
344 | taso.Image = Bpimage; |
---|
345 | taso.Tag = "PhysicsBlock"; |
---|
346 | Add(taso); |
---|
347 | } |
---|
348 | |
---|
349 | void LisaaTurret(Vector paikka, double leveys, double korkeus) |
---|
350 | { |
---|
351 | PhysicsObject Turret = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
352 | Turret.Position = paikka; |
---|
353 | Turret.Image = TurretImage; |
---|
354 | Turret.Tag = "turret"; |
---|
355 | Add(Turret); |
---|
356 | |
---|
357 | |
---|
358 | Timer ajastin = new Timer(); |
---|
359 | ajastin.Interval = 0.1; |
---|
360 | ajastin.Timeout += delegate |
---|
361 | { |
---|
362 | if (pelaaja1.X > Turret.X && Math.Abs(pelaaja1.Y - Turret.Y) < 20 && Turret.IsDestroyed == false) |
---|
363 | { |
---|
364 | PhysicsObject nuoli = new PhysicsObject(30, 5); |
---|
365 | nuoli.Position = Turret.Position; |
---|
366 | nuoli.Velocity = new Vector(1700, 0); |
---|
367 | Add(nuoli); |
---|
368 | nuoli.Image = Arrow; |
---|
369 | nuoli.Tag = "nuoli"; |
---|
370 | //AddCollisionHandler(nuoli, CollisionHandler.DestroyObject); |
---|
371 | ajastin.Stop(); |
---|
372 | } |
---|
373 | }; |
---|
374 | ajastin.Start(); |
---|
375 | } |
---|
376 | |
---|
377 | void PhysicBlock(Vector paikka, double leveys, double korkeus) |
---|
378 | { |
---|
379 | PhysicsObject PhysicBlock = new PhysicsObject(leveys, korkeus); |
---|
380 | PhysicBlock.Position = paikka; |
---|
381 | PhysicBlock.Image = PhysicBlockImage; |
---|
382 | PhysicBlock.Mass = 200.0; |
---|
383 | Add(PhysicBlock); |
---|
384 | } |
---|
385 | |
---|
386 | void Moonstone(Vector paikka, double leveys, double korkeus) |
---|
387 | { |
---|
388 | PhysicsObject Moonstone = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
389 | Moonstone.Position = paikka; |
---|
390 | //Moonstone.Image = MoonstoneImage; |
---|
391 | Moonstone.Tag = "moonstone"; |
---|
392 | Add(Moonstone); |
---|
393 | } |
---|
394 | |
---|
395 | |
---|
396 | void Water(Vector paikka, double leveys, double korkeus) |
---|
397 | { |
---|
398 | GameObject Water = new GameObject(leveys, korkeus); |
---|
399 | Water.Position = paikka; |
---|
400 | Water.Color = new Color(0, 0, 100, 55); |
---|
401 | Add(Water, 2); |
---|
402 | Water.Tag = "Water"; |
---|
403 | |
---|
404 | Timer ajastin = new Timer(); |
---|
405 | ajastin.Interval = 0.1; |
---|
406 | ajastin.Timeout += delegate |
---|
407 | { |
---|
408 | int palikoitaVasemmalla = GetObjectsAt(Water.Position + new Vector(-leveys, 0)).Count; |
---|
409 | int palikoitaOikealla = GetObjectsAt(Water.Position + new Vector(leveys, 0)).Count; |
---|
410 | int palikoitaAlhaalla = GetObjectsAt(Water.Position + new Vector(0, -korkeus)).Count; |
---|
411 | |
---|
412 | if (palikoitaOikealla + palikoitaVasemmalla + palikoitaAlhaalla < 6) |
---|
413 | { |
---|
414 | Water.Destroy(); |
---|
415 | ajastin.Stop(); |
---|
416 | } |
---|
417 | }; |
---|
418 | ajastin.Start(); |
---|
419 | } |
---|
420 | |
---|
421 | |
---|
422 | |
---|
423 | void LisaaHealt(Vector paikka, double leveys, double korkeus) |
---|
424 | { |
---|
425 | PhysicsObject healt = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
426 | healt.IgnoresCollisionResponse = true; |
---|
427 | healt.Position = paikka; |
---|
428 | healt.Image = tahtiKuva; |
---|
429 | healt.Tag = "healt"; |
---|
430 | Add(healt); |
---|
431 | } |
---|
432 | |
---|
433 | void LisaaPommipakkaus(Vector paikka, double leveys, double korkeus) |
---|
434 | { |
---|
435 | PhysicsObject Pommipakkaus = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
436 | Pommipakkaus.IgnoresCollisionResponse = true; |
---|
437 | Pommipakkaus.Position = paikka; |
---|
438 | //Pommipakkaus.Image = tahtiKuva; |
---|
439 | Pommipakkaus.Tag = "Pommipakkaus"; |
---|
440 | Add(Pommipakkaus); |
---|
441 | } |
---|
442 | void LisaaSpeedBoots(Vector paikka, double leveys, double korkeus) |
---|
443 | { |
---|
444 | PhysicsObject SpeedShoe = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
445 | SpeedShoe.IgnoresCollisionResponse = true; |
---|
446 | SpeedShoe.Position = paikka; |
---|
447 | SpeedShoe.Tag = "SpeedBoots"; |
---|
448 | SpeedShoe.Image = SpeedShoeImage; |
---|
449 | Add(SpeedShoe); |
---|
450 | } |
---|
451 | void LisaaPelaaja(Vector paikka, double leveys, double korkeus) |
---|
452 | { |
---|
453 | pelaaja1 = new PlatformCharacter(leveys, korkeus); |
---|
454 | pelaaja1.Position = paikka; |
---|
455 | pelaaja1.Mass = 4.0; |
---|
456 | pelaaja1.Image = Player; |
---|
457 | pelaaja1.Tag = "pelaaja"; |
---|
458 | pelaaja1.Mass = 100.0; |
---|
459 | AddCollisionHandler(pelaaja1, "healt", TormaaHealtiin); |
---|
460 | AddCollisionHandler(pelaaja1, "silmamob", TormaaSilmaMobiin); |
---|
461 | AddCollisionHandler(pelaaja1, "snake", TormaaSnakeen); |
---|
462 | AddCollisionHandler(pelaaja1, "nuoli", TormaaNuoleen); |
---|
463 | AddCollisionHandler(pelaaja1, "SpeedBoots", TormaaSpeedBootsiin); |
---|
464 | AddCollisionHandler(pelaaja1, "Pommipakkaus", TormaaPommipakkaukseen); |
---|
465 | AddCollisionHandler(pelaaja1, "Ammo", AmmoTormaus); |
---|
466 | AddCollisionHandler(pelaaja1, "OxygenBottle", OxygenBotle); |
---|
467 | AddCollisionHandler(pelaaja1, "Lgm", TormaaLGM); |
---|
468 | Add(pelaaja1); |
---|
469 | } |
---|
470 | |
---|
471 | void OxygenBottle(Vector paikka, double leveys, double korkeus) |
---|
472 | { |
---|
473 | PhysicsObject OxygenBottle = PhysicsObject.CreateStaticObject(leveys / 2, korkeus / 2); |
---|
474 | OxygenBottle.IgnoresCollisionResponse = true; |
---|
475 | OxygenBottle.Position = paikka; |
---|
476 | OxygenBottle.Tag = "OxygenBottle"; |
---|
477 | OxygenBottle.Image = OxygenBottleImage; |
---|
478 | Add(OxygenBottle); |
---|
479 | } |
---|
480 | |
---|
481 | |
---|
482 | void LisaaSilmamob(Vector paikka, double leveys, double korkeus) |
---|
483 | { |
---|
484 | PlatformCharacter SilmaMob = new PlatformCharacter(leveys, korkeus); |
---|
485 | PlatformWandererBrain SilmaMobAivot = new PlatformWandererBrain(); |
---|
486 | SilmaMob.Position = paikka; |
---|
487 | SilmaMobAivot.Speed = 100; |
---|
488 | SilmaMob.Tag = "silmamob"; |
---|
489 | SilmaMob.Image = silmamobimage; |
---|
490 | SilmaMob.Brain = SilmaMobAivot; |
---|
491 | Add(SilmaMob); |
---|
492 | } |
---|
493 | |
---|
494 | void LisaaSnakemob(Vector paikka, double leveys, double korkeus) |
---|
495 | { |
---|
496 | PlatformCharacter Snake = new PlatformCharacter(leveys, korkeus); |
---|
497 | PlatformWandererBrain Snakeaivot = new PlatformWandererBrain(); |
---|
498 | Snakeaivot.Speed = 100; |
---|
499 | Snake.Position = paikka; |
---|
500 | Snake.Tag = "snake"; |
---|
501 | Snake.Brain = Snakeaivot; |
---|
502 | Snake.Animation = new Animation(Snakiitio); |
---|
503 | Snake.Animation.Start(); |
---|
504 | |
---|
505 | Add(Snake); |
---|
506 | } |
---|
507 | |
---|
508 | void LisaaLGM(Vector paikka, double leveys, double korkeus) |
---|
509 | { |
---|
510 | PlatformCharacter LGM = new PlatformCharacter(leveys, korkeus); |
---|
511 | FollowerBrain LGMAivot = new FollowerBrain("pelaaja"); |
---|
512 | LGM.Position = paikka; |
---|
513 | LGMAivot.Speed = 100; |
---|
514 | LGM.Tag = "Lgm"; |
---|
515 | LGM.Image = LittleGreenMan; |
---|
516 | LGM.Brain = LGMAivot; |
---|
517 | Add(LGM); |
---|
518 | } |
---|
519 | |
---|
520 | void Wizard(Vector paikka, double leveys, double korkeus) |
---|
521 | { |
---|
522 | PlatformCharacter Wizard = new PlatformCharacter(leveys, korkeus); |
---|
523 | Wizard.Position = paikka; |
---|
524 | Wizard.Image = Player; |
---|
525 | Wizard.Tag = "Wizard"; |
---|
526 | |
---|
527 | FollowerBrain WizardBrain = new FollowerBrain(pelaaja1); |
---|
528 | PlatformWandererBrain toisetAivot = new PlatformWandererBrain(); |
---|
529 | WizardBrain.FarBrain = toisetAivot; |
---|
530 | Wizard.Brain = WizardBrain; |
---|
531 | WizardBrain.DistanceClose = 10 * RUUDUN_KOKO; |
---|
532 | |
---|
533 | |
---|
534 | Wizard.Weapon = new AssaultRifle(10, 10); |
---|
535 | Wizard.Weapon.Position = new Vector(10, 0); |
---|
536 | Wizard.Weapon.AttackSound = WizardZap; |
---|
537 | Wizard.Weapon.Power.DefaultValue = 200; |
---|
538 | |
---|
539 | Wizard.Weapon.Image = WizardrWand; |
---|
540 | //Wizard.Weapon.Image = WizardrWand; Ammuksen kuvaksi |
---|
541 | Add(Wizard); |
---|
542 | |
---|
543 | const double ampumisEtaisyys = 10 * RUUDUN_KOKO; |
---|
544 | WizardBrain.TargetClose += delegate |
---|
545 | { |
---|
546 | Timer shootingtimer = new Timer(); |
---|
547 | shootingtimer.Interval = 0.75; |
---|
548 | shootingtimer.Timeout += delegate |
---|
549 | { |
---|
550 | if (Vector.Distance(Wizard.Position, pelaaja1.Position) < ampumisEtaisyys) |
---|
551 | { |
---|
552 | PhysicsObject Ammus = Wizard.Weapon.Shoot(); |
---|
553 | if (Ammus != null) |
---|
554 | { |
---|
555 | Ammus.Image = WizParticle; |
---|
556 | AddCollisionHandler(Ammus, CollisionHandler.DestroyObject); |
---|
557 | Ammus.Tag = "Ammo"; |
---|
558 | } |
---|
559 | } |
---|
560 | }; |
---|
561 | shootingtimer.Start(); |
---|
562 | }; |
---|
563 | |
---|
564 | } |
---|
565 | |
---|
566 | void Ninja(Vector paikka, double leveys, double korkeus) |
---|
567 | { |
---|
568 | PlatformCharacter Ninja = new PlatformCharacter(leveys /8 *3, korkeus); |
---|
569 | Ninja.Position = paikka; |
---|
570 | Ninja.Image = NinjaImage; |
---|
571 | Ninja.Tag = "Ninja"; |
---|
572 | GameObject NinjaThings = new GameObject(leveys, korkeus); |
---|
573 | NinjaThings.Image = Ninjathings; |
---|
574 | Ninja.Add(NinjaThings); |
---|
575 | |
---|
576 | FollowerBrain NinjaBrain = new FollowerBrain(pelaaja1); |
---|
577 | PlatformWandererBrain toisetAivot = new PlatformWandererBrain(); |
---|
578 | NinjaBrain.FarBrain = toisetAivot; |
---|
579 | Ninja.Brain = NinjaBrain; |
---|
580 | |
---|
581 | |
---|
582 | Ninja.Weapon = new AssaultRifle(10, 10); |
---|
583 | Ninja.Weapon.AttackSound = null; |
---|
584 | Ninja.Weapon.Power.Value = 20; |
---|
585 | Ninja.Weapon.Power.DefaultValue = 20; |
---|
586 | |
---|
587 | Ninja.Weapon.Image = Empty; |
---|
588 | Ninja.Tag = "NINZA"; |
---|
589 | Add(Ninja); |
---|
590 | |
---|
591 | const double ampumisEtaisyys = 10 * RUUDUN_KOKO; |
---|
592 | NinjaBrain.TargetClose += delegate |
---|
593 | { |
---|
594 | Timer shootingtimer = new Timer(); |
---|
595 | shootingtimer.Interval = 5; |
---|
596 | shootingtimer.Timeout += delegate |
---|
597 | { |
---|
598 | if (Vector.Distance(Ninja.Position, pelaaja1.Position) < ampumisEtaisyys && NinjaIsRaged == true) |
---|
599 | { |
---|
600 | PhysicsObject Ammus = Ninja.Weapon.Shoot(); |
---|
601 | if (Ammus != null) |
---|
602 | { |
---|
603 | Ammus.Image = NinjaStarImage; |
---|
604 | AddCollisionHandler(Ammus, CollisionHandler.DestroyObject); |
---|
605 | Ammus.Tag = "Ammo"; |
---|
606 | } |
---|
607 | } |
---|
608 | }; |
---|
609 | shootingtimer.Start(); |
---|
610 | }; |
---|
611 | } |
---|
612 | |
---|
613 | |
---|
614 | void LisaaNappaimet() |
---|
615 | { |
---|
616 | //Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
617 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, LuoPeliValikko, "Lopeta peli"); |
---|
618 | |
---|
619 | if (ControllerOne.IsConnected == false) |
---|
620 | { |
---|
621 | |
---|
622 | Keyboard.Listen(Key.A, ButtonState.Down, Liikuta, "", pelaaja1, -1.0); |
---|
623 | Keyboard.Listen(Key.D, ButtonState.Down, Liikuta, "", pelaaja1, 1.0); |
---|
624 | Keyboard.Listen(Key.W, ButtonState.Pressed, Hyppaa, "", pelaaja1, JumpSpeed); |
---|
625 | Keyboard.Listen(Key.W, ButtonState.Pressed, Ui, "", pelaaja1); |
---|
626 | |
---|
627 | Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Lyo, "Pelaaja Lyö", pelaaja1); |
---|
628 | Mouse.Listen(MouseButton.Right, ButtonState.Pressed, HeitaPommi, "Pelaaja heittää pommin", pelaaja1); |
---|
629 | |
---|
630 | } |
---|
631 | |
---|
632 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); |
---|
633 | |
---|
634 | ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa, "Liikuta pelaajaa tattia pyörittämällä."); |
---|
635 | ControllerOne.Listen(Button.A, ButtonState.Pressed, Hyppaa, "", pelaaja1, JumpSpeed); |
---|
636 | ControllerOne.Listen(Button.A, ButtonState.Down, Ui, "", pelaaja1); |
---|
637 | ControllerOne.Listen(Button.RightShoulder, ButtonState.Pressed, HeitaPommi, "Pelaaja heittää pommin", pelaaja1); |
---|
638 | ControllerOne.Listen(Button.LeftShoulder, ButtonState.Pressed, Lyo, "Pelaaja Lyö", pelaaja1); |
---|
639 | } |
---|
640 | |
---|
641 | void LiikutaPelaajaa(AnalogState tatinTila) |
---|
642 | { |
---|
643 | Vector tatinAsento = tatinTila.StateVector; |
---|
644 | pelaaja1.Walk(tatinAsento.X * nopeus); |
---|
645 | } |
---|
646 | void Lyo(PlatformCharacter hahmo) |
---|
647 | { |
---|
648 | if (saapiiskata == false) |
---|
649 | return; |
---|
650 | |
---|
651 | saapiiskata = false; |
---|
652 | |
---|
653 | PhysicsObject temp = new PhysicsObject(50, 20); |
---|
654 | //temp.IsVisible = false; |
---|
655 | temp.IgnoresGravity = true; |
---|
656 | temp.IgnoresCollisionResponse = true; |
---|
657 | temp.Destroyed += delegate { saapiiskata = true; }; |
---|
658 | temp.Tag = "temp"; |
---|
659 | Add(temp); |
---|
660 | temp.Animation = new Animation(Ruoskanimaatio); |
---|
661 | temp.Animation.Start(); |
---|
662 | |
---|
663 | AddCollisionHandler(temp, "silmamob", CollisionHandler.DestroyTarget); |
---|
664 | AddCollisionHandler(temp, "snake", CollisionHandler.DestroyTarget); |
---|
665 | AddCollisionHandler(temp, "Lgm", CollisionHandler.DestroyTarget); |
---|
666 | AddCollisionHandler(temp, "NINZA", NinjaRage); |
---|
667 | |
---|
668 | Timer.SingleShot(0.1, temp.Destroy); |
---|
669 | |
---|
670 | Timer ajastin = new Timer(); |
---|
671 | ajastin.Interval = 0.01; |
---|
672 | ajastin.Timeout += delegate |
---|
673 | { |
---|
674 | if (hahmo.FacingDirection == Direction.Left) |
---|
675 | { |
---|
676 | temp.TextureWrapSize = new Vector(-1, 1); |
---|
677 | temp.Position = new Vector((hahmo.Position.X - (hahmo.Width / 2) - (temp.Width * .35)), hahmo.Position.Y); |
---|
678 | } |
---|
679 | else |
---|
680 | { |
---|
681 | temp.TextureWrapSize = new Vector(1, 1); |
---|
682 | temp.Position = new Vector((hahmo.Position.X + (hahmo.Width / 2) + (temp.Width * .35)), hahmo.Position.Y); |
---|
683 | } |
---|
684 | }; |
---|
685 | ajastin.Start(); |
---|
686 | } |
---|
687 | void HeitaPommi(PlatformCharacter hahmo) |
---|
688 | { |
---|
689 | if (saapommittaa == false || Pommit.Value <= 0) |
---|
690 | return; |
---|
691 | Pommit.Value--; |
---|
692 | |
---|
693 | saapommittaa = false; |
---|
694 | |
---|
695 | Grenade Pommi = new Grenade(10.0); |
---|
696 | for (int i = 0; i < destroybleThings.Count; i++) |
---|
697 | { |
---|
698 | Pommi.Explosion.AddShockwaveHandler(destroybleThings[i], DestroyCube); |
---|
699 | } |
---|
700 | Pommi.Explosion.AddShockwaveHandler(pelaaja1, PalyerTouchingExplo); |
---|
701 | hahmo.Throw(Pommi, Angle.FromDegrees(30), 10000); |
---|
702 | Pommi.Image = Bomb; |
---|
703 | |
---|
704 | Timer.SingleShot(.2, delegate { saapommittaa = true; }); |
---|
705 | } |
---|
706 | |
---|
707 | void Liikuta(PlatformCharacter hahmo, double suunta) |
---|
708 | { |
---|
709 | hahmo.Walk(nopeus * suunta); |
---|
710 | } |
---|
711 | |
---|
712 | void Hyppaa(PlatformCharacter hahmo, double nopeus) |
---|
713 | { |
---|
714 | hahmo.Jump(nopeus); |
---|
715 | } |
---|
716 | |
---|
717 | void Ui (PlatformCharacter hahmo) |
---|
718 | { |
---|
719 | GameObject alla = GetObjectAt(hahmo.Position - new Vector(0, RUUDUN_KOKO / 2 + 2)); |
---|
720 | if (alla != null && alla.Tag == "Water") |
---|
721 | { |
---|
722 | hahmo.Velocity = new Vector(0, 100); |
---|
723 | } |
---|
724 | } |
---|
725 | |
---|
726 | void TormaaHealtiin(PhysicsObject hahmo, PhysicsObject healt) |
---|
727 | { |
---|
728 | maaliAani.Play(aanenvoimakkuus, 0.0, 0.0); |
---|
729 | healt.Destroy(); |
---|
730 | elamaLaskuri.Value += 5; |
---|
731 | } |
---|
732 | |
---|
733 | void LuoElamaLaskuri() |
---|
734 | { |
---|
735 | elamaLaskuri = new IntMeter(10); |
---|
736 | elamaLaskuri.MaxValue = 99; |
---|
737 | elamaLaskuri.LowerLimit += ElamaLoppui; |
---|
738 | |
---|
739 | Label ElamaKuva = new Label(playerhealth); |
---|
740 | ElamaKuva.Size = new Vector(80, 80); |
---|
741 | Add(ElamaKuva); |
---|
742 | |
---|
743 | Label pisteNaytto = new Label(); |
---|
744 | pisteNaytto.X = Screen.Left + 100; |
---|
745 | pisteNaytto.Y = Screen.Top - 100; |
---|
746 | pisteNaytto.TextColor = Color.Black; |
---|
747 | pisteNaytto.Color = Color.Red; |
---|
748 | pisteNaytto.BindTo(elamaLaskuri); |
---|
749 | Add(pisteNaytto); |
---|
750 | |
---|
751 | ElamaKuva.X = pisteNaytto.X; |
---|
752 | ElamaKuva.Y = pisteNaytto.Y; |
---|
753 | |
---|
754 | |
---|
755 | |
---|
756 | } |
---|
757 | |
---|
758 | void CreateOxygenMeter() |
---|
759 | { |
---|
760 | OxygenMeter = new IntMeter(10, 0, 10); |
---|
761 | //OxygenMeter.LowerLimit += ElamaLoppui; |
---|
762 | |
---|
763 | ProgressBar OxygenBar = new ProgressBar(500, 20); |
---|
764 | OxygenBar.X = 0; |
---|
765 | OxygenBar.Y = Screen.Top - 20; |
---|
766 | OxygenBar.BindTo(OxygenMeter); |
---|
767 | OxygenBar.Color = Color.MidnightBlue; |
---|
768 | OxygenBar.BarColor = Color.LightBlue; |
---|
769 | Add(OxygenBar); |
---|
770 | |
---|
771 | Timer DrowningTimer = new Timer(); |
---|
772 | DrowningTimer.Interval = DrownTime; |
---|
773 | DrowningTimer.Timeout += CheckDrowning; |
---|
774 | DrowningTimer.Start(); |
---|
775 | } |
---|
776 | |
---|
777 | void CheckDrowning() |
---|
778 | { |
---|
779 | GameObject Water = GetObjectAt(pelaaja1.Position, "Water", 1); |
---|
780 | if (Water == null) |
---|
781 | { |
---|
782 | OxygenMeter.Value++; |
---|
783 | } |
---|
784 | else |
---|
785 | { |
---|
786 | OxygenMeter.Value--; |
---|
787 | |
---|
788 | if (OxygenMeter.Value == 0) |
---|
789 | { |
---|
790 | elamaLaskuri.Value--; |
---|
791 | } |
---|
792 | } |
---|
793 | } |
---|
794 | |
---|
795 | |
---|
796 | |
---|
797 | void ElamaLoppui() |
---|
798 | { |
---|
799 | pelaaja1.Destroy(); |
---|
800 | ControllerOne.Vibrate(0.7, 0.7, 0.0, 0.0, 0.3); |
---|
801 | ExplosionSystem rajahdys = new ExplosionSystem(veripartikkeli, 100); |
---|
802 | Add(rajahdys); |
---|
803 | rajahdys.MaxScale = 1.0; |
---|
804 | rajahdys.MaxVelocity = 20.0; |
---|
805 | rajahdys.MinLifetime = 2.0; |
---|
806 | int pMaara = 50; |
---|
807 | Timer.SingleShot(3.0, ConfirmExit); |
---|
808 | |
---|
809 | |
---|
810 | |
---|
811 | rajahdys.AddEffect(pelaaja1.X, pelaaja1.Y, pMaara); |
---|
812 | //rajahdys.X = pelaaja1.X; |
---|
813 | //rajahdys.Y = pelaaja1.Y; |
---|
814 | } |
---|
815 | void TormaaSilmaMobiin(PhysicsObject hahmo, PhysicsObject silmamob) |
---|
816 | { |
---|
817 | elamaLaskuri.Value -= 1; |
---|
818 | } |
---|
819 | |
---|
820 | void TormaaSnakeen(PhysicsObject hahmo, PhysicsObject Snake) |
---|
821 | { |
---|
822 | elamaLaskuri.Value -= 1; |
---|
823 | } |
---|
824 | |
---|
825 | void AmmoTormaus(PhysicsObject hahmo, PhysicsObject ammo) |
---|
826 | { |
---|
827 | elamaLaskuri.Value -= 9; |
---|
828 | } |
---|
829 | |
---|
830 | void TormaaLGM(PhysicsObject hahmo, PhysicsObject LGM) |
---|
831 | { |
---|
832 | elamaLaskuri.Value -= 1; |
---|
833 | } |
---|
834 | |
---|
835 | void TormaaNuoleen(PhysicsObject hahmo, PhysicsObject nuoli) |
---|
836 | { |
---|
837 | elamaLaskuri.Value -= 2; |
---|
838 | |
---|
839 | } |
---|
840 | |
---|
841 | void TormaaSpeedBootsiin(PhysicsObject hahmo, PhysicsObject SpeedBoots) |
---|
842 | { |
---|
843 | nopeus *= 2; |
---|
844 | SpeedBoots.Destroy(); |
---|
845 | Timer.SingleShot(5.0, delegate { nopeus /= 2; }); |
---|
846 | |
---|
847 | } |
---|
848 | |
---|
849 | void TormaaPommipakkaukseen(PhysicsObject hahmo, PhysicsObject Pommipakkaus) |
---|
850 | { |
---|
851 | Pommit.Value += 5; |
---|
852 | Pommipakkaus.Destroy(); |
---|
853 | } |
---|
854 | |
---|
855 | void OxygenBotle(PhysicsObject hahmo, PhysicsObject OxygenBottle) |
---|
856 | { |
---|
857 | DrownTime.Value+= 0.5; |
---|
858 | OxygenBottle.Destroy(); |
---|
859 | } |
---|
860 | |
---|
861 | void DestroyCube(IPhysicsObject destroyable, Vector v ) |
---|
862 | { |
---|
863 | destroyable.Destroy(); |
---|
864 | } |
---|
865 | void PalyerTouchingExplo(IPhysicsObject pelaaja1, Vector v) |
---|
866 | { |
---|
867 | elamaLaskuri.Value -= 5; |
---|
868 | } |
---|
869 | |
---|
870 | void NinjaRage(PhysicsObject Ninja, PhysicsObject Temp) |
---|
871 | { |
---|
872 | NinjaIsRaged = true; |
---|
873 | } |
---|
874 | } |
---|