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