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 LeoS : PhysicsGame |
---|
10 | { |
---|
11 | PhysicsObject pelaaja; |
---|
12 | bool pelaajaIlmassa = false; |
---|
13 | SoundEffect hyppyAani = LoadSoundEffect("Jump"); |
---|
14 | |
---|
15 | |
---|
16 | public override void Begin() |
---|
17 | { |
---|
18 | ClearAll(); |
---|
19 | MultiSelectWindow valikko = new MultiSelectWindow ("Menu", "Control Help", "Level 1", "Level 2", "Level 3", |
---|
20 | "Level 4", "Exit Game" ); valikko.ItemSelected += PainettiinValikonNappia; |
---|
21 | valikko.Color = Color.Gold; |
---|
22 | valikko.DefaultCancel = -1; |
---|
23 | Add(valikko); |
---|
24 | } |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | void AloitaPeli(string levelFile) |
---|
29 | { |
---|
30 | LataaKentta(levelFile); |
---|
31 | |
---|
32 | |
---|
33 | Level.Background.CreateGradient(Color.Teal, Color.Ruby); |
---|
34 | Gravity = new Vector(0, -400); |
---|
35 | |
---|
36 | MediaPlayer.Play("Tausta"); |
---|
37 | |
---|
38 | Surface alareuna = Surface.CreateBottom(Level); |
---|
39 | alareuna.IsVisible = false; |
---|
40 | alareuna.Tag = "reuna"; |
---|
41 | Add(alareuna); |
---|
42 | |
---|
43 | Surface oikeareuna = Surface.CreateRight(Level); |
---|
44 | oikeareuna.IsVisible = false; |
---|
45 | oikeareuna.Tag = "muuri"; |
---|
46 | Add(oikeareuna); |
---|
47 | AsetaOhjaimet(); |
---|
48 | Camera.Follow(pelaaja); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | void PainettiinValikonNappia(int valinta) |
---|
53 | { |
---|
54 | switch (valinta) |
---|
55 | { |
---|
56 | case 0: |
---|
57 | Ohjeet(); |
---|
58 | break; |
---|
59 | case 1: |
---|
60 | AloitaPeli("kentta1"); |
---|
61 | break; |
---|
62 | case 2: |
---|
63 | AloitaPeli("kentta2"); |
---|
64 | break; |
---|
65 | case 3: |
---|
66 | AloitaPeli("kentta3"); |
---|
67 | break; |
---|
68 | case 4: |
---|
69 | AloitaPeli2("kentta4"); |
---|
70 | break; |
---|
71 | case 5: |
---|
72 | Exit(); |
---|
73 | break; |
---|
74 | } |
---|
75 | } |
---|
76 | void LataaKentta(string levelFile) |
---|
77 | { |
---|
78 | TileMap ruudut = TileMap.FromLevelAsset(levelFile); |
---|
79 | ruudut.SetTileMethod('P', LuoPelaaja); |
---|
80 | ruudut.SetTileMethod('#', LuoPalikka); |
---|
81 | ruudut.SetTileMethod('*', LuoEste); |
---|
82 | ruudut.SetTileMethod('T', LuoTykki); |
---|
83 | ruudut.SetTileMethod('W', LuoExtra); |
---|
84 | ruudut.Execute(20, 20); |
---|
85 | } |
---|
86 | |
---|
87 | void LuoPelaaja(Vector paikka, double leveys, double korkeus) |
---|
88 | { |
---|
89 | pelaaja = new PhysicsObject(leveys, korkeus); |
---|
90 | pelaaja.Shape = Shape.Hexagon; |
---|
91 | pelaaja.Color = Color.HotPink; |
---|
92 | pelaaja.Position = paikka; |
---|
93 | pelaaja.Mass = 10; |
---|
94 | AddCollisionHandler(pelaaja, delegate(PhysicsObject p, PhysicsObject o) { pelaajaIlmassa = false; }); |
---|
95 | AddCollisionHandler(pelaaja, "reuna", PelaajaOsuiReunaan); |
---|
96 | AddCollisionHandler(pelaaja, "muuri", PelaajaOsuiMuuriin); |
---|
97 | AddCollisionHandler(pelaaja, "tahti", PelaajaOsuiTahtiin); |
---|
98 | pelaaja.Restitution = 100.00; |
---|
99 | Add(pelaaja); |
---|
100 | } |
---|
101 | |
---|
102 | void LuoExtra(Vector paikka, double leveys, double korkeus) |
---|
103 | { |
---|
104 | PhysicsObject extra = PhysicsObject.CreateStaticObject(leveys, |
---|
105 | korkeus, Shape.Ellipse); |
---|
106 | extra.Position = paikka; |
---|
107 | extra.Color = Color.Ivory; |
---|
108 | Add(extra); |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | void PelaajaOsuiReunaan(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
114 | { |
---|
115 | tormaaja.Destroy(); |
---|
116 | Explosion rajahdys = new Explosion(500.0); |
---|
117 | rajahdys.Position = pelaaja.Position; |
---|
118 | Add(rajahdys); |
---|
119 | Label tekstikentta = new Label("teksti"); |
---|
120 | tekstikentta.Text = "You Have Detonated"; |
---|
121 | tekstikentta.TextColor = Color.Black; |
---|
122 | Add(tekstikentta); |
---|
123 | tekstikentta.Font = Font.DefaultLarge; |
---|
124 | LuoAikaLaskuri(); |
---|
125 | |
---|
126 | |
---|
127 | } |
---|
128 | |
---|
129 | void LuoPalikka(Vector paikka, double leveys, double korkeus) |
---|
130 | { |
---|
131 | PhysicsObject taso = PhysicsObject.CreateStaticObject( |
---|
132 | leveys, korkeus, Shape.Rectangle); |
---|
133 | taso.Position = paikka; |
---|
134 | taso.Color = Color.Green; |
---|
135 | Add(taso); |
---|
136 | } |
---|
137 | |
---|
138 | void LuoEste(Vector paikka, double leveys, double korkeus) |
---|
139 | { |
---|
140 | PhysicsObject este = PhysicsObject.CreateStaticObject( |
---|
141 | leveys, korkeus, Shape.Star); |
---|
142 | este.Position = paikka; |
---|
143 | este.Color = Color.DarkMagenta; |
---|
144 | este.Tag = "tahti"; |
---|
145 | Add(este); |
---|
146 | } |
---|
147 | void AsetaOhjaimet() |
---|
148 | { |
---|
149 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Poistu"); |
---|
150 | Keyboard.Listen(Key.Right, ButtonState.Pressed, Etene, "Pelaaja 1: hyppää", pelaaja); |
---|
151 | Keyboard.Listen(Key.Up, ButtonState.Pressed, Hyppy, "Pelaaja 1: Liiku", pelaaja); |
---|
152 | Keyboard.Listen(Key.Down, ButtonState.Pressed, Hyppy2, "Hyppää alas", pelaaja); |
---|
153 | } |
---|
154 | |
---|
155 | void Etene(PhysicsObject pelaaja) |
---|
156 | { |
---|
157 | Vector nopeus = new Vector(200, 0); |
---|
158 | pelaaja.Velocity = nopeus; |
---|
159 | } |
---|
160 | |
---|
161 | void Hyppy(PhysicsObject pelaaja) |
---|
162 | { |
---|
163 | if (pelaajaIlmassa) return; |
---|
164 | Vector nopeus = new Vector(0, 200); |
---|
165 | pelaaja.Velocity = nopeus; |
---|
166 | pelaajaIlmassa = true; |
---|
167 | hyppyAani.Play(); |
---|
168 | |
---|
169 | } |
---|
170 | void PelaajaOsuiMuuriin(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
171 | { |
---|
172 | Label tekstikentta = new Label("teksti"); |
---|
173 | tekstikentta.Text = "You Reach the End"; |
---|
174 | tekstikentta.Color = Color.Aqua; |
---|
175 | tekstikentta.TextColor = Color.Red; |
---|
176 | Add(tekstikentta); |
---|
177 | tekstikentta.Font = Font.DefaultLargeBold; |
---|
178 | pelaaja.Destroy(); |
---|
179 | LuoAikaLaskuri(); |
---|
180 | } |
---|
181 | void PelaajaOsuiTahtiin(PhysicsObject tormaaja, PhysicsObject kohde) |
---|
182 | { |
---|
183 | |
---|
184 | pelaaja.Destroy(); |
---|
185 | Explosion rajahdys = new Explosion(600.0); |
---|
186 | rajahdys.Position = pelaaja.Position; |
---|
187 | Add(rajahdys); |
---|
188 | Label tekstikentta = new Label("teksti"); |
---|
189 | tekstikentta.Text = "You Hit a Star"; |
---|
190 | tekstikentta.Color = Color.Yellow; |
---|
191 | tekstikentta.TextColor = Color.Red; |
---|
192 | tekstikentta.Font = Font.DefaultLargeBold; |
---|
193 | Add(tekstikentta); |
---|
194 | LuoAikaLaskuri(); |
---|
195 | |
---|
196 | } |
---|
197 | |
---|
198 | void LuoTykki(Vector paikka, double leveys, double korkeus) |
---|
199 | { |
---|
200 | Cannon ase = new Cannon(50, 10); |
---|
201 | ase.Tag = "kanuuna"; |
---|
202 | ase.Angle = Angle.FromDegrees(90); |
---|
203 | ase.Power.DefaultValue = 9000; |
---|
204 | ase.ProjectileCollision += AmmusOsuiPelaajaan; |
---|
205 | ase.MaxAmmoLifetime = TimeSpan.FromSeconds(1.0); |
---|
206 | ase.Position = paikka; |
---|
207 | ase.AttackSound = null; |
---|
208 | Add(ase); |
---|
209 | Timer ampumisAjastin = new Timer(); |
---|
210 | ampumisAjastin.Interval = 1.2; |
---|
211 | ampumisAjastin.Start(); |
---|
212 | ampumisAjastin.Timeout += delegate { ase.Shoot(); }; |
---|
213 | } |
---|
214 | |
---|
215 | void AmmusOsuiPelaajaan(PhysicsObject ammus, PhysicsObject kohde) |
---|
216 | { |
---|
217 | |
---|
218 | Label tekstikentta = new Label("teksti"); |
---|
219 | tekstikentta.Text = "Cannon Destroyed You"; |
---|
220 | tekstikentta.Color = Color.Yellow; |
---|
221 | tekstikentta.TextColor = Color.Red; |
---|
222 | tekstikentta.Font = Font.DefaultLargeBold; |
---|
223 | Add(tekstikentta); |
---|
224 | kohde.Destroy(); |
---|
225 | LuoAikaLaskuri(); |
---|
226 | } |
---|
227 | void AloitaPeli2(string levelFile) |
---|
228 | { |
---|
229 | |
---|
230 | |
---|
231 | LataaKentta(levelFile); |
---|
232 | Level.Background.CreateGradient(Color.Teal, Color.Ruby); |
---|
233 | Gravity = new Vector(0, 400); |
---|
234 | |
---|
235 | MediaPlayer.Play("Tausta2"); |
---|
236 | |
---|
237 | Surface yläreuna = Surface.CreateTop(Level); |
---|
238 | yläreuna.IsVisible = false; |
---|
239 | yläreuna.Tag = "reuna"; |
---|
240 | Add(yläreuna); |
---|
241 | |
---|
242 | Surface oikeareuna = Surface.CreateRight(Level); |
---|
243 | oikeareuna.IsVisible = false; |
---|
244 | oikeareuna.Tag = "muuri"; |
---|
245 | Add(oikeareuna); |
---|
246 | AsetaOhjaimet(); |
---|
247 | Camera.Follow(pelaaja); |
---|
248 | |
---|
249 | } |
---|
250 | void Hyppy2(PhysicsObject pelaaja) |
---|
251 | { |
---|
252 | if (pelaajaIlmassa) return; |
---|
253 | Vector nopeus = new Vector(0, -200); |
---|
254 | pelaaja.Velocity = nopeus; |
---|
255 | pelaajaIlmassa = true; |
---|
256 | hyppyAani.Play(); |
---|
257 | |
---|
258 | |
---|
259 | |
---|
260 | } |
---|
261 | void LuoAikaLaskuri() |
---|
262 | { |
---|
263 | Timer aikaLaskuri = new Timer(); |
---|
264 | aikaLaskuri.Interval = 2.5; |
---|
265 | aikaLaskuri.Timeout += delegate { Begin(); }; |
---|
266 | aikaLaskuri.Start(1); |
---|
267 | } |
---|
268 | void Ohjeet() |
---|
269 | { |
---|
270 | LuoAikaLaskuri2(); |
---|
271 | |
---|
272 | Label tekstikentta = new Label("teksti"); |
---|
273 | tekstikentta.Text = "You Jump with UP-Button,Move Forward with RIGHT-Button and Jump Down with DOWN-Button"; |
---|
274 | tekstikentta.TextColor = Color.Red; |
---|
275 | tekstikentta.Font = Font.DefaultLargeBold; |
---|
276 | Add(tekstikentta); |
---|
277 | |
---|
278 | Label tekstikentta2 = new Label("teksti"); |
---|
279 | tekstikentta2.Text = "This screen is readable about 5 seconds"; |
---|
280 | tekstikentta2.TextColor = Color.Yellow; |
---|
281 | tekstikentta2.Font = Font.DefaultLargeBold; |
---|
282 | tekstikentta2.X = 0.0; |
---|
283 | tekstikentta2.Y = -80.0; |
---|
284 | Add(tekstikentta2); |
---|
285 | } |
---|
286 | void LuoAikaLaskuri2() |
---|
287 | { |
---|
288 | Timer aikaLaskuri = new Timer(); |
---|
289 | aikaLaskuri.Interval = 5; |
---|
290 | aikaLaskuri.Timeout += delegate { Begin(); }; |
---|
291 | aikaLaskuri.Start(); |
---|
292 | |
---|
293 | } |
---|
294 | void Poiminta() |
---|
295 | { |
---|
296 | |
---|
297 | } |
---|
298 | } |
---|
299 | |
---|
300 | |
---|
301 | |
---|
302 | |
---|
303 | |
---|