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 Pong : PhysicsGame |
---|
10 | { |
---|
11 | Vector nopeusYlos = new Vector(0, 200); |
---|
12 | Vector nopeusAlas = new Vector(0, -200); |
---|
13 | |
---|
14 | PhysicsObject pallo; |
---|
15 | |
---|
16 | PhysicsObject maila1; |
---|
17 | PhysicsObject maila2; |
---|
18 | |
---|
19 | public override void Begin() |
---|
20 | { |
---|
21 | LuoKentta(); |
---|
22 | AsetaOhjaimet(); |
---|
23 | AloitaPeli(); |
---|
24 | } |
---|
25 | |
---|
26 | void AsetaOhjaimet() |
---|
27 | { |
---|
28 | Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMailaYlos, "Pelaaja 1: Liikuta mailaa ylös"); |
---|
29 | Keyboard.Listen(Key.A, ButtonState.Released, PysaytaMaila1, null); |
---|
30 | |
---|
31 | |
---|
32 | } |
---|
33 | |
---|
34 | void LuoKentta() |
---|
35 | { |
---|
36 | // TODO: Kirjoita ohjelmakoodisi tähän |
---|
37 | pallo = new PhysicsObject(44.0, 44.0); |
---|
38 | Add(pallo); |
---|
39 | pallo.Shape = Shape.Hexagon; |
---|
40 | pallo.X = 200.0; |
---|
41 | pallo.Y = 30; |
---|
42 | |
---|
43 | maila1 = LuoMaila(Level.Left + 20.0, 0.0); |
---|
44 | maila2 = LuoMaila(Level.Right - 20.0, 0.0); |
---|
45 | |
---|
46 | |
---|
47 | Level.CreateBorders(); |
---|
48 | pallo.Restitution = 1.0; |
---|
49 | Level.CreateBorders(1.0, true); |
---|
50 | Level.BackgroundColor = Color.Cyan; |
---|
51 | Camera.ZoomToLevel(); |
---|
52 | |
---|
53 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
54 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
55 | } |
---|
56 | void AloitaPeli() |
---|
57 | { |
---|
58 | Vector impulssi = new Vector(500.0, 0.0); |
---|
59 | pallo.Hit(impulssi); |
---|
60 | } |
---|
61 | void LuoMaila(double x, double y) |
---|
62 | { |
---|
63 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); |
---|
64 | maila.Shape = Shape.Rectangle; |
---|
65 | maila.X = x; |
---|
66 | maila.Y = y; |
---|
67 | maila.Restitution = 1.0; |
---|
68 | Add(maila); |
---|
69 | return maila; |
---|
70 | } |
---|
71 | void AsetaNopeus(PhysicsObject maila, Vector nopeus) |
---|
72 | { |
---|
73 | maila.Velocity = nopeus; |
---|
74 | } |
---|
75 | } |
---|