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 FysiikkaPeli1 : PhysicsGame |
---|
10 | { |
---|
11 | Image kenttaKuva = LoadImage("Kentta"); |
---|
12 | Image Pahankuva = LoadImage("Pahis"); |
---|
13 | Pelaaja OlioH; |
---|
14 | SoundEffect NamAani = LoadSoundEffect("BOING1"); |
---|
15 | IntMeter PisteLaskuri; |
---|
16 | |
---|
17 | public override void Begin() |
---|
18 | { |
---|
19 | Luokenttä(); |
---|
20 | Mouse.IsCursorVisible = true; |
---|
21 | LuoOhjaimet(); |
---|
22 | |
---|
23 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
24 | Camera.ZoomToLevel(-1000); |
---|
25 | |
---|
26 | } |
---|
27 | void Luokenttä() |
---|
28 | { |
---|
29 | ColorTileMap ruudut = ColorTileMap.FromLevelAsset("Kentta"); |
---|
30 | |
---|
31 | ruudut.SetTileMethod(Color.Gold, LuoOlioH); |
---|
32 | ruudut.SetTileMethod(Color.Black, LuoTaso); |
---|
33 | ruudut.SetTileMethod(Color.Red, LuoOlioP); |
---|
34 | ruudut.SetTileMethod(Color.Rose, LuoHerkut); |
---|
35 | |
---|
36 | ruudut.Execute(50, 50); |
---|
37 | |
---|
38 | Level.Background.Color = Color.White; |
---|
39 | |
---|
40 | Label pisteNaytto = new Label(); |
---|
41 | pisteNaytto.X = Screen.Left + 100; |
---|
42 | pisteNaytto.Y = Screen.Top - 100; |
---|
43 | pisteNaytto.TextColor = Color.Black; |
---|
44 | pisteNaytto.Color = Color.White; |
---|
45 | |
---|
46 | pisteNaytto.BindTo(OlioH.ElamaLaskuri); |
---|
47 | Add(pisteNaytto); |
---|
48 | |
---|
49 | PisteLaskuri = new IntMeter(0); |
---|
50 | |
---|
51 | Label pisteNaytto2 = new Label(); |
---|
52 | pisteNaytto2.X = Screen.Right - 100; |
---|
53 | pisteNaytto2.Y = Screen.Top - 100; |
---|
54 | pisteNaytto2.TextColor = Color.Black; |
---|
55 | pisteNaytto2.Color = Color.White; |
---|
56 | |
---|
57 | pisteNaytto2.BindTo(PisteLaskuri); |
---|
58 | Add(pisteNaytto2); |
---|
59 | |
---|
60 | } |
---|
61 | void LuoOlioH(Vector paikka, double leveys, double korkeus) |
---|
62 | { |
---|
63 | OlioH = new Pelaaja(leveys, korkeus); |
---|
64 | OlioH.Position = paikka; |
---|
65 | AddCollisionHandler(OlioH, "Pahis", TormaaVihuun); |
---|
66 | Add(OlioH); |
---|
67 | OlioH.Color = Color.Gold; |
---|
68 | OlioH.Shape = Shape.Circle; |
---|
69 | |
---|
70 | AddCollisionHandler(OlioH, "Herkku", OlioSyo); |
---|
71 | } |
---|
72 | void TormaaVihuun(PhysicsObject Tormaaja,PhysicsObject KukaTormaa) |
---|
73 | { |
---|
74 | Pelaaja P = (Pelaaja)Tormaaja; |
---|
75 | P.ElamaLaskuri.AddValue(-1); |
---|
76 | } |
---|
77 | void LuoTaso(Vector paikka, double leveys, double korkeus) |
---|
78 | { |
---|
79 | PhysicsObject seina = PhysicsObject.CreateStaticObject(leveys, korkeus); |
---|
80 | seina.Position = paikka; |
---|
81 | seina.Color = Color.Black; |
---|
82 | seina.CollisionIgnoreGroup = 1; |
---|
83 | Add(seina); |
---|
84 | } |
---|
85 | void LuoHerkut(Vector paikka, double leveys, double korkeus) |
---|
86 | { |
---|
87 | PhysicsObject Herkku = new PhysicsObject(20.0, 20.0); |
---|
88 | Add(Herkku); |
---|
89 | Herkku.Shape = Shape.Circle; |
---|
90 | Herkku.Color = Color.LimeGreen; |
---|
91 | Herkku.Position = paikka; |
---|
92 | Herkku.Tag = "Herkku"; |
---|
93 | } |
---|
94 | void OlioSyo(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
95 | { |
---|
96 | //NamAani.Play(); |
---|
97 | kohde.Destroy(); |
---|
98 | PisteLaskuri.AddValue(1); |
---|
99 | if (PisteLaskuri.Value == 28) |
---|
100 | { |
---|
101 | MessageDisplay.Add("Jeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee Voitit :3"); |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | } |
---|
106 | void LuoOlioP(Vector paikka, double leveys, double korkeus) |
---|
107 | { |
---|
108 | PhysicsObject OlioP = new PhysicsObject(leveys, korkeus); |
---|
109 | OlioP.IgnoresCollisionResponse = true; |
---|
110 | OlioP.Position = paikka; |
---|
111 | OlioP.Tag = "Pahis"; |
---|
112 | Add(OlioP, 1); |
---|
113 | OlioP.Color = Color.Red; |
---|
114 | OlioP.Shape = Shape.Circle; |
---|
115 | |
---|
116 | PathFollowerBrain polkuAivot = new PathFollowerBrain(100); |
---|
117 | |
---|
118 | OlioP.Brain = polkuAivot; |
---|
119 | |
---|
120 | polkuAivot.Active = true; |
---|
121 | polkuAivot.TurnWhileMoving = true; |
---|
122 | polkuAivot.Speed = 150; |
---|
123 | |
---|
124 | List<Vector> polku = new List<Vector>(); |
---|
125 | |
---|
126 | polku.Add(new Vector(0.0, 0.0)); |
---|
127 | polku.Add(new Vector(-300, 0.0)); |
---|
128 | polku.Add(new Vector(-300, 350)); |
---|
129 | polku.Add(new Vector(50, 350)); |
---|
130 | polku.Add(new Vector(50, -10)); |
---|
131 | polku.Add(new Vector(-30, 0.0)); |
---|
132 | polku.Add(new Vector(-30, -150)); |
---|
133 | polku.Add(new Vector(215, -150)); |
---|
134 | polku.Add(new Vector(215, 500)); |
---|
135 | polku.Add(new Vector(-450, 500)); |
---|
136 | polku.Add(new Vector(-450, 70)); |
---|
137 | polku.Add(new Vector(-280, 70)); |
---|
138 | polku.Add(new Vector(-280, 350)); |
---|
139 | polku.Add(new Vector(35, 350)); |
---|
140 | polku.Add(new Vector(35, 270)); |
---|
141 | polku.Add(new Vector(200, 270)); |
---|
142 | polku.Add(new Vector(200, -150)); |
---|
143 | polku.Add(new Vector(-450, -150)); |
---|
144 | polku.Add(new Vector(-450, 500)); |
---|
145 | polku.Add(new Vector(-215, 500)); |
---|
146 | polku.Add(new Vector(-215, 350)); |
---|
147 | polku.Add(new Vector(-120, 350)); |
---|
148 | polku.Add(new Vector(-120, 0.0)); |
---|
149 | |
---|
150 | polkuAivot.Path = polku; |
---|
151 | polkuAivot.Loop = true; |
---|
152 | |
---|
153 | } |
---|
154 | void LuoOhjaimet() |
---|
155 | { |
---|
156 | Keyboard.Listen(Key.Left, ButtonState.Down, |
---|
157 | LiikutaPelaajaa, null, new Vector(-29000, 0)); |
---|
158 | Keyboard.Listen(Key.Right, ButtonState.Down, |
---|
159 | LiikutaPelaajaa, null, new Vector(29000, 0)); |
---|
160 | Keyboard.Listen(Key.Up, ButtonState.Down, |
---|
161 | LiikutaPelaajaa, null, new Vector(0, 2000)); |
---|
162 | Keyboard.Listen(Key.Down, ButtonState.Down, |
---|
163 | LiikutaPelaajaa, null, new Vector(0, -2000)); |
---|
164 | |
---|
165 | } |
---|
166 | void LiikutaPelaajaa(Vector vektori) |
---|
167 | { |
---|
168 | OlioH.Push(vektori); |
---|
169 | } |
---|
170 | |
---|
171 | } |
---|
172 | class Pelaaja : PlatformCharacter |
---|
173 | { |
---|
174 | |
---|
175 | public int Elamat { get; set; } |
---|
176 | |
---|
177 | private IntMeter elamaLaskuri = new IntMeter(3, 0, 3); |
---|
178 | public IntMeter ElamaLaskuri { get { return elamaLaskuri; } } |
---|
179 | |
---|
180 | public Pelaaja(double leveys, double korkeus) |
---|
181 | : base(leveys, korkeus) |
---|
182 | { |
---|
183 | elamaLaskuri.LowerLimit += delegate |
---|
184 | { |
---|
185 | this.Destroy(); }; |
---|
186 | } |
---|
187 | } |
---|