1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.ScreenObjects; |
---|
4 | using Jypeli.Assets; |
---|
5 | |
---|
6 | namespace Pong |
---|
7 | { |
---|
8 | public class Peli : PhysicsGame |
---|
9 | { |
---|
10 | PhysicsObject pallo; |
---|
11 | PhysicsObject maila1; |
---|
12 | PhysicsObject maila2; |
---|
13 | |
---|
14 | protected override void Begin() |
---|
15 | { |
---|
16 | Vector impulssi = new Vector(500.0, 0.0); |
---|
17 | Luokentta(); |
---|
18 | asetaohjaimet(); |
---|
19 | Aloitapeli(); |
---|
20 | pallo.Hit(impulssi); |
---|
21 | |
---|
22 | } |
---|
23 | |
---|
24 | void Luokentta() |
---|
25 | { |
---|
26 | pallo = new PhysicsObject(40.0, 40.0); |
---|
27 | pallo.Shape = Shapes.Circle; |
---|
28 | Add(pallo); |
---|
29 | Level.CreateBorders(1.0, false); |
---|
30 | pallo.Restitution = 1.0; |
---|
31 | Level.BackgroundColor = Color.LightBlue; |
---|
32 | Camera.ZoomToLevel(1.0); |
---|
33 | pallo.X = -200.0; |
---|
34 | pallo.Y = 0.0; |
---|
35 | |
---|
36 | maila1 = LuoMaila(Level.Left + 20.0, 0.0); |
---|
37 | maila2 = LuoMaila(Level.Right - 20.0, 0.0); |
---|
38 | } |
---|
39 | |
---|
40 | void Aloitapeli() |
---|
41 | { |
---|
42 | Vector impulssi = new Vector( 500.0, 0.0); |
---|
43 | pallo.Hit(impulssi); |
---|
44 | } |
---|
45 | |
---|
46 | PhysicsObject LuoMaila (Double x, double y) |
---|
47 | { |
---|
48 | PhysicsObject maila = PhysicsObject.CreateStaticObject( 20.0, 100.0); |
---|
49 | maila.Shape = Shapes.Rectangle; |
---|
50 | maila.X = x; |
---|
51 | maila.Y = y; |
---|
52 | maila.Restitution = 1.0; |
---|
53 | Add(maila); |
---|
54 | |
---|
55 | return maila; |
---|
56 | } |
---|
57 | |
---|
58 | void asetaohjaimet() |
---|
59 | { |
---|
60 | Keyboard.Listen(Key.A, ButtonState.Pressed, liikutamailaylös, "pelaaja 1: liikutaa mailaa ylös",maila1); |
---|
61 | Keyboard.Listen(Key.A, ButtonState.Released, pysaytamaila, null, maila1); |
---|
62 | Keyboard.Listen(Key.Z, ButtonState.Pressed, LiikutaMailaaAlas, "Pelaaja 1: Liikuta mailaa alas", maila1); |
---|
63 | Keyboard.Listen(Key.Z, ButtonState.Released, PysaytaMaila, null, maila1); |
---|
64 | |
---|
65 | Keyboard.Listen(Key.Up, ButtonState.Pressed, LiikutaMailaaYlos, "Pelaaja 2: Liikuta mailaa ylös", maila2); |
---|
66 | Keyboard.Listen(Key.Up, ButtonState.Released, PysaytaMaila, null, maila2); |
---|
67 | Keyboard.Listen(Key.Down, ButtonState.Pressed, LiikutaMailaaAlas, "Pelaaja 2: Liikuta mailaa alas", maila2); |
---|
68 | Keyboard.Listen(Key.Down, ButtonState.Released, PysaytaMaila, null, maila2); |
---|
69 | |
---|
70 | Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); |
---|
71 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); |
---|
72 | } |
---|
73 | |
---|
74 | void liikutamailaylös( PhysicsObject maila ) |
---|
75 | { |
---|
76 | Vector nopeus = new Vector(0, 200); |
---|
77 | maila.Velocity = nopeus; |
---|
78 | } |
---|
79 | |
---|
80 | void pysaytamaila(PhysicsObject maila) |
---|
81 | { |
---|
82 | maila.Velocity = Vector.Zero; |
---|
83 | } |
---|
84 | |
---|
85 | void liikutamailaalas(PhysicsObject maila) |
---|
86 | { |
---|
87 | Vector nopeus = new Vector(0, -200); |
---|
88 | maila.Velocity = nopeus; |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|
93 | } |
---|