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 Makkarajono : PhysicsGame |
---|
10 | { |
---|
11 | public static PhysicsGame Game; |
---|
12 | public static List<Platform> Platforms = new List<Platform>(); |
---|
13 | |
---|
14 | public static void Add (PhysicsObject Object) |
---|
15 | { |
---|
16 | Game.Add(Object); |
---|
17 | } |
---|
18 | |
---|
19 | MessageWindow winScreen; |
---|
20 | Label timeScreenP; |
---|
21 | Timer timeTimer; |
---|
22 | Timer colorTimer; |
---|
23 | IntMeter p1Points; |
---|
24 | IntMeter p2Points; |
---|
25 | IntMeter timeCounterSeconds; |
---|
26 | IntMeter timeCounterMinutes; |
---|
27 | bool gameIsStarted = false; |
---|
28 | bool blockLeft = false; |
---|
29 | bool blockRight = false; |
---|
30 | double Multiplier1 = 0.0; |
---|
31 | double Multiplier2 = 0.0; |
---|
32 | public static PlatformCharacter2 player; |
---|
33 | public static PlatformCharacter2 player2; |
---|
34 | PlatformCharacter2 bot1; |
---|
35 | PhysicsObject block; |
---|
36 | GameObject icon1; |
---|
37 | GameObject icon2; |
---|
38 | Image playerImage = LoadImage("Huggo"); |
---|
39 | Image player2Image = LoadImage("Huggouggo"); |
---|
40 | Image p1Icon = LoadImage("P1icon"); |
---|
41 | Image p2Icon = LoadImage("P2icon"); |
---|
42 | Image blockImage = LoadImage("Palikka"); |
---|
43 | Image platImage = LoadImage("Frame"); |
---|
44 | private Animation p1Punch; |
---|
45 | private Animation P1WalkAnim; |
---|
46 | private Animation p2Punch; |
---|
47 | private Animation P2WalkAnim; |
---|
48 | string p1name; |
---|
49 | string p2name; |
---|
50 | SoundEffect punchNoice1 = LoadSoundEffect("hitSound1"); |
---|
51 | Image[] Panim1Kuvat = LoadImages("P1animP/P1animP", 1, 7, false); |
---|
52 | Image[] RanimKuvat = LoadImages("P1animR/Wanim", 1, 9, false); |
---|
53 | Image[] Panim2Kuvat = LoadImages("P2animP/huggouggopanim", 1, 7, false); |
---|
54 | Image[] Ramin2Kuvat = LoadImages("P2animR/HuggouggoWanim", 1, 9, false); |
---|
55 | MultiSelectWindow StartMenu; |
---|
56 | InputWindow nameAsk; |
---|
57 | |
---|
58 | bool isAttacking = false; |
---|
59 | bool isAttacking2 = false; |
---|
60 | |
---|
61 | List<Vector> Spawnpoints = new List<Vector>(); |
---|
62 | |
---|
63 | protected override void OnExiting(object sender, EventArgs args) |
---|
64 | { |
---|
65 | if(gameIsStarted) |
---|
66 | Platform.PlatformThread.Abort(); |
---|
67 | base.OnExiting(sender, args); |
---|
68 | } |
---|
69 | |
---|
70 | public override void Begin() |
---|
71 | { |
---|
72 | ClearAll(); |
---|
73 | IsFullScreen = false; |
---|
74 | StartMenu = new MultiSelectWindow("Welcome!", "Start", "Exit"); |
---|
75 | StartMenu.AddItemHandler(0, AskNames, false); |
---|
76 | StartMenu.AddItemHandler(1, Exit); |
---|
77 | Add(StartMenu); |
---|
78 | } |
---|
79 | |
---|
80 | void StartGame() |
---|
81 | { |
---|
82 | |
---|
83 | ClearAll(); |
---|
84 | Multiplier1 = 0; |
---|
85 | Multiplier2 = 0; |
---|
86 | gameIsStarted = true; |
---|
87 | SmoothTextures = false; |
---|
88 | p1Punch = new Animation(Panim1Kuvat); |
---|
89 | p2Punch = new Animation(Panim2Kuvat); |
---|
90 | p2Punch.FPS = 30; |
---|
91 | p1Punch.FPS = 30; |
---|
92 | P1WalkAnim = new Animation(RanimKuvat); |
---|
93 | P2WalkAnim = new Animation(Ramin2Kuvat); |
---|
94 | Game = this; |
---|
95 | if (Platform.PlatformThread == null) |
---|
96 | Platform.InitializePlatformThread(); |
---|
97 | else |
---|
98 | Platform.DisabledPlatforms.Clear(); |
---|
99 | |
---|
100 | CreateLevel("Level1"); |
---|
101 | } |
---|
102 | |
---|
103 | void AskNames(bool isQuoestion2) |
---|
104 | { |
---|
105 | ClearAll(); |
---|
106 | if (!isQuoestion2) |
---|
107 | { |
---|
108 | nameAsk = new InputWindow("Gimme ur name player 1"); |
---|
109 | nameAsk.MaxCharacters = 20; |
---|
110 | nameAsk.TextEntered += delegate { ProcessNameInput(nameAsk, false); }; |
---|
111 | Add(nameAsk); |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | nameAsk = new InputWindow("Gimme ur name player 2"); |
---|
116 | nameAsk.TextEntered += delegate{ ProcessNameInput(nameAsk, true); }; |
---|
117 | nameAsk.MaxCharacters = 20; |
---|
118 | Add(nameAsk); |
---|
119 | nameAsk.Closed += delegate { StartGame(); }; |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | void ProcessNameInput(InputWindow _window, bool isPlayer2) |
---|
124 | { |
---|
125 | if (!isPlayer2) |
---|
126 | { |
---|
127 | p1name = _window.InputBox.Text; |
---|
128 | AskNames(true); |
---|
129 | } |
---|
130 | else |
---|
131 | p2name = _window.InputBox.Text; |
---|
132 | } |
---|
133 | |
---|
134 | private double Clamp(double value, double min, double max) |
---|
135 | { |
---|
136 | return Math.Min(Math.Max(value, min), max); |
---|
137 | } |
---|
138 | |
---|
139 | private double GetCameraRadiusX () |
---|
140 | { |
---|
141 | return Camera.ScreenToWorld(new Vector(Screen.Right, 0)).X - Camera.ScreenToWorld(Vector.Zero).X; |
---|
142 | } |
---|
143 | |
---|
144 | private double GetCameraRadiusY() |
---|
145 | { |
---|
146 | return Camera.ScreenToWorld(new Vector(Screen.Bottom, 0)).Y - Camera.ScreenToWorld(Vector.Zero).Y; |
---|
147 | } |
---|
148 | |
---|
149 | private double TimeLeft = 3589; |
---|
150 | |
---|
151 | protected override void Update(Time time) |
---|
152 | { |
---|
153 | base.Update(time); |
---|
154 | |
---|
155 | if (gameIsStarted) |
---|
156 | { |
---|
157 | |
---|
158 | Camera.Position = Vector.Average(player.Position, player2.Position); |
---|
159 | |
---|
160 | if (Camera.ScreenToWorld(new Vector(Screen.Right, 0)).X >= 660) |
---|
161 | Camera.Position = new Vector(660 - GetCameraRadiusX(), Camera.Position.Y); |
---|
162 | else if (Camera.ScreenToWorld(new Vector(Screen.Left, 0)).X <= -660) |
---|
163 | Camera.Position = new Vector(-660 + GetCameraRadiusX(), Camera.Position.Y); |
---|
164 | |
---|
165 | if (Camera.ScreenToWorld(new Vector(Screen.Bottom, 0)).Y <= -100) |
---|
166 | Camera.Position = new Vector(Camera.Position.X, -100 + GetCameraRadiusY()); |
---|
167 | |
---|
168 | Camera.ZoomFactor = Clamp(1.0 / (Vector.Distance(player.Position, player2.Position) * 0.001), 0.99, 2); |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | void CreateLevel(string _levelImage) |
---|
173 | { |
---|
174 | ColorTileMap _level = ColorTileMap.FromLevelAsset(_levelImage); |
---|
175 | _level.SetTileMethod("#FFFFFFFF", (Vector _pos, double x, double y) => |
---|
176 | { |
---|
177 | Spawnpoints.Add(_pos); |
---|
178 | }); |
---|
179 | _level.Execute(50, 50); |
---|
180 | |
---|
181 | _level = ColorTileMap.FromLevelAsset(_levelImage); |
---|
182 | _level.SetTileMethod("#FFFFFF00", AddPlayer, true); |
---|
183 | _level.SetTileMethod("#FF0000FF", AddPlayer, false); |
---|
184 | _level.Execute(50, 50); |
---|
185 | |
---|
186 | _level = ColorTileMap.FromLevelAsset(_levelImage); |
---|
187 | _level.SetTileMethod("FF0000", AddPlatform); |
---|
188 | _level.SetTileMethod("000000", AddBlock); |
---|
189 | |
---|
190 | _level.Execute(50, 50); |
---|
191 | |
---|
192 | Gravity = new Vector(0, -500); |
---|
193 | |
---|
194 | Surface bottomBorder = Surface.CreateBottom(Level, 100, 100, 4); |
---|
195 | bottomBorder.Tag = "BBorder"; |
---|
196 | Add(bottomBorder); |
---|
197 | Surface leftBorder = Surface.CreateLeft(Level, 100, 100, 4); |
---|
198 | leftBorder.Tag = "LBorder"; |
---|
199 | Add(leftBorder); |
---|
200 | Surface rightBorder = Surface.CreateRight(Level, 100, 100, 4); |
---|
201 | rightBorder.Tag = "RBorder"; |
---|
202 | Add(rightBorder); |
---|
203 | Surface topBorder = Surface.CreateTop(Level, 100, 100, 4); |
---|
204 | rightBorder.Tag = "TBorder"; |
---|
205 | Add(rightBorder); |
---|
206 | AddCollisionHandler(bottomBorder, HitBorder); |
---|
207 | AddCollisionHandler(leftBorder, HitBorder); |
---|
208 | AddCollisionHandler(rightBorder, HitBorder); |
---|
209 | AddCollisionHandler(topBorder, HitBorder); |
---|
210 | |
---|
211 | AddIcon(p1Icon, Screen.Left + 30, Screen.Top - 30, 50, 50, p1name, Screen.Left + 80, Screen.Top - 30, false); |
---|
212 | AddIcon(p2Icon, Screen.Right - 30, Screen.Top - 30, 50, 50, p2name, Screen.Right - 80, Screen.Top - 30, true); |
---|
213 | AddTimeCounter(); |
---|
214 | } |
---|
215 | |
---|
216 | void AddPlayer(Vector _pos, double x, double y, bool isPlayer2) |
---|
217 | { |
---|
218 | if (isPlayer2) |
---|
219 | { |
---|
220 | player2 = new PlatformCharacter2(x / 2, y); |
---|
221 | player2.Shape = Shape.Circle; |
---|
222 | player2.Color = Color.HotPink; |
---|
223 | player2.Image = player2Image; |
---|
224 | player2.StaticFriction = 0; |
---|
225 | player2.KineticFriction = 0; |
---|
226 | player2.LinearDamping = 1; |
---|
227 | player2.AngularDamping = 1; |
---|
228 | player2.Position = Spawnpoints[RandomGen.NextInt(0, Spawnpoints.Count - 1)]; |
---|
229 | player2.CanRotate = false; |
---|
230 | player2.CollisionIgnoreGroup = 2; |
---|
231 | player2.Tag = "player"; |
---|
232 | Add(player2); |
---|
233 | AddControlls(player2); |
---|
234 | |
---|
235 | Timer ajastin = new Timer(); |
---|
236 | ajastin.Interval = 0.05; |
---|
237 | ajastin.Timeout += delegate |
---|
238 | { |
---|
239 | List<GameObject> left = GetObjectsAt(player2.Position + new Vector(-player2.Width / 2 - 1, 0)); |
---|
240 | List<GameObject> right = GetObjectsAt(player2.Position + new Vector(player2.Width / 2 + 1, 0)); |
---|
241 | |
---|
242 | left.RemoveAll(o => o.Tag.ToString() != "Block"); |
---|
243 | right.RemoveAll(o => o.Tag.ToString() != "Block"); |
---|
244 | |
---|
245 | blockRight = right.Count > 0; |
---|
246 | blockLeft = left.Count > 0; |
---|
247 | |
---|
248 | if (blockRight || blockLeft) |
---|
249 | { |
---|
250 | player2.StopVertical(); |
---|
251 | } |
---|
252 | }; |
---|
253 | ajastin.Start(); |
---|
254 | } |
---|
255 | else |
---|
256 | { |
---|
257 | player = new PlatformCharacter2(x / 2, y); |
---|
258 | player.Shape = Shape.Circle; |
---|
259 | player.Color = Color.HotPink; |
---|
260 | player.Image = playerImage; |
---|
261 | player.StaticFriction = 0; |
---|
262 | player.KineticFriction = 0; |
---|
263 | player.LinearDamping = 1; |
---|
264 | player.AngularDamping = 1; |
---|
265 | player.Position = Spawnpoints[RandomGen.NextInt(0, Spawnpoints.Count - 1)]; |
---|
266 | player.CanRotate = false; |
---|
267 | player.CollisionIgnoreGroup = 1; |
---|
268 | player.Tag = "player"; |
---|
269 | Add(player); |
---|
270 | AddControlls(player); |
---|
271 | |
---|
272 | Timer ajastin = new Timer(); |
---|
273 | ajastin.Interval = 0.05; |
---|
274 | ajastin.Timeout += delegate |
---|
275 | { |
---|
276 | List<GameObject> left = GetObjectsAt(player.Position + new Vector(-player.Width / 2 - 1, 0)); |
---|
277 | List<GameObject> right = GetObjectsAt(player.Position + new Vector(player.Width / 2 + 1, 0)); |
---|
278 | |
---|
279 | left.RemoveAll(o => o.Tag.ToString() != "Block"); |
---|
280 | right.RemoveAll(o => o.Tag.ToString() != "Block"); |
---|
281 | |
---|
282 | blockRight = right.Count > 0; |
---|
283 | blockLeft = left.Count > 0; |
---|
284 | |
---|
285 | if (blockRight || blockLeft) |
---|
286 | { |
---|
287 | player.StopVertical(); |
---|
288 | } |
---|
289 | }; |
---|
290 | ajastin.Start(); |
---|
291 | } |
---|
292 | |
---|
293 | } |
---|
294 | |
---|
295 | void GetDown (bool isPlayer2) |
---|
296 | { |
---|
297 | foreach (Platform platform in Platforms) |
---|
298 | { |
---|
299 | platform.Process(false, isPlayer2); |
---|
300 | } |
---|
301 | } |
---|
302 | |
---|
303 | void HitBorder(PhysicsObject collider, PhysicsObject target) |
---|
304 | { |
---|
305 | target.Position = Spawnpoints[RandomGen.NextInt(0, Spawnpoints.Count - 1)]; |
---|
306 | if (target == player) |
---|
307 | { |
---|
308 | p2Points.Value += 1; |
---|
309 | Multiplier2 = 0; |
---|
310 | } |
---|
311 | else |
---|
312 | { |
---|
313 | p1Points.Value += 1; |
---|
314 | Multiplier1 = 0; |
---|
315 | } |
---|
316 | } |
---|
317 | |
---|
318 | void AddControlls(PlatformCharacter2 _player) |
---|
319 | { |
---|
320 | if (_player == player) |
---|
321 | { |
---|
322 | _player.AnimWalk = P1WalkAnim; |
---|
323 | _player.AnimIdle = playerImage; |
---|
324 | } |
---|
325 | else |
---|
326 | { |
---|
327 | _player.AnimWalk = P2WalkAnim; |
---|
328 | _player.AnimIdle = player2Image; |
---|
329 | } |
---|
330 | |
---|
331 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
332 | |
---|
333 | if (_player == player) |
---|
334 | { |
---|
335 | Keyboard.Listen(Key.A, ButtonState.Down, delegate { |
---|
336 | if(!isAttacking) |
---|
337 | _player.Walk(Direction.Left); |
---|
338 | }, null); |
---|
339 | Keyboard.Listen(Key.A, ButtonState.Released, delegate { _player.StopHorizontal(); }, null); |
---|
340 | Keyboard.Listen(Key.D, ButtonState.Down, delegate { |
---|
341 | if(!isAttacking) |
---|
342 | _player.Walk(Direction.Right); }, null); |
---|
343 | Keyboard.Listen(Key.D, ButtonState.Released, delegate { _player.StopHorizontal(); }, null); |
---|
344 | Keyboard.Listen(Key.W, ButtonState.Pressed, delegate { |
---|
345 | if(!isAttacking) |
---|
346 | Jump(_player, true); }, null); |
---|
347 | Keyboard.Listen(Key.S, ButtonState.Down, GetDown, null, false); |
---|
348 | Keyboard.Listen(Key.Space, ButtonState.Pressed, delegate |
---|
349 | { |
---|
350 | if (_player.FacingDirection == Direction.Left) |
---|
351 | Punch(_player, player2, true, Multiplier1); |
---|
352 | |
---|
353 | if (_player.FacingDirection == Direction.Right) |
---|
354 | Punch(_player, player2, false, Multiplier1); |
---|
355 | |
---|
356 | }, null); |
---|
357 | } |
---|
358 | if (_player == player2) |
---|
359 | { |
---|
360 | Keyboard.Listen(Key.Left, ButtonState.Down, delegate { |
---|
361 | if(!isAttacking2) |
---|
362 | _player.Walk(Direction.Left); }, null); |
---|
363 | Keyboard.Listen(Key.Left, ButtonState.Released, delegate { |
---|
364 | if(!isAttacking2) |
---|
365 | _player.StopHorizontal(); }, null); |
---|
366 | Keyboard.Listen(Key.Right, ButtonState.Down, delegate { _player.Walk(Direction.Right); }, null); |
---|
367 | Keyboard.Listen(Key.Right, ButtonState.Released, delegate { _player.StopHorizontal(); }, null); |
---|
368 | Keyboard.Listen(Key.Up, ButtonState.Pressed, delegate { |
---|
369 | if(!isAttacking2) |
---|
370 | Jump(_player, true); }, null); |
---|
371 | Keyboard.Listen(Key.Down, ButtonState.Down, GetDown, null, true); |
---|
372 | Keyboard.Listen(Key.RightControl, ButtonState.Pressed, delegate |
---|
373 | { |
---|
374 | if (_player.FacingDirection == Direction.Left) |
---|
375 | Punch(_player, player, true, Multiplier2); |
---|
376 | |
---|
377 | if (_player.FacingDirection == Direction.Right) |
---|
378 | Punch(_player, player, false, Multiplier2); |
---|
379 | |
---|
380 | }, null); |
---|
381 | } |
---|
382 | } |
---|
383 | |
---|
384 | void AddPlatform(Vector _pos, double x, double y) |
---|
385 | { |
---|
386 | Platforms.Add(new Platform(_pos.X, _pos.Y, x, y, platImage)); |
---|
387 | } |
---|
388 | |
---|
389 | void AddBlock(Vector _pos, double x, double y) |
---|
390 | { |
---|
391 | block = new PhysicsObject(x, y); |
---|
392 | block.Position = _pos; |
---|
393 | block.Color = Color.Black; |
---|
394 | block.Image = blockImage; |
---|
395 | block.StaticFriction = 0; |
---|
396 | block.Tag = "Block"; |
---|
397 | block.TextureWrapSize = new Vector(x / 50.0, y / 50.0); |
---|
398 | block.MakeStatic(); |
---|
399 | Add(block); |
---|
400 | } |
---|
401 | |
---|
402 | void AddBot(Vector _pos, double x, double y) |
---|
403 | { |
---|
404 | bot1 = new PlatformCharacter2(x/2, y); |
---|
405 | bot1.Position = _pos; |
---|
406 | bot1.Shape = Shape.Rectangle; |
---|
407 | bot1.Color = Color.HotPink; |
---|
408 | bot1.CollisionIgnoreGroup = 1; |
---|
409 | bot1.KineticFriction = 0; |
---|
410 | bot1.StaticFriction = 0; |
---|
411 | bot1.Tag = "Bot1"; |
---|
412 | Add(bot1); |
---|
413 | } |
---|
414 | |
---|
415 | void AddIcon(Image _iconPic, double x, double y, double _widht, double _height, string _name, double textWidht, double textHeight, bool isIcon2) |
---|
416 | { |
---|
417 | if (isIcon2) |
---|
418 | { |
---|
419 | icon2 = new Label(_widht, _height); |
---|
420 | icon2.Image = _iconPic; |
---|
421 | icon2.X = x; |
---|
422 | icon2.Y = y; |
---|
423 | //_icon.Position = Camera.ScreenToWorld(new Vector(x, y)); |
---|
424 | Layers[3].RelativeTransition = Vector.Zero; |
---|
425 | Layers[3].IgnoresZoom = true; |
---|
426 | Add(icon2, 3); |
---|
427 | |
---|
428 | p2Points = new IntMeter(0); |
---|
429 | |
---|
430 | Label pointScreen = new Label(); |
---|
431 | pointScreen.X = icon2.X - 20; |
---|
432 | pointScreen.Y = icon2.Y - 50; |
---|
433 | pointScreen.Title = "Points"; |
---|
434 | |
---|
435 | pointScreen.BindTo(p2Points); |
---|
436 | Add(pointScreen); |
---|
437 | } |
---|
438 | else |
---|
439 | { |
---|
440 | icon1 = new Label(_widht, _height); |
---|
441 | icon1.Image = _iconPic; |
---|
442 | icon1.X = x; |
---|
443 | icon1.Y = y; |
---|
444 | //_icon.Position = Camera.ScreenToWorld(new Vector(x, y)); |
---|
445 | Layers[3].RelativeTransition = Vector.Zero; |
---|
446 | Layers[3].IgnoresZoom = true; |
---|
447 | Add(icon1, 3); |
---|
448 | |
---|
449 | p1Points = new IntMeter(0); |
---|
450 | |
---|
451 | Label pointScreen = new Label(); |
---|
452 | pointScreen.X = icon1.X + 20; |
---|
453 | pointScreen.Y = icon1.Y - 50; |
---|
454 | pointScreen.Title = "Points"; |
---|
455 | |
---|
456 | pointScreen.BindTo(p1Points); |
---|
457 | Add(pointScreen); |
---|
458 | } |
---|
459 | |
---|
460 | AddPlayerNames(_name, textWidht, textHeight,isIcon2); |
---|
461 | } |
---|
462 | |
---|
463 | void AddPlayerNames(string _name, double x, double y, bool isIcon2) |
---|
464 | { |
---|
465 | Label nameField = new Label(_name.Length * 14, 30, _name); |
---|
466 | nameField.X = x; |
---|
467 | nameField.Y = y; |
---|
468 | Layers[3].RelativeTransition = Vector.Zero; |
---|
469 | Layers[3].IgnoresZoom = true; |
---|
470 | Add(nameField, 3); |
---|
471 | |
---|
472 | if (isIcon2) |
---|
473 | nameField.X = icon2.Left - nameField.Width / 2.0; |
---|
474 | else |
---|
475 | nameField.X = icon1.Right + nameField.Width / 2.0; |
---|
476 | |
---|
477 | //if (_name == p2name) |
---|
478 | //{ |
---|
479 | // while (nameField.Left < icon2.Right) |
---|
480 | // nameField.X -= 1; |
---|
481 | //} |
---|
482 | } |
---|
483 | |
---|
484 | void MovePlayer(PhysicsObject _object, Vector _vector) |
---|
485 | { |
---|
486 | _object.Velocity = _vector; |
---|
487 | } |
---|
488 | |
---|
489 | void Jump(PlatformCharacter2 character, bool isPlayer2) |
---|
490 | { |
---|
491 | if (blockLeft) |
---|
492 | { |
---|
493 | character.ForceJump(400); |
---|
494 | character.Hit(new Vector(200, 0)); |
---|
495 | } |
---|
496 | else if (blockRight) |
---|
497 | { |
---|
498 | character.ForceJump(600); |
---|
499 | character.Hit(new Vector(-200, 0)); |
---|
500 | } |
---|
501 | else |
---|
502 | { |
---|
503 | character.Jump(400); |
---|
504 | |
---|
505 | } |
---|
506 | |
---|
507 | foreach (Platform platform in Platforms) |
---|
508 | { |
---|
509 | platform.Process(true, isPlayer2); |
---|
510 | } |
---|
511 | } |
---|
512 | |
---|
513 | void Punch(PlatformCharacter2 _player, PlatformCharacter2 _object, bool left, Double _multiplier) |
---|
514 | { |
---|
515 | if (left) |
---|
516 | { |
---|
517 | if (_player.Left - 20 < _object.Right && _player.Left > _object.Right - 6) |
---|
518 | { |
---|
519 | punchNoice1.Play(); |
---|
520 | |
---|
521 | |
---|
522 | _object.Push(new Vector(-1500 * _multiplier, 100 * _multiplier)); |
---|
523 | if (_player == player) |
---|
524 | Multiplier1 += 2; |
---|
525 | |
---|
526 | else |
---|
527 | Multiplier2 += 2; |
---|
528 | } |
---|
529 | } |
---|
530 | |
---|
531 | if (!left) |
---|
532 | { |
---|
533 | if (_player.Right + 20 > _object.Left && _player.Right < _object.Left + 6) |
---|
534 | { |
---|
535 | punchNoice1.Play(); |
---|
536 | _object.Push(new Vector(1500 * _multiplier, 100 * _multiplier)); |
---|
537 | |
---|
538 | if (_player == player) |
---|
539 | Multiplier1 += 2; |
---|
540 | |
---|
541 | else |
---|
542 | Multiplier2 += 2; |
---|
543 | } |
---|
544 | } |
---|
545 | if (_player == player) |
---|
546 | { |
---|
547 | isAttacking = true; |
---|
548 | |
---|
549 | _player.PlayAnimation(p1Punch, () => |
---|
550 | { |
---|
551 | _player.StopHorizontal(); |
---|
552 | Timer.SingleShot(0.3, delegate { isAttacking = false; }); |
---|
553 | }); |
---|
554 | } |
---|
555 | else |
---|
556 | { |
---|
557 | isAttacking2 = true; |
---|
558 | _player.PlayAnimation(p2Punch, () => |
---|
559 | { |
---|
560 | _player.Stop(); |
---|
561 | Timer.SingleShot(0.5, delegate { isAttacking2 = false; }); |
---|
562 | }); |
---|
563 | } |
---|
564 | } |
---|
565 | |
---|
566 | void AddTimeCounter() |
---|
567 | { |
---|
568 | timeCounterSeconds = new IntMeter(30); |
---|
569 | timeCounterMinutes = new IntMeter(1); |
---|
570 | |
---|
571 | timeTimer = new Timer(); |
---|
572 | timeTimer.Interval = 1; |
---|
573 | timeTimer.Timeout += delegate { CountDown();}; |
---|
574 | timeTimer.Start(); |
---|
575 | |
---|
576 | timeScreenP = new Label(); |
---|
577 | timeScreenP.TextColor = Color.White; |
---|
578 | timeScreenP.DecimalPlaces = 1; |
---|
579 | timeScreenP.Text = timeCounterMinutes + ":" + timeCounterSeconds; |
---|
580 | timeScreenP.X = Screen.Center.X; |
---|
581 | timeScreenP.Y = Screen.Top - 20; |
---|
582 | timeScreenP.Font = Font.DefaultLargeBold; |
---|
583 | Add(timeScreenP, 3); |
---|
584 | } |
---|
585 | |
---|
586 | void CountDown() |
---|
587 | { |
---|
588 | timeCounterSeconds.Value -= 1; |
---|
589 | if (timeCounterSeconds.Value >= 10) |
---|
590 | timeScreenP.Text = timeCounterMinutes + ":" + timeCounterSeconds; |
---|
591 | |
---|
592 | else |
---|
593 | { |
---|
594 | timeScreenP.Text = timeCounterMinutes + ":0" + timeCounterSeconds; |
---|
595 | } |
---|
596 | |
---|
597 | if (timeCounterSeconds.Value <= 0 && timeCounterMinutes.Value > 0) |
---|
598 | { |
---|
599 | timeCounterMinutes.Value -= 1; |
---|
600 | timeCounterSeconds.Value += 60; |
---|
601 | } |
---|
602 | colorTimer = new Timer(); |
---|
603 | colorTimer.Interval = 0.05; |
---|
604 | colorTimer.Timeout += delegate |
---|
605 | { |
---|
606 | if (timeCounterSeconds <= 10 && timeCounterMinutes == 0) { |
---|
607 | Color _randomColor = RandomColor(); |
---|
608 | timeScreenP.TextColor = _randomColor; |
---|
609 | } |
---|
610 | else |
---|
611 | { |
---|
612 | timeScreenP.TextColor = Color.White; |
---|
613 | } |
---|
614 | }; |
---|
615 | colorTimer.Start(); |
---|
616 | |
---|
617 | if (timeCounterSeconds.Value <= 0 && timeCounterMinutes.Value == 0) |
---|
618 | { |
---|
619 | colorTimer.Stop(); |
---|
620 | timeScreenP.TextColor = Color.White; |
---|
621 | WinScreen(); |
---|
622 | } |
---|
623 | |
---|
624 | } |
---|
625 | |
---|
626 | void WinScreen() |
---|
627 | { |
---|
628 | if(p1Points > p2Points) |
---|
629 | { |
---|
630 | Pause(); |
---|
631 | if(p1name == "") |
---|
632 | winScreen = new MessageWindow("Blue player won!"); |
---|
633 | else |
---|
634 | winScreen = new MessageWindow(p1name + " won!"); |
---|
635 | winScreen.Closed += delegate { Begin(); Pause(); }; |
---|
636 | Add(winScreen); |
---|
637 | } |
---|
638 | else if (p2Points > p1Points) |
---|
639 | { |
---|
640 | Pause(); |
---|
641 | if(p2name == "") |
---|
642 | winScreen = new MessageWindow("Green player won!"); |
---|
643 | else |
---|
644 | winScreen = new MessageWindow(p2name + " won!"); |
---|
645 | winScreen.Closed += delegate { Begin(); Pause(); }; |
---|
646 | Add(winScreen); |
---|
647 | } |
---|
648 | else |
---|
649 | { |
---|
650 | Pause(); |
---|
651 | winScreen = new MessageWindow( "Draw!"); |
---|
652 | winScreen.Closed += delegate { Begin(); Pause(); }; |
---|
653 | Add(winScreen); |
---|
654 | |
---|
655 | } |
---|
656 | } |
---|
657 | |
---|
658 | Color RandomColor() |
---|
659 | { |
---|
660 | byte[] buffer = new byte[3]; |
---|
661 | new Random(DateTime.Now.Millisecond * 100000 + DateTime.Now.Second * 10000 + DateTime.Now.Minute * 100000).NextBytes(buffer); |
---|
662 | return new Color(buffer[0], buffer[1], buffer[2]); |
---|
663 | } |
---|
664 | |
---|
665 | } |
---|