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