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 | IntMeter goopHP; |
---|
19 | IntMeter HP; |
---|
20 | |
---|
21 | Label foeHP; |
---|
22 | Label playerHP; |
---|
23 | |
---|
24 | Vector nopeusYlos = new Vector(0, 100); |
---|
25 | Vector nopeusAlas = new Vector(0, -100); |
---|
26 | Vector nopeusVasen = new Vector(-200, 0); |
---|
27 | Vector nopeusOikea = new Vector(200, 0); |
---|
28 | |
---|
29 | public override void Begin() |
---|
30 | { |
---|
31 | LuoAlue(); |
---|
32 | luopelaaja(); |
---|
33 | LuoHP(); |
---|
34 | Kontrollit(); |
---|
35 | |
---|
36 | |
---|
37 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
38 | } |
---|
39 | |
---|
40 | void LuoAlue() |
---|
41 | { |
---|
42 | Level.Background.Color = Color.White; |
---|
43 | |
---|
44 | command = new GameObject(450.0, 300.0); |
---|
45 | command.Shape = Shape.Rectangle; |
---|
46 | command.Color = Color.Black; |
---|
47 | command.X = 370.00; |
---|
48 | command.Y = -330.00; |
---|
49 | command.Image = LoadImage("Kökkö"); |
---|
50 | Add(command); |
---|
51 | |
---|
52 | feed = new GameObject(1000.00, 300.00); |
---|
53 | feed.Shape = Shape.Rectangle; |
---|
54 | feed.Color = Color.Black; |
---|
55 | feed.X = -400.00; |
---|
56 | feed.Y = -330.00; |
---|
57 | Add(feed); |
---|
58 | |
---|
59 | portrait = new GameObject(250.00, 300.00); |
---|
60 | portrait.Shape = Shape.Rectangle; |
---|
61 | portrait.Color = Color.Black; |
---|
62 | portrait.X = 750.00; |
---|
63 | portrait.Y = -330.00; |
---|
64 | Add(portrait); |
---|
65 | |
---|
66 | foe = new GameObject(1800.00, 700.00); |
---|
67 | foe.Shape = Shape.Rectangle; |
---|
68 | foe.Color = Color.Aqua; |
---|
69 | foe.X = -10.00; |
---|
70 | foe.Y = 200.00; |
---|
71 | foe.Image = LoadImage("köntsä"); |
---|
72 | Add(foe); |
---|
73 | } |
---|
74 | |
---|
75 | PhysicsObject luopelaaja() |
---|
76 | { |
---|
77 | Pointer = new PhysicsObject(5.0, 5.0); |
---|
78 | Pointer.Color = Color.White; |
---|
79 | Pointer.X = 190.00; |
---|
80 | Pointer.Y = -220.00; |
---|
81 | Add(Pointer, 3); |
---|
82 | return Pointer; |
---|
83 | } |
---|
84 | |
---|
85 | void LuoHP() |
---|
86 | { |
---|
87 | goopHP = new IntMeter(20); |
---|
88 | |
---|
89 | Label foeHP = new Label(); |
---|
90 | |
---|
91 | foeHP.X = 150.00; |
---|
92 | foeHP.Y = Screen.Top - 40.00; |
---|
93 | foeHP.TextColor = Color.Red; |
---|
94 | foeHP.Color = Color.Transparent; |
---|
95 | |
---|
96 | foeHP.BindTo(goopHP); |
---|
97 | Add(foeHP); |
---|
98 | |
---|
99 | HP = new IntMeter(60); |
---|
100 | |
---|
101 | Label playerHP = new Label(); |
---|
102 | |
---|
103 | playerHP.X = 660.00; |
---|
104 | playerHP.Y = -200.00; |
---|
105 | playerHP.TextColor = Color.LightGreen; |
---|
106 | playerHP.Color = Color.Transparent; |
---|
107 | |
---|
108 | playerHP.BindTo(HP); |
---|
109 | Add(playerHP); |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | } |
---|
115 | void AsetaNopeus(PhysicsObject Pointer, Vector nopeus) |
---|
116 | { |
---|
117 | if (Pointer.Velocity.Magnitude > 0) return; |
---|
118 | |
---|
119 | Vector sijainti = Pointer.Position + nopeus; |
---|
120 | if (sijainti.Y > command.Top) return; |
---|
121 | else if (sijainti.Y < command.Bottom) return; |
---|
122 | |
---|
123 | Pointer.MoveTo(Pointer.Position + nopeus, 1000.00); |
---|
124 | |
---|
125 | } |
---|
126 | void Kontrollit() |
---|
127 | { |
---|
128 | Keyboard.Listen(Key.Down, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusAlas); |
---|
129 | //Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
130 | |
---|
131 | Keyboard.Listen(Key.Up, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusYlos); |
---|
132 | //Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
133 | |
---|
134 | //Keyboard.Listen(Key.Left, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusVasen); |
---|
135 | ///Keyboard.Listen(Key.Left, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
136 | |
---|
137 | //Keyboard.Listen(Key.Right, ButtonState.Pressed, AsetaNopeus, "liikkuu", Pointer, nopeusOikea); |
---|
138 | //Keyboard.Listen(Key.Right, ButtonState.Released, AsetaNopeus, null, Pointer, Vector.Zero); |
---|
139 | |
---|
140 | Keyboard.Listen(Key.Z, ButtonState.Pressed, Valitse, null); |
---|
141 | |
---|
142 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
143 | |
---|
144 | } |
---|
145 | |
---|
146 | void Valitse() |
---|
147 | |
---|
148 | { |
---|
149 | if (Pointer.Y > command.Top - command.Height / 3) Attack(); |
---|
150 | else if (Pointer.Y < command.Bottom + command.Height / 3) Exit(); |
---|
151 | else Exit(); |
---|
152 | } |
---|
153 | |
---|
154 | void Attack() |
---|
155 | { |
---|
156 | goopHP.Value -= 10; |
---|
157 | |
---|
158 | Hitanim(); |
---|
159 | } |
---|
160 | |
---|
161 | void Hitanim() |
---|
162 | { |
---|
163 | GameObject hit = new GameObject(100.00, 100.00); |
---|
164 | hit.Shape = Shape.Star; |
---|
165 | hit.Color = Color.OrangeRed; |
---|
166 | hit.X = 0.00; |
---|
167 | hit.Y = Screen.Top - 60.00; |
---|
168 | Add(hit, 3); |
---|
169 | hit.Image = LoadImage("hitanim2"); |
---|
170 | hit.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 50); |
---|
171 | |
---|
172 | PlaySound("hit"); |
---|
173 | |
---|
174 | GameObject hit2 = new GameObject(100.00, 100.00); |
---|
175 | hit2.Shape = Shape.Star; |
---|
176 | hit2.Color = Color.OrangeRed; |
---|
177 | hit2.X = 0.00; |
---|
178 | hit2.Y = Screen.Top - 60.00; |
---|
179 | hit2.Image = LoadImage("hitanim"); |
---|
180 | hit2.MaximumLifetime = new TimeSpan(0, 0, 0, 0, 100); |
---|
181 | Add(hit2, 3); |
---|
182 | |
---|
183 | Attackfeed(); |
---|
184 | } |
---|
185 | |
---|
186 | void Attackfeed() |
---|
187 | { |
---|
188 | GameObject feed2= new GameObject (1000.00, 300.00); |
---|
189 | feed2.Shape = Shape.Rectangle; |
---|
190 | feed2.Color = Color.Black; |
---|
191 | feed2.X = -400.00; |
---|
192 | feed2.Y = -330.00; |
---|
193 | feed2.Image = LoadImage("feed2"); |
---|
194 | Add(feed2); |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | } |
---|