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