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 | PhysicsObject pallo; |
---|
12 | public override void Begin() |
---|
13 | { |
---|
14 | LuoKentta(); |
---|
15 | AloitaPeli(); |
---|
16 | AsetaOhjaimet(); |
---|
17 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
18 | |
---|
19 | } |
---|
20 | void AloitaPeli() |
---|
21 | { |
---|
22 | Vector impulssi = new Vector(400.0, 0.0); |
---|
23 | pallo.Hit(impulssi); |
---|
24 | } |
---|
25 | void LuoKentta() { |
---|
26 | |
---|
27 | |
---|
28 | Level.Width = Screen.Width; |
---|
29 | Camera.ZoomToLevel(); |
---|
30 | pallo = new PhysicsObject(40.0, 40.0); |
---|
31 | // TODO: Kirjoita ohjelmakoodisi tähän |
---|
32 | Add(pallo); |
---|
33 | |
---|
34 | pallo.Shape = Shape.Circle; |
---|
35 | pallo.X = -200.0; |
---|
36 | pallo.Y = 0.0; |
---|
37 | pallo.Restitution = 1.0; |
---|
38 | Level.CreateBorders(1.0, false); |
---|
39 | Level.Background.Color = Color.DarkGreen; |
---|
40 | |
---|
41 | LuoMaila(Level.Left + 20.0, 0.0); |
---|
42 | LuoMaila(Level.Right - 20.0, 0.0); |
---|
43 | |
---|
44 | } |
---|
45 | void AsetaOhjaimet() |
---|
46 | { |
---|
47 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
48 | Keyboard.Listen(Key.A, ButtonState.Down, LiikutaMailaYlös, "Pelaaja 1: Liikuta mailaa ylös"); |
---|
49 | |
---|
50 | } |
---|
51 | void AsetaNopeus(PhysicsObject maila, Vector nopeus) |
---|
52 | { |
---|
53 | maila.Velocity = nopeus; |
---|
54 | } |
---|
55 | |
---|
56 | void LuoMaila(double x, double y) |
---|
57 | { |
---|
58 | PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); |
---|
59 | maila.Shape = Shape.Rectangle; |
---|
60 | maila.X = x; |
---|
61 | maila.Y = y; |
---|
62 | maila.Restitution = 1.0; |
---|
63 | Add(maila); |
---|
64 | } |
---|
65 | } |
---|