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 PhysicsBall : PhysicsGame |
---|
10 | { |
---|
11 | Image Tausta = LoadImage("Maisema"); |
---|
12 | PhysicsObject Pelaaja; |
---|
13 | PhysicsObject Maali; |
---|
14 | PhysicsObject Nappula; |
---|
15 | |
---|
16 | public override void Begin() |
---|
17 | { |
---|
18 | |
---|
19 | Level.Background.Image = Tausta; |
---|
20 | |
---|
21 | LuoMaali(); |
---|
22 | AloitaKentta(); |
---|
23 | Pelaaja = new PhysicsObject(40, 40); |
---|
24 | Pelaaja.X = -400; |
---|
25 | Pelaaja.Y = -350; |
---|
26 | Pelaaja.Shape = Shape.Circle; |
---|
27 | Pelaaja.Color = Color.Red; |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | Add(Pelaaja); |
---|
32 | Level.CreateBorders(); |
---|
33 | Pelaaja.KineticFriction = 0.8; |
---|
34 | |
---|
35 | |
---|
36 | Gravity = new Vector(0, -700); |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | Keyboard.Listen(Key.A, ButtonState.Down, |
---|
41 | LiikutaPelaajaa, null, new Vector(-300, 0), Pelaaja); |
---|
42 | Keyboard.Listen(Key.D, ButtonState.Down, |
---|
43 | LiikutaPelaajaa, null, new Vector(300, 0), Pelaaja); |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); |
---|
48 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
49 | |
---|
50 | Level.BackgroundColor = Color.LightGray; |
---|
51 | |
---|
52 | |
---|
53 | Camera.ZoomToLevel(); |
---|
54 | |
---|
55 | } |
---|
56 | void AloitaKentta() |
---|
57 | { |
---|
58 | |
---|
59 | Camera.Follow(Pelaaja); |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | } |
---|
66 | void LiikutaPelaajaa(Vector vektori, PhysicsObject pelaaja) |
---|
67 | { |
---|
68 | pelaaja.Push(vektori); |
---|
69 | } |
---|
70 | Object LuoMaali() |
---|
71 | { |
---|
72 | PhysicsObject Nappula = PhysicsObject.CreateStaticObject(20, 20); |
---|
73 | Nappula.Shape = Shape.Rectangle; |
---|
74 | Nappula.X = -300; |
---|
75 | Nappula.Y = Level.Top; |
---|
76 | Add(Nappula); |
---|
77 | Nappula.Color = Color.Red; |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | PhysicsObject Maali = PhysicsObject.CreateStaticObject(400.0, 400.0); |
---|
83 | Maali.Shape = Shape.Rectangle; |
---|
84 | Maali.X = Level.Right; |
---|
85 | Maali.Y = Level.Bottom; |
---|
86 | Add(Maali); |
---|
87 | Maali.Color = Color.Black; |
---|
88 | return Maali; |
---|
89 | |
---|
90 | |
---|
91 | } |
---|
92 | |
---|
93 | } |
---|