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