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 KillSlender : PhysicsGame |
---|
10 | { |
---|
11 | PhysicsObject pelaaja; |
---|
12 | Image tyyppi = LoadImage("tyyppi"); |
---|
13 | public override void Begin() |
---|
14 | |
---|
15 | |
---|
16 | { |
---|
17 | // TODO: |
---|
18 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
19 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
20 | pelaaja = new PhysicsObject(50, 100); |
---|
21 | pelaaja.Shape = Shape.Rectangle; |
---|
22 | Add(pelaaja); |
---|
23 | pelaaja.Image = tyyppi; |
---|
24 | Gravity = new Vector(0.0, -800.0); |
---|
25 | TileMap ruudut = TileMap.FromLevelAsset("kentta1"); |
---|
26 | ruudut.SetTileMethod('1', LuoPelaaja); |
---|
27 | ruudut.SetTileMethod('=', LuoPalikka); |
---|
28 | ruudut.SetTileMethod('*', LuoTahti); |
---|
29 | ruudut.Execute(20, 20); |
---|
30 | Keyboard.Listen(Key.Left, ButtonState.Down, |
---|
31 | LiikutaPelaajaa, null, new Vector(-1000, 0)); |
---|
32 | Keyboard.Listen(Key.Right, ButtonState.Down, |
---|
33 | LiikutaPelaajaa, null, new Vector(1000, 0)); |
---|
34 | Keyboard.Listen(Key.Up, ButtonState.Down, |
---|
35 | LiikutaPelaajaa, null, new Vector(0, 1000)); |
---|
36 | Keyboard.Listen(Key.Down, ButtonState.Down, |
---|
37 | LiikutaPelaajaa, null, new Vector(0, -1000)); |
---|
38 | Keyboard.Listen(Key.P, ButtonState.Pressed, Pause, "Pysäyttää pelin"); |
---|
39 | IsPaused = true; PhysicsObject slender = new PhysicsObject(50, 150); |
---|
40 | slender.Shape = Shape.Rectangle; |
---|
41 | Add(slender); |
---|
42 | FollowerBrain seuraajanAivot = new FollowerBrain(pelaaja); |
---|
43 | slender.Brain = seuraajanAivot; |
---|
44 | seuraajanAivot.Speed = 175; |
---|
45 | Image olionKuva = LoadImage("slender"); |
---|
46 | slender.Image = olionKuva; |
---|
47 | Camera.Follow(pelaaja); |
---|
48 | } |
---|
49 | void LuoPalikka(Vector paikka, double leveys, double korkeus) |
---|
50 | { |
---|
51 | PhysicsObject palikka = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
52 | palikka.Position = paikka; |
---|
53 | palikka.Shape = Shape.Rectangle; |
---|
54 | palikka.Color = Color.Gray; |
---|
55 | Add(palikka); |
---|
56 | |
---|
57 | } |
---|
58 | void LuoTahti(Vector paikka, double leveys, double korkeus) |
---|
59 | { |
---|
60 | PhysicsObject tahti = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
61 | tahti.Position = paikka; |
---|
62 | tahti.Shape = Shape.Rectangle; |
---|
63 | tahti.Color = Color.Gray; |
---|
64 | Add(tahti); |
---|
65 | } |
---|
66 | void LiikutaPelaajaa(Vector vektori) |
---|
67 | { |
---|
68 | pelaaja.Push(vektori); |
---|
69 | } |
---|
70 | void LuoPelaaja(Vector paikka, double leveys, double korkeus) |
---|
71 | { |
---|
72 | pelaaja.Position = paikka; |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | |
---|