1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Widgets; |
---|
7 | |
---|
8 | |
---|
9 | public class Pong : PhysicsGame |
---|
10 | { |
---|
11 | Vector nopeusYlos = new Vector(0, 200); |
---|
12 | Vector nopeusAlas = new Vector(0, -200); |
---|
13 | PhysicsObject pallo; |
---|
14 | PhysicsObject maila1; |
---|
15 | PhysicsObject maila2; |
---|
16 | |
---|
17 | public override void Begin () |
---|
18 | { |
---|
19 | LuoKentta (); |
---|
20 | LuoReunat (); |
---|
21 | AsetaOhjaimet (); |
---|
22 | AloitaPeli (); |
---|
23 | |
---|
24 | } |
---|
25 | void LuoKentta() |
---|
26 | { |
---|
27 | pallo = new PhysicsObject(30.0, 40.0); |
---|
28 | Add(pallo); |
---|
29 | pallo.Shape = Shape.Rectangle; |
---|
30 | pallo.Shape = Shape.FromImage(LoadImage("Untitled")); |
---|
31 | pallo.X = -200.0; |
---|
32 | pallo.Y = 0.0; |
---|
33 | |
---|
34 | maila1 = LuoMaila (Level.Left + 20.0, 0.0); |
---|
35 | maila2 = LuoMaila (Level.Right - 20, 0.0); |
---|
36 | |
---|
37 | pallo.Restitution = 1.0; |
---|
38 | Level.Background.Color = Color.Green; |
---|
39 | pallo.Color = Color.Black; |
---|
40 | //Camera.ZoomToLevel(); |
---|
41 | //Camera.Zoom(1.05); |
---|
42 | |
---|
43 | } |
---|
44 | void LuoReunat() |
---|
45 | { |
---|
46 | PhysicsObject alaReuna = Level.CreateBottomBorder (); |
---|
47 | alaReuna.Y = -425; |
---|
48 | alaReuna.IsVisible = true; |
---|
49 | PhysicsObject yläReuna = Level.CreateTopBorder (); |
---|
50 | yläReuna.Y = 425; |
---|
51 | yläReuna.IsVisible = true; |
---|
52 | PhysicsObject vasenReuna = Level.CreateLeftBorder (); |
---|
53 | vasenReuna.Y = 0; |
---|
54 | vasenReuna.IsVisible = true; |
---|
55 | PhysicsObject oikeaReuna = Level.CreateRightBorder (); |
---|
56 | oikeaReuna.Y = 0; |
---|
57 | oikeaReuna.IsVisible = true; |
---|
58 | } |
---|
59 | PhysicsObject LuoMaila(double mailacoordX, double mailacoordY) |
---|
60 | { |
---|
61 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); |
---|
62 | maila.Shape = Shape.Rectangle; |
---|
63 | maila.X = mailacoordX; |
---|
64 | maila.Y = mailacoordY; |
---|
65 | maila.Restitution = 1.0; |
---|
66 | Add(maila); |
---|
67 | return maila; |
---|
68 | } |
---|
69 | void AloitaPeli() |
---|
70 | { |
---|
71 | Vector impulssi = new Vector (500.0, 12.0); |
---|
72 | pallo.Hit (impulssi); |
---|
73 | |
---|
74 | } |
---|
75 | void AsetaOhjaimet() |
---|
76 | { |
---|
77 | Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); |
---|
78 | Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); |
---|
79 | Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); |
---|
80 | Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); |
---|
81 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
82 | Keyboard.Listen(Key.5, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila1, nopeusYlos); |
---|
83 | Keyboard.Listen(Key.5, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); |
---|
84 | Keyboard.Listen(Key.2, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila1, nopeusAlas); |
---|
85 | Keyboard.Listen(Key.2, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); |
---|
86 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
87 | } |
---|
88 | void AsetaNopeus(PhysicsObject maila, Vector nopeus) |
---|
89 | { |
---|
90 | maila.Velocity = nopeus; |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | } |
---|
96 | |
---|