1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Widgets; |
---|
4 | using Jypeli.Assets; |
---|
5 | |
---|
6 | public class Peli : PhysicsGame |
---|
7 | { |
---|
8 | Timer kello; |
---|
9 | PhysicsObject pelaaja; |
---|
10 | |
---|
11 | protected override void Begin() |
---|
12 | { |
---|
13 | MessageDisplay.TextColor = Color.White; |
---|
14 | kello = LuoLahettaja(); |
---|
15 | Tuho(); |
---|
16 | Level.BackgroundColor = Color.Black; |
---|
17 | pelaaja = Pelaaja(); |
---|
18 | |
---|
19 | } |
---|
20 | |
---|
21 | PhysicsObject Pelaaja() |
---|
22 | { |
---|
23 | PhysicsObject pelaaja = new PhysicsObject(50.0, 50.0); |
---|
24 | pelaaja.Color = Color.Blue; |
---|
25 | pelaaja.Shape = Shapes.Triangle; |
---|
26 | pelaaja.IgnoresCollisionResponse = true; |
---|
27 | |
---|
28 | Keyboard.Listen(Key.Left, ButtonState.Down, Vauhdikkuus, "Siirry vasemmalle", new Vector(-100.0, 0.0)); |
---|
29 | Keyboard.Listen(Key.Left, ButtonState.Released, Vauhdikkuus, null, Vector.Zero); |
---|
30 | Keyboard.Listen(Key.Right, ButtonState.Down, Vauhdikkuus, "Sirry oikealle", new Vector (100.0, 0.0)); |
---|
31 | Keyboard.Listen(Key.Right, ButtonState.Released, Vauhdikkuus, null, Vector.Zero); |
---|
32 | Add(pelaaja); |
---|
33 | return pelaaja; |
---|
34 | } |
---|
35 | |
---|
36 | PhysicsObject Minion() |
---|
37 | { |
---|
38 | PhysicsObject minion = new PhysicsObject(50.0, 50.0); |
---|
39 | minion.Color = Color.DarkGray; |
---|
40 | minion.Shape = Shapes.Triangle; |
---|
41 | double vaakasijainti = RandomGen.NextDouble(Level.Left, Level.Right); |
---|
42 | minion.Y = Level.Top + 200; |
---|
43 | minion.X = vaakasijainti; |
---|
44 | Add(minion); |
---|
45 | |
---|
46 | Vector[] reitti = new Vector[2]; |
---|
47 | reitti[0] = new Vector(0, Level.Top); |
---|
48 | reitti[1] = new Vector(vaakasijainti, Level.Bottom - 200); |
---|
49 | PathFollowerBrain aivot = new PathFollowerBrain(reitti); |
---|
50 | minion.Brain = aivot; |
---|
51 | aivot.Speed = 200; |
---|
52 | aivot.Active = true; |
---|
53 | return minion; |
---|
54 | } |
---|
55 | |
---|
56 | Timer LuoLahettaja() |
---|
57 | { |
---|
58 | Timer kello = new Timer(); |
---|
59 | kello.Interval = 0.6; |
---|
60 | kello.Trigger += LahetaMinion; |
---|
61 | kello.Start(); |
---|
62 | return kello; |
---|
63 | } |
---|
64 | |
---|
65 | PhysicsObject Tuho() |
---|
66 | { |
---|
67 | PhysicsObject tuho = PhysicsObject.CreateStaticObject(Screen.Width, 60.0); |
---|
68 | tuho.Y = Level.Bottom + 0; |
---|
69 | Add(tuho); |
---|
70 | AddCollisionHandler(tuho, Tyrmays); |
---|
71 | return tuho; |
---|
72 | } |
---|
73 | |
---|
74 | void Tyrmays(PhysicsObject tyrmaaja, PhysicsObject kohde) |
---|
75 | { |
---|
76 | kohde.Destroy(); |
---|
77 | MessageDisplay.Add("Vihollinen pääsi ohitsesi"); |
---|
78 | } |
---|
79 | |
---|
80 | void LahetaMinion(Timer sender) |
---|
81 | { |
---|
82 | Minion(); |
---|
83 | } |
---|
84 | |
---|
85 | void Vauhdikkuus(Vector suunta) |
---|
86 | { |
---|
87 | pelaaja.Velocity = suunta; |
---|
88 | } |
---|
89 | |
---|
90 | } |
---|