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 OK : PhysicsGame |
---|
10 | { |
---|
11 | GameObject command; //UI-ruutu, jossa pelikomennot |
---|
12 | GameObject feed; //UI-ruutu, johon tulee combat log |
---|
13 | GameObject portrait; //ruutu, jossa pelihahmon HP ja kauniit kasvot |
---|
14 | GameObject tappio; //ruutu, joka ilmaantuu pelaajan hävitessä |
---|
15 | GameObject foe1; //ruutu, jossa pahis 1 |
---|
16 | GameObject foe2; //ruutu, jossa pahis 2 |
---|
17 | GameObject foe3; //ruutu, jossa pahis 3 |
---|
18 | double textheight = -220; |
---|
19 | double textwidth = -750; |
---|
20 | GameObject transition; //ruutu, jolla peli menee eteenpäin |
---|
21 | |
---|
22 | PhysicsObject Pointer; //jolla valitaan schaibaa |
---|
23 | Timer ajastin; |
---|
24 | bool pelaajatoiminut = false; //tarkistaa, että onko pelaaja käyttänyt vuoronsa, että hän ei pääse rikkomaan peliä |
---|
25 | |
---|
26 | IntMeter goopHP; //ekan vihollisen hp |
---|
27 | IntMeter skeleHP; //tokan vihollisen hp |
---|
28 | IntMeter HP; //pelaajan hp |
---|
29 | int playerdamage = 10; //pelaajan papu |
---|
30 | int enemy1damage = 5; //ekan vihollisen tehot |
---|
31 | int enemy2damage = 20; //tokan vihollisen tehot |
---|
32 | |
---|
33 | Label foeHP; // eka vihu |
---|
34 | Label foe2HP; //toka vihu |
---|
35 | Label playerHP; |
---|
36 | Label feedtext; |
---|
37 | |
---|
38 | Vector nopeusYlos = new Vector(0, 100); |
---|
39 | Vector nopeusAlas = new Vector(0, -100); |
---|
40 | Vector nopeusVasen = new Vector(-200, 0); |
---|
41 | Vector nopeusOikea = new Vector(200, 0); |
---|
42 | |
---|
43 | public override void Begin() |
---|
44 | { |
---|
45 | LuoAlue(); |
---|
46 | luopelaaja(); |
---|
47 | LuoHP(); |
---|
48 | Kontrollit(); |
---|
49 | |
---|
50 | |
---|
51 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
52 | } |
---|
53 | |
---|
54 | void LuoAlue() |
---|
55 | { |
---|
56 | |
---|
57 | Level.Background.Color = Color.White; |
---|
58 | |
---|
59 | command = new GameObject(450.0, 300.0); |
---|
60 | command.Shape = Shape.Rectangle; |
---|
61 | command.Color = Color.Black; |
---|
62 | command.X = 370.00; |
---|
63 | command.Y = -330.00; |
---|
64 | command.Image = LoadImage("Kökkö"); |
---|
65 | Add(command); |
---|
66 | |
---|
67 | feed = new GameObject(1000.00, 300.00); |
---|
68 | feed.Shape = Shape.Rectangle; |
---|
69 | feed.Color = Color.Black; |
---|
70 | feed.X = -400.00; |
---|
71 | feed.Y = -330.00; |
---|
72 | Add(feed); |
---|
73 | |
---|
74 | feedtext = new Label(); |
---|
75 | feedtext.X = textwidth; |
---|
76 | feedtext.Y = textheight; |
---|
77 | feedtext.TextColor = Color.White; |
---|
78 | feedtext.Color = Color.Transparent; |
---|
79 | Add(feedtext, 2); |
---|
80 | |
---|
81 | |
---|
82 | portrait = new GameObject(250.00, 300.00); |
---|
83 | portrait.Shape = Shape.Rectangle; |
---|
84 | portrait.Color = Color.Black; |
---|
85 | portrait.X = 750.00; |
---|
86 | portrait.Y = -330.00; |
---|
87 | Add(portrait); |
---|
88 | |
---|
89 | foe1 = new GameObject(1800.00, 700.00); |
---|
90 | foe1.Shape = Shape.Rectangle; |
---|
91 | foe1.Color = Color.Aqua; |
---|
92 | foe1.X = -10.00; |
---|
93 | foe1.Y = 200.00; |
---|
94 | foe1.Image = LoadImage("köntsä"); |
---|
95 | Add(foe1); |
---|
96 | } |
---|
97 | |
---|
98 | PhysicsObject luopelaaja() |
---|
99 | { |
---|
100 | Pointer = new PhysicsObject(5.0, 5.0); |
---|
101 | Pointer.Color = Color.White; |
---|
102 | Pointer.X = 190.00; |
---|
103 | Pointer.Y = -220.00; |
---|
104 | Add(Pointer, 2); |
---|
105 | Pointer.IgnoresExplosions = true; |
---|
106 | return Pointer; |
---|
107 | } |
---|
108 | |
---|
109 | void LuoHP() |
---|
110 | { |
---|
111 | goopHP = new IntMeter(20); |
---|
112 | |
---|
113 | foeHP = new Label(); |
---|
114 | |
---|
115 | foeHP.X = 150.00; |
---|
116 | foeHP.Y = Screen.Top - 40.00; |
---|
117 | foeHP.TextColor = Color.Red; |
---|
118 | foeHP.Color = Color.Transparent; |
---|
119 | |
---|
120 | foeHP.BindTo(goopHP); |
---|
121 | Add(foeHP, 2); |
---|
122 | |
---|
123 | HP = new IntMeter(65); |
---|
124 | |
---|
125 | Label playerHP = new Label(); |
---|
126 | |
---|
127 | playerHP.X = 660.00; |
---|
128 | playerHP.Y = -200.00; |
---|
129 | playerHP.TextColor = Color.LightGreen; |
---|
130 | playerHP.Color = Color.Transparent; |
---|
131 | |
---|
132 | playerHP.BindTo(HP); |
---|
133 | Add(playerHP, 2); |
---|
134 | |
---|
135 | skeleHP = new IntMeter(40); |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | } |
---|
141 | void AsetaNopeus(PhysicsObject Pointer, Vector nopeus) |
---|
142 | { |
---|
143 | PlaySound("blip"); |
---|
144 | |
---|
145 | if (Pointer.Velocity.Magnitude > 0) return; |
---|
146 | |
---|
147 | Vector sijainti = Pointer.Position + nopeus; |
---|
148 | if (sijainti.Y > command.Top) return; |
---|
149 | else if (sijainti.Y < command.Bottom) return; |
---|
150 | |
---|
151 | Pointer.MoveTo(Pointer.Position + nopeus, 1000.00); |
---|
152 | |
---|
153 | } |
---|
154 | void Kontrollit() |
---|
155 | { |
---|
156 | Keyboard.Listen(Key.Down, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusAlas); |
---|
157 | //Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
158 | |
---|
159 | Keyboard.Listen(Key.Up, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusYlos); |
---|
160 | //Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | //Keyboard.Listen(Key.Left, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusVasen); |
---|
165 | ///Keyboard.Listen(Key.Left, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
166 | |
---|
167 | //Keyboard.Listen(Key.Right, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusOikea); |
---|
168 | //Keyboard.Listen(Key.Right, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
169 | |
---|
170 | Keyboard.Listen(Key.Z, ButtonState.Pressed, Valitse, null); |
---|
171 | |
---|
172 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
173 | |
---|
174 | } |
---|
175 | |
---|
176 | void Valitse() |
---|
177 | |
---|
178 | { |
---|
179 | if (pelaajatoiminut) return; |
---|
180 | pelaajatoiminut = true; |
---|
181 | if (Pointer.Y > command.Top - command.Height / 3) Attack(); |
---|
182 | else if (Pointer.Y < command.Bottom + command.Height / 3) Exit(); |
---|
183 | else Exit(); |
---|
184 | } |
---|
185 | |
---|
186 | void Attack() //mitä tapahtuu jos painaa attackkia |
---|
187 | { |
---|
188 | if (goopHP.Value > 0) attackenemy1(); |
---|
189 | else if (skeleHP.Value > 0) attackenemy2(); |
---|
190 | } |
---|
191 | |
---|
192 | void attackenemy1() |
---|
193 | { |
---|
194 | goopHP.Value -= playerdamage; |
---|
195 | |
---|
196 | GameObject hit = new GameObject(100.00, 100.00); |
---|
197 | hit.Shape = Shape.Star; |
---|
198 | hit.Color = Color.OrangeRed; |
---|
199 | hit.X = 0.00; |
---|
200 | hit.Y = Screen.Top - 60.00; |
---|
201 | Add(hit, 3); |
---|
202 | hit.Image = LoadImage("hitanim2"); |
---|
203 | hit.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 50); |
---|
204 | |
---|
205 | PlaySound("hit"); |
---|
206 | |
---|
207 | GameObject hit2 = new GameObject(100.00, 100.00); |
---|
208 | hit2.Shape = Shape.Star; |
---|
209 | hit2.Color = Color.OrangeRed; |
---|
210 | hit2.X = 0.00; |
---|
211 | hit2.Y = Screen.Top - 60.00; |
---|
212 | hit2.Image = LoadImage("hitanim"); |
---|
213 | hit2.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 100); |
---|
214 | Add(hit2, 3); |
---|
215 | |
---|
216 | Attackfeed(playerdamage); |
---|
217 | } |
---|
218 | |
---|
219 | void attackenemy2() |
---|
220 | { |
---|
221 | skeleHP.Value -= playerdamage; |
---|
222 | |
---|
223 | GameObject hit = new GameObject(100.00, 100.00); |
---|
224 | hit.Shape = Shape.Star; |
---|
225 | hit.Color = Color.OrangeRed; |
---|
226 | hit.X = 0.00; |
---|
227 | hit.Y = Screen.Top - 60.00; |
---|
228 | Add(hit, 3); |
---|
229 | hit.Image = LoadImage("hitanim2"); |
---|
230 | hit.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 50); |
---|
231 | |
---|
232 | PlaySound("hit"); |
---|
233 | |
---|
234 | GameObject hit2 = new GameObject(100.00, 100.00); |
---|
235 | hit2.Shape = Shape.Star; |
---|
236 | hit2.Color = Color.OrangeRed; |
---|
237 | hit2.X = 0.00; |
---|
238 | hit2.Y = Screen.Top - 60.00; |
---|
239 | hit2.Image = LoadImage("hitanim"); |
---|
240 | hit2.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 100); |
---|
241 | Add(hit2, 3); |
---|
242 | |
---|
243 | Attackfeed(playerdamage); |
---|
244 | } |
---|
245 | |
---|
246 | void Attackfeed(double damage) //combat login tiedot päivittyy |
---|
247 | { |
---|
248 | double y = feedtext.Y; |
---|
249 | |
---|
250 | feedtext.Text = "Delivered " + damage + " damage.\n" + feedtext.Text; |
---|
251 | feedtext.Y = textheight - feedtext.Height / 2; |
---|
252 | |
---|
253 | if (goopHP == 0) Transition(); |
---|
254 | |
---|
255 | if (goopHP == 0) return; |
---|
256 | |
---|
257 | if (goopHP > 0) Timer.SingleShot(1.0, Enemy1attack); |
---|
258 | |
---|
259 | else if (skeleHP > 0) Timer.SingleShot(1.0, Enemy2attack); |
---|
260 | } |
---|
261 | |
---|
262 | void Enemy1attack() //ekan vihollisen AI |
---|
263 | |
---|
264 | { |
---|
265 | PlaySound("playertakesdamage"); |
---|
266 | HP.Value -= enemy1damage; |
---|
267 | |
---|
268 | double y = feedtext.Y; |
---|
269 | double x = feedtext.X; |
---|
270 | |
---|
271 | feedtext.Text = "Received " + enemy1damage + " damage.\n" + feedtext.Text; |
---|
272 | feedtext.Y = textheight - feedtext.Height / 2; |
---|
273 | feedtext.X = textwidth;; |
---|
274 | |
---|
275 | pelaajatoiminut = false; |
---|
276 | |
---|
277 | if (HP == 0) Lose(); |
---|
278 | } |
---|
279 | |
---|
280 | void Enemy2attack() |
---|
281 | { |
---|
282 | PlaySound("playertakesdamage"); |
---|
283 | HP.Value -= enemy2damage; |
---|
284 | |
---|
285 | double y = feedtext.Y; |
---|
286 | double x = feedtext.X; |
---|
287 | |
---|
288 | feedtext.Text = "Received " + enemy2damage + " damage.\n" + feedtext.Text; |
---|
289 | feedtext.Y = textheight - feedtext.Height / 2; |
---|
290 | feedtext.X = textwidth; ; |
---|
291 | |
---|
292 | pelaajatoiminut = false; |
---|
293 | |
---|
294 | if (HP == 0) Lose(); |
---|
295 | } |
---|
296 | |
---|
297 | void Transition() //pelin siirtyminen eteenpäin, kun pahis voitettu |
---|
298 | { |
---|
299 | foeHP.Destroy(); |
---|
300 | |
---|
301 | transition = new GameObject(1800.00, 700.00); |
---|
302 | transition.Shape = Shape.Rectangle; |
---|
303 | transition.Color = Color.Aqua; |
---|
304 | transition.X = -10.00; |
---|
305 | transition.Y = 200.00; |
---|
306 | transition.Image = LoadImage("transiitio"); |
---|
307 | Add(transition); |
---|
308 | |
---|
309 | Timer.SingleShot(1.5, Lisaapahis2); |
---|
310 | } |
---|
311 | |
---|
312 | void Lisaapahis2() |
---|
313 | { |
---|
314 | foe2 = new GameObject(1800.00, 700.00); |
---|
315 | foe2.Shape = Shape.Rectangle; |
---|
316 | foe2.Color = Color.Aqua; |
---|
317 | foe2.X = -10.00; |
---|
318 | foe2.Y = 200.00; |
---|
319 | foe2.Image = LoadImage("luumies"); |
---|
320 | Add(foe2); |
---|
321 | |
---|
322 | pelaajatoiminut = false; |
---|
323 | |
---|
324 | skeleHP = new IntMeter(40); |
---|
325 | |
---|
326 | foeHP = new Label(); |
---|
327 | |
---|
328 | foeHP.X = 150.00; |
---|
329 | foeHP.Y = Screen.Top - 40.00; |
---|
330 | foeHP.TextColor = Color.Red; |
---|
331 | foeHP.Color = Color.Transparent; |
---|
332 | Add(foeHP); |
---|
333 | |
---|
334 | foeHP.BindTo(skeleHP); |
---|
335 | Add(foeHP, 3); |
---|
336 | |
---|
337 | } |
---|
338 | |
---|
339 | void Lose() //pelaajan häviö |
---|
340 | { |
---|
341 | pelaajatoiminut = true; |
---|
342 | |
---|
343 | tappio = new GameObject(Screen.Width, Screen.Height); |
---|
344 | tappio.Shape = Shape.Rectangle; |
---|
345 | tappio.Color = Color.Black; |
---|
346 | tappio.Image = LoadImage("häviö"); |
---|
347 | Add(tappio, 3); |
---|
348 | |
---|
349 | } |
---|
350 | } |
---|
351 | |
---|