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 OK : PhysicsGame |
---|
10 | { |
---|
11 | GameObject command; |
---|
12 | GameObject feed; |
---|
13 | GameObject portrait; |
---|
14 | GameObject foe; |
---|
15 | |
---|
16 | PhysicsObject Pointer; |
---|
17 | |
---|
18 | Vector nopeusYlos = new Vector(0, 100); |
---|
19 | Vector nopeusAlas = new Vector(0, -100); |
---|
20 | Vector nopeusVasen = new Vector(-200, 0); |
---|
21 | Vector nopeusOikea = new Vector(200, 0); |
---|
22 | |
---|
23 | public override void Begin() |
---|
24 | { |
---|
25 | LuoAlue(); |
---|
26 | luopelaaja(); |
---|
27 | Kontrollit(); |
---|
28 | |
---|
29 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
30 | } |
---|
31 | |
---|
32 | void LuoAlue() |
---|
33 | { |
---|
34 | Level.Background.Color = Color.White; |
---|
35 | |
---|
36 | command = new GameObject(450.0, 300.0); |
---|
37 | command.Shape = Shape.Rectangle; |
---|
38 | command.Color = Color.Black; |
---|
39 | command.X = 370.00; |
---|
40 | command.Y = -330.00; |
---|
41 | command.Image = LoadImage("Kökkö"); |
---|
42 | Add(command); |
---|
43 | |
---|
44 | feed = new GameObject(1000.00, 300.00); |
---|
45 | feed.Shape = Shape.Rectangle; |
---|
46 | feed.Color = Color.Black; |
---|
47 | feed.X = -400.00; |
---|
48 | feed.Y = -330.00; |
---|
49 | Add(feed); |
---|
50 | |
---|
51 | portrait = new GameObject(250.00, 300.00); |
---|
52 | portrait.Shape = Shape.Rectangle; |
---|
53 | portrait.Color = Color.Black; |
---|
54 | portrait.X = 750.00; |
---|
55 | portrait.Y = -330.00; |
---|
56 | Add(portrait); |
---|
57 | |
---|
58 | foe = new GameObject(1800.00, 700.00); |
---|
59 | foe.Shape = Shape.Rectangle; |
---|
60 | foe.Color = Color.Blue; |
---|
61 | foe.X = -10.00; |
---|
62 | foe.Y = 200.00; |
---|
63 | Add(foe); |
---|
64 | } |
---|
65 | |
---|
66 | PhysicsObject luopelaaja() |
---|
67 | { |
---|
68 | Pointer = new PhysicsObject (10.0, 10.0); |
---|
69 | Pointer.Color = Color.White; |
---|
70 | Pointer.X = 190.00; |
---|
71 | Pointer.Y = -220.00; |
---|
72 | Add(Pointer,3); |
---|
73 | return Pointer; |
---|
74 | } |
---|
75 | |
---|
76 | void AsetaNopeus(PhysicsObject Pointer, Vector nopeus) |
---|
77 | { |
---|
78 | Vector sijainti = Pointer.Position + nopeus; |
---|
79 | if (sijainti.Y > command.Top) return; |
---|
80 | else if (sijainti.Y < command.Bottom) return; |
---|
81 | |
---|
82 | Pointer.MoveTo(Pointer.Position + nopeus, 1000.00); |
---|
83 | |
---|
84 | } |
---|
85 | void Kontrollit () |
---|
86 | { |
---|
87 | Keyboard.Listen(Key.Down, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusAlas); |
---|
88 | //Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
89 | |
---|
90 | Keyboard.Listen(Key.Up, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusYlos); |
---|
91 | //Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
92 | |
---|
93 | //Keyboard.Listen(Key.Left, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusVasen); |
---|
94 | ///Keyboard.Listen(Key.Left, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
95 | |
---|
96 | //Keyboard.Listen(Key.Right, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusOikea); |
---|
97 | //Keyboard.Listen(Key.Right, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
98 | |
---|
99 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); } |
---|
100 | } |
---|