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 Peli : PhysicsGame |
---|
10 | { |
---|
11 | PhysicsObject Mato; |
---|
12 | PhysicsObject Saalis; |
---|
13 | |
---|
14 | public override void Begin() |
---|
15 | { |
---|
16 | // TODO: Kirjoita ohjelmakoodisi tähän |
---|
17 | LuoKentta(); |
---|
18 | LuoMato(); |
---|
19 | AsetaOhjaimet(); |
---|
20 | |
---|
21 | Timer ajastin = new Timer(); |
---|
22 | ajastin.Interval = 0.1; |
---|
23 | ajastin.Trigger += LiikutaMatoa; |
---|
24 | ajastin.Start(); |
---|
25 | |
---|
26 | Timer sadeajastin = new Timer(); |
---|
27 | ajastin.Interval = 0.1; |
---|
28 | ajastin.Trigger += Vihollinen; |
---|
29 | ajastin.Start(); |
---|
30 | |
---|
31 | |
---|
32 | LuoSaalis(20, 30); |
---|
33 | LuoLaskuri(); |
---|
34 | |
---|
35 | |
---|
36 | LuoVihollinen(); |
---|
37 | |
---|
38 | |
---|
39 | } |
---|
40 | |
---|
41 | void LuoKentta() |
---|
42 | { |
---|
43 | Level.CreateBorders(); |
---|
44 | Camera.ZoomToLevel(); |
---|
45 | |
---|
46 | |
---|
47 | } |
---|
48 | |
---|
49 | void LuoMato() |
---|
50 | { |
---|
51 | Mato = new PhysicsObject(30.0, 40.0); |
---|
52 | Add(Mato); |
---|
53 | Mato.Shape = Shape.Star; |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | } |
---|
58 | |
---|
59 | void AsetaOhjaimet() |
---|
60 | |
---|
61 | { |
---|
62 | Mouse.IsCursorVisible = true; |
---|
63 | // Mouse.ListenMovement(0.1, KuunteleLiiketta, null); |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | void KuunteleLiiketta(AnalogState hiirenTila) |
---|
68 | { |
---|
69 | Mato.X = Mouse.PositionOnWorld.X; |
---|
70 | Mato.Y = Mouse.PositionOnWorld.Y; |
---|
71 | |
---|
72 | Vector hiirenLiike = hiirenTila.MouseMovement; |
---|
73 | |
---|
74 | } |
---|
75 | |
---|
76 | void LiikutaMatoa (Timer sender ) |
---|
77 | { |
---|
78 | Vector etaisyys = Mouse.PositionOnWorld - Mato.Position; |
---|
79 | Mato.MoveTo(Mouse.PositionOnWorld, etaisyys.Magnitude*1.5 ); |
---|
80 | Mato.Angle = etaisyys.Angle; |
---|
81 | |
---|
82 | } |
---|
83 | |
---|
84 | void LuoSaalis(double X, double Y) |
---|
85 | { |
---|
86 | Saalis = new PhysicsObject(30, 30); |
---|
87 | Add(Saalis); |
---|
88 | Saalis.Shape = Shape.Heart; |
---|
89 | Saalis.Position = new Vector(X, Y); |
---|
90 | FollowerBrain karkuunSaalis = new FollowerBrain(Mato, -50); |
---|
91 | karkuunSaalis.Target = Mato; |
---|
92 | Saalis.Brain = karkuunSaalis; |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | } |
---|
100 | IntMeter pisteLaskuri; |
---|
101 | |
---|
102 | void LuoLaskuri() |
---|
103 | { |
---|
104 | pisteLaskuri = new IntMeter(0); |
---|
105 | |
---|
106 | Label pisteTeksti = new Label("Pisteitä: "); |
---|
107 | pisteTeksti.X = Screen.Right - 160; |
---|
108 | pisteTeksti.Y = Screen.Top - 100; |
---|
109 | pisteTeksti.TextColor = Color.Red; |
---|
110 | Add(pisteTeksti); |
---|
111 | |
---|
112 | Label pisteNaytto = new Label(); |
---|
113 | pisteNaytto.X = Screen.Right - 110; |
---|
114 | pisteNaytto.Y = Screen.Top - 100; |
---|
115 | pisteNaytto.TextColor = Color.Red; |
---|
116 | |
---|
117 | pisteNaytto.BindTo(pisteLaskuri); |
---|
118 | Add(pisteNaytto); |
---|
119 | |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | void LuoVihollinen() |
---|
124 | { |
---|
125 | Vector suunta = new Vector(0, 1); |
---|
126 | PhysicsObject Vihollinen = new PhysicsObject(new RaySegment(Vector.zero, suunta, 2000) ); |
---|
127 | Add(Vihollinen); |
---|
128 | |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | } |
---|