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 | class player : PhysicsObject |
---|
10 | { |
---|
11 | public IntMeter health = new IntMeter(100,0,100); |
---|
12 | |
---|
13 | public player(double width, double height) |
---|
14 | : base(width, height) |
---|
15 | { |
---|
16 | health.LowerLimit += delegate |
---|
17 | { |
---|
18 | this.Destroy(); |
---|
19 | }; |
---|
20 | } |
---|
21 | } |
---|
22 | |
---|
23 | class enemy : PhysicsObject |
---|
24 | { |
---|
25 | public IntMeter health = new IntMeter(100, 0, 100); |
---|
26 | public IntMeter ScoreValue = new IntMeter(100, 0, int.MaxValue); |
---|
27 | public bool canShoot = false; |
---|
28 | |
---|
29 | public enemy(double width, double height) |
---|
30 | : base(width, height) |
---|
31 | { |
---|
32 | health.LowerLimit += delegate { this.Destroy(); }; |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | class bullet : PhysicsObject |
---|
37 | { |
---|
38 | public int damage; |
---|
39 | |
---|
40 | public bullet(double width, double height) |
---|
41 | : base(width, height) { } |
---|
42 | } |
---|
43 | class frontborder : PhysicsObject |
---|
44 | { |
---|
45 | |
---|
46 | public frontborder(double width, double height) |
---|
47 | : base(width, height) { } |
---|
48 | } |
---|
49 | class backborder : PhysicsObject |
---|
50 | { |
---|
51 | |
---|
52 | public backborder(double width, double height) |
---|
53 | : base(width, height) { } |
---|
54 | } |
---|
55 | |
---|
56 | public class LM2 : PhysicsGame |
---|
57 | { |
---|
58 | player player = new player(5, 5); |
---|
59 | PhysicsObject playership = new PhysicsObject(37, 48); |
---|
60 | double player_speed = 400; |
---|
61 | Vector stagespeed = new Vector(-500,0); |
---|
62 | |
---|
63 | bool BlazeIt = false; |
---|
64 | |
---|
65 | //Player |
---|
66 | Image player_ship_01 = LoadImage("player_ship_01"); |
---|
67 | //Bullets |
---|
68 | Image bullet_green_laser01 = LoadImage("bullet_green_laser01"); |
---|
69 | Image bullet_player = LoadImage("bullet_player"); |
---|
70 | //Enemies |
---|
71 | Image enemy_ship_01 = LoadImage("enemy_ship_01"); |
---|
72 | Image enemy_ship_01_red = LoadImage("enemy_ship_01_red"); |
---|
73 | |
---|
74 | //Weapon |
---|
75 | double wpn_shootRate = 0.05; |
---|
76 | int wpn_damageRatio = 1; |
---|
77 | DoubleMeter wpn_spread = new DoubleMeter(1,1,10); |
---|
78 | |
---|
79 | |
---|
80 | Timer wpn_timer = new Timer(); |
---|
81 | |
---|
82 | |
---|
83 | public override void Begin() |
---|
84 | { |
---|
85 | SetWindowSize(1280, 800, false); |
---|
86 | |
---|
87 | Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); |
---|
88 | |
---|
89 | CreateLevel("level_test"); |
---|
90 | } |
---|
91 | |
---|
92 | //TODO INTRO |
---|
93 | void introScene() |
---|
94 | { |
---|
95 | introBorders(); |
---|
96 | |
---|
97 | |
---|
98 | } |
---|
99 | void introBorders() |
---|
100 | { |
---|
101 | PhysicsObject introBorder = new PhysicsObject(Screen.WidthSafe, Screen.HeightSafe / 4); |
---|
102 | introBorder.Shape = Shape.Rectangle; |
---|
103 | introBorder.Color = Color.Black; |
---|
104 | introBorder.IgnoresCollisionResponse = true; |
---|
105 | introBorder.IgnoresPhysicsLogics = true; |
---|
106 | introBorder.Position = new Vector(introBorder.Position.X, Screen.TopSafe - introBorder.Height / 2); |
---|
107 | Add(introBorder); |
---|
108 | |
---|
109 | PhysicsObject introBorder2 = new PhysicsObject(Screen.WidthSafe, Screen.HeightSafe / 4); |
---|
110 | introBorder2.Shape = Shape.Rectangle; |
---|
111 | introBorder2.Color = Color.Black; |
---|
112 | introBorder2.IgnoresCollisionResponse = true; |
---|
113 | introBorder2.IgnoresPhysicsLogics = true; |
---|
114 | introBorder2.Position = new Vector(introBorder2.Position.X, Screen.BottomSafe + introBorder2.Height / 2); |
---|
115 | Add(introBorder2); |
---|
116 | } |
---|
117 | |
---|
118 | //Stage creation |
---|
119 | void CreateLevel(string level) |
---|
120 | { |
---|
121 | Level.Background.Color = Color.LightGray; |
---|
122 | Timer strobeBg = new Timer(); |
---|
123 | strobeBg.Interval = 0.005; |
---|
124 | strobeBg.Timeout += delegate { |
---|
125 | Level.Background.Color = RandomGen.NextColor(); |
---|
126 | }; |
---|
127 | if (BlazeIt) strobeBg.Start(); |
---|
128 | |
---|
129 | TileMap lvl = TileMap.FromLevelAsset(level); |
---|
130 | lvl.SetTileMethod('x', border); |
---|
131 | lvl.SetTileMethod('%', frontBorder); |
---|
132 | lvl.SetTileMethod('&', backBorder); |
---|
133 | lvl.SetTileMethod('P', AddPlayer); |
---|
134 | lvl.SetTileMethod('1', enemy_ship_1); |
---|
135 | lvl.SetTileMethod('R', enemy_ship_1_red); |
---|
136 | lvl.Execute(35, 35); |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | //AddPlayer(Screen.Center, 0, 0); |
---|
142 | AddControls(); |
---|
143 | AddHealthbar(); |
---|
144 | setwpn_timer(); |
---|
145 | |
---|
146 | Camera.Position = player.Position; |
---|
147 | //Camera.ZoomFactor = 0.5; |
---|
148 | //edgeBorders(); |
---|
149 | } |
---|
150 | //Tiles for level |
---|
151 | void border(Vector position, double width, double height) |
---|
152 | { |
---|
153 | PhysicsObject border = PhysicsObject.CreateStaticObject(width, height); |
---|
154 | border.Position = position; |
---|
155 | border.Restitution = 0; |
---|
156 | border.KineticFriction = 0; |
---|
157 | border.StaticFriction = 0; |
---|
158 | border.Color = Color.Lighter(Color.Black, 20); |
---|
159 | border.Tag = "border"; |
---|
160 | Add(border, 1); |
---|
161 | |
---|
162 | PhysicsObject border2 = PhysicsObject.CreateStaticObject(width*2, height); |
---|
163 | border2.Position = position; |
---|
164 | border2.Restitution = 0; |
---|
165 | border2.KineticFriction = 0; |
---|
166 | border2.StaticFriction = 0; |
---|
167 | border2.Color = Color.Lighter(Color.Black, 20); |
---|
168 | border2.Tag = "border"; |
---|
169 | Add(border2, 0); |
---|
170 | |
---|
171 | Timer strobe = new Timer(); |
---|
172 | strobe.Interval = 0.005; |
---|
173 | strobe.Timeout += delegate { |
---|
174 | border.Color = RandomGen.NextColor(); |
---|
175 | border2.Color = RandomGen.NextColor(); |
---|
176 | }; |
---|
177 | if (BlazeIt) strobe.Start(); |
---|
178 | } |
---|
179 | void frontBorder(Vector position, double width, double height) |
---|
180 | { |
---|
181 | frontborder border = new frontborder(width, height); |
---|
182 | border.Position = position; |
---|
183 | border.Color = Color.White; |
---|
184 | border.Restitution = 0; |
---|
185 | border.Tag = "border"; |
---|
186 | border.IgnoresCollisionResponse = true; |
---|
187 | border.IgnoresPhysicsLogics = true; |
---|
188 | AddCollisionHandler<PhysicsObject, player>(border, frontBorderCollision); |
---|
189 | AddCollisionHandler<PhysicsObject, enemy>(border, frontBorderCollisionEnemy); |
---|
190 | Add(border); |
---|
191 | } |
---|
192 | void backBorder(Vector position, double width, double height) |
---|
193 | { |
---|
194 | backborder border = new backborder(width, height); |
---|
195 | border.Position = position; |
---|
196 | border.Color = Color.White; |
---|
197 | border.Restitution = 0; |
---|
198 | border.Tag = "border"; |
---|
199 | border.IgnoresCollisionResponse = true; |
---|
200 | border.IgnoresCollisionResponse = true; |
---|
201 | AddCollisionHandler<PhysicsObject, player>(border, backBorderCollision); |
---|
202 | //AddCollisionHandler<PhysicsObject, enemy>(border, backBorderCollisionEnemy); |
---|
203 | Add(border); |
---|
204 | } |
---|
205 | void frontBorderCollision(PhysicsObject border, PhysicsObject target) |
---|
206 | { |
---|
207 | player.health.Value = player.health.Value - player.health.Value; |
---|
208 | } |
---|
209 | void frontBorderCollisionEnemy(PhysicsObject border, enemy enemy) |
---|
210 | { |
---|
211 | enemy.canShoot = true; |
---|
212 | } |
---|
213 | void backBorderCollision(PhysicsObject border, PhysicsObject target) |
---|
214 | { |
---|
215 | player.health.Value = player.health.Value - player.health.Value; |
---|
216 | } |
---|
217 | void backBorderCollisionEnemy(PhysicsObject border, enemy enemy) |
---|
218 | { |
---|
219 | enemy.Destroy(); |
---|
220 | } |
---|
221 | |
---|
222 | void testblock(Vector pos, double width, double height) |
---|
223 | { |
---|
224 | PhysicsObject b = new PhysicsObject(width, height); |
---|
225 | b.Position = pos; |
---|
226 | b.Shape = Shape.Rectangle; |
---|
227 | b.Color = Color.Blue; |
---|
228 | Add(b); |
---|
229 | } |
---|
230 | |
---|
231 | //Player related |
---|
232 | void AddPlayer(Vector pos, double width, double height) |
---|
233 | { |
---|
234 | player.Shape = Shape.Circle; |
---|
235 | player.Color = Color.Red; |
---|
236 | player.MomentOfInertia = 10; |
---|
237 | player.Restitution = 0; |
---|
238 | player.Mass = int.MaxValue; |
---|
239 | player.CanRotate = true; |
---|
240 | player.KineticFriction = 0; |
---|
241 | player.StaticFriction = 0; |
---|
242 | player.IgnoresGravity = true; |
---|
243 | player.Position = pos; |
---|
244 | player.Tag = "player1"; |
---|
245 | Add(player,2); |
---|
246 | |
---|
247 | Timer strobePlr = new Timer(); |
---|
248 | strobePlr.Interval = 0.005; |
---|
249 | strobePlr.Timeout += delegate { player.Color = RandomGen.NextColor(); }; |
---|
250 | if (BlazeIt) strobePlr.Start(); |
---|
251 | |
---|
252 | playership.Image = player_ship_01; |
---|
253 | playership.IgnoresCollisionResponse = true; |
---|
254 | playership.IgnoresPhysicsLogics = true; |
---|
255 | playership.Angle = Angle.FromDegrees(-90); |
---|
256 | playership.CanRotate = false; |
---|
257 | //playership.Parent = player; |
---|
258 | playership.Position = player.Position; |
---|
259 | |
---|
260 | FollowerBrain playershipbrain = new FollowerBrain(player); |
---|
261 | playershipbrain.Speed = 500; |
---|
262 | playershipbrain.DistanceFar = 5000; |
---|
263 | playershipbrain.DistanceClose = 0; |
---|
264 | playershipbrain.StopWhenTargetClose = true; |
---|
265 | playershipbrain.Active = true; |
---|
266 | playershipbrain.TurnWhileMoving = false; |
---|
267 | |
---|
268 | playership.Brain = playershipbrain; |
---|
269 | Add(playership, -2); |
---|
270 | } |
---|
271 | void AddHealthbar() |
---|
272 | { |
---|
273 | ProgressBar healthBar = new ProgressBar(200, 10); |
---|
274 | healthBar.BorderColor = Color.Black; |
---|
275 | healthBar.Color = Color.Black; |
---|
276 | healthBar.BarColor = Color.Red; |
---|
277 | healthBar.BindTo(player.health); |
---|
278 | healthBar.Angle = Angle.RightAngle; |
---|
279 | healthBar.Position = new Vector(Screen.LeftSafe + 30, Screen.BottomSafe + 235); |
---|
280 | Add(healthBar); |
---|
281 | |
---|
282 | Timer strobehpBar = new Timer(); |
---|
283 | strobehpBar.Interval = 0.005; |
---|
284 | strobehpBar.Timeout += delegate { healthBar.BarColor = RandomGen.NextColor(); }; |
---|
285 | if (BlazeIt) strobehpBar.Start(); |
---|
286 | } |
---|
287 | void AddControls() |
---|
288 | |
---|
289 | { |
---|
290 | ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, null); |
---|
291 | ControllerOne.ListenAnalog(AnalogControl.LeftStick, -0.1, move, null); |
---|
292 | |
---|
293 | ControllerOne.Listen(Button.B, ButtonState.Pressed, shoot, null); |
---|
294 | ControllerOne.Listen(Button.B, ButtonState.Released, stopShoot, null); |
---|
295 | |
---|
296 | //cheat |
---|
297 | Keyboard.Listen(Key.U, ButtonState.Pressed, cheat_upgrade, null); |
---|
298 | } |
---|
299 | void move(AnalogState speed) |
---|
300 | { |
---|
301 | player.Velocity = speed.StateVector * player_speed; |
---|
302 | } |
---|
303 | void cheat_upgrade() |
---|
304 | { |
---|
305 | wpn_spread.Value++; |
---|
306 | } |
---|
307 | |
---|
308 | //Weapon system |
---|
309 | void shoot() |
---|
310 | { |
---|
311 | //wpn_timer.Stop(); |
---|
312 | wpn_timer.Interval = wpn_shootRate; |
---|
313 | |
---|
314 | wpn_timer.Start(); |
---|
315 | } |
---|
316 | void setwpn_timer() |
---|
317 | { |
---|
318 | wpn_timer.Timeout += delegate |
---|
319 | { |
---|
320 | if (!player.IsDestroyed) |
---|
321 | { |
---|
322 | if (ControllerOne.GetButtonState(Button.B) == ButtonState.Down) |
---|
323 | { |
---|
324 | Weapon(); |
---|
325 | wpn_timer.Interval = wpn_shootRate; |
---|
326 | } |
---|
327 | }; |
---|
328 | }; |
---|
329 | } |
---|
330 | |
---|
331 | void stopShoot() |
---|
332 | { |
---|
333 | wpn_timer.Stop(); |
---|
334 | } |
---|
335 | |
---|
336 | void Weapon() |
---|
337 | { |
---|
338 | if (wpn_spread.Value == 1) |
---|
339 | { |
---|
340 | Projectile(player.Position + new Vector(10, 5), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
341 | Projectile(player.Position + new Vector(10, -5), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
342 | } |
---|
343 | else if (wpn_spread.Value == 2) |
---|
344 | { |
---|
345 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
346 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
347 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
348 | } |
---|
349 | else if (wpn_spread.Value == 3) |
---|
350 | { |
---|
351 | Projectile(player.Position + new Vector(10, 5), new Vector(1200, 15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
352 | Projectile(player.Position + new Vector(10, -5), new Vector(1200, -15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
353 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 20), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
354 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -20), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
355 | } |
---|
356 | else if (wpn_spread.Value == 4) |
---|
357 | { |
---|
358 | Projectile(player.Position + new Vector(10, 5), new Vector(1200, 25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
359 | Projectile(player.Position + new Vector(10, -5), new Vector(1200, -25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
360 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
361 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
362 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
363 | } |
---|
364 | else if (wpn_spread.Value == 5) |
---|
365 | { |
---|
366 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
367 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
368 | |
---|
369 | Projectile(player.Position + new Vector(10, 5), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
370 | Projectile(player.Position + new Vector(10, -5), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
371 | |
---|
372 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 55), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
373 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -55), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
374 | } |
---|
375 | else if (wpn_spread.Value == 6) |
---|
376 | { |
---|
377 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
378 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, -25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
379 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
380 | Projectile(player.Position + new Vector(10, 5), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
381 | Projectile(player.Position + new Vector(10, -5), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
382 | |
---|
383 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 75), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
384 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -75), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
385 | } |
---|
386 | else if (wpn_spread.Value == 7) |
---|
387 | { |
---|
388 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
389 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, -15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
390 | Projectile(player.Position + new Vector(10, 5), new Vector(1200, 15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
391 | Projectile(player.Position + new Vector(10, -5), new Vector(1200, -15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
392 | |
---|
393 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
394 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
395 | |
---|
396 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
397 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
398 | } |
---|
399 | else if (wpn_spread.Value == 8) |
---|
400 | { |
---|
401 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
402 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
403 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, -25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
404 | Projectile(player.Position + new Vector(10, 5), new Vector(1200, 25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
405 | Projectile(player.Position + new Vector(10, -5), new Vector(1200, -25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
406 | |
---|
407 | Projectile(player.Position + new Vector(10, 5), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
408 | Projectile(player.Position + new Vector(10, -5), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
409 | |
---|
410 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
411 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
412 | } |
---|
413 | else if (wpn_spread.Value == 9) |
---|
414 | { |
---|
415 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
416 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, -15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
417 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
418 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -15), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
419 | |
---|
420 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
421 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
422 | |
---|
423 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
424 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
425 | |
---|
426 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 75), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
427 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, -75), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
428 | } |
---|
429 | else if (wpn_spread.Value == 10) |
---|
430 | { |
---|
431 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
432 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, -25), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
433 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 0), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
434 | Projectile(player.Position + new Vector(10, 0), new Vector(1200, 50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
435 | Projectile(player.Position + new Vector(10, -0), new Vector(1200, -50), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
436 | |
---|
437 | Projectile(player.Position + new Vector(10, 5), new Vector(1200, 75), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
438 | Projectile(player.Position + new Vector(10, -5), new Vector(1200, -75), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
439 | |
---|
440 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 100), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
441 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -100), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
442 | |
---|
443 | Projectile(player.Position + new Vector(10, 10), new Vector(1200, 125), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
444 | Projectile(player.Position + new Vector(10, -10), new Vector(1200, -125), new Vector(40, 12), Color.LightBlue, "bullet", Shape.Rectangle); |
---|
445 | } |
---|
446 | } |
---|
447 | void Projectile(Vector pos, Vector vel, Vector size, Color color, string type, Shape shape) |
---|
448 | { |
---|
449 | bullet projectile = new bullet(size.X, size.Y); |
---|
450 | projectile.Shape = Shape.Diamond; |
---|
451 | projectile.Color = color; |
---|
452 | projectile.IgnoresGravity = true; |
---|
453 | projectile.Position = pos; |
---|
454 | projectile.Tag = "player_bullet"; |
---|
455 | if (!BlazeIt) projectile.Image = bullet_player; |
---|
456 | projectile.damage = wpn_damageRatio; |
---|
457 | projectile.IgnoresCollisionResponse = true; |
---|
458 | |
---|
459 | projectile.CollisionIgnoreGroup = 2; |
---|
460 | projectile.MaximumLifetime = TimeSpan.FromSeconds(1.57); |
---|
461 | |
---|
462 | //AddCollisionHandler(projectile, "border", destroy); |
---|
463 | AddCollisionHandler<bullet, frontborder>(projectile, destroy); |
---|
464 | AddCollisionHandler<bullet, enemy>(projectile, damageEnemy); |
---|
465 | |
---|
466 | Add(projectile, -2); |
---|
467 | projectile.Hit(vel / 1.5); |
---|
468 | projectile.Angle = projectile.Velocity.Angle; |
---|
469 | |
---|
470 | |
---|
471 | Timer strobe = new Timer(); |
---|
472 | strobe.Interval = 0.005; |
---|
473 | strobe.Timeout += delegate { |
---|
474 | projectile.Color = RandomGen.NextColor(); |
---|
475 | if (projectile.IsDestroyed) strobe.Stop(); |
---|
476 | }; |
---|
477 | if (BlazeIt) strobe.Start(); |
---|
478 | } |
---|
479 | |
---|
480 | //Enemies |
---|
481 | void enemy_ship_1(Vector pos, double width, double height) |
---|
482 | { |
---|
483 | enemy enemyship = new enemy(70, 35); |
---|
484 | enemyship.Shape = Shape.Circle; |
---|
485 | enemyship.Color = Color.Black; |
---|
486 | enemyship.Position = pos; |
---|
487 | enemyship.IgnoresCollisionResponse = true; |
---|
488 | enemyship.health.MaxValue = 8; |
---|
489 | enemyship.Image = enemy_ship_01; |
---|
490 | |
---|
491 | Add(enemyship); |
---|
492 | enemyship.Hit(stagespeed); |
---|
493 | AddCollisionHandler<enemy, player>(enemyship, damagePlayerEnemyShip); |
---|
494 | AddCollisionHandler<enemy, frontborder>(enemyship, enemy_ship_1_frontborder); |
---|
495 | } |
---|
496 | void enemy_ship_1_frontborder(enemy enemyship, frontborder border) |
---|
497 | { |
---|
498 | enemyship.LifetimeLeft = TimeSpan.FromSeconds(4); |
---|
499 | } |
---|
500 | void enemy_ship_1_red(Vector pos, double width, double height) |
---|
501 | { |
---|
502 | enemy enemyship = new enemy(70, 35); |
---|
503 | enemyship.Shape = Shape.Circle; |
---|
504 | enemyship.Color = Color.Black; |
---|
505 | enemyship.Position = pos; |
---|
506 | enemyship.IgnoresCollisionResponse = true; |
---|
507 | enemyship.health.MaxValue = 8; |
---|
508 | enemyship.Image = enemy_ship_01_red; |
---|
509 | |
---|
510 | Add(enemyship); |
---|
511 | enemyship.Hit(stagespeed); |
---|
512 | AddCollisionHandler<enemy, player>(enemyship, damagePlayerEnemyShip); |
---|
513 | AddCollisionHandler<enemy, frontborder>(enemyship, enemy_ship_1_red_frontborder); |
---|
514 | } |
---|
515 | void enemy_ship_1_red_frontborder(enemy enemyship, frontborder border) |
---|
516 | { |
---|
517 | if (!enemyship.canShoot) |
---|
518 | { |
---|
519 | enemyship.Angle = Angle.FromDegrees(180); |
---|
520 | enemyship.Velocity = -stagespeed; |
---|
521 | enemyship.Position = new Vector(border.X-1400, enemyship.Position.Y); |
---|
522 | enemyship.LifetimeLeft = TimeSpan.FromSeconds(4); |
---|
523 | |
---|
524 | enemyship.canShoot = true; |
---|
525 | }; |
---|
526 | } |
---|
527 | |
---|
528 | //Misc |
---|
529 | void destroy(PhysicsObject p, PhysicsObject target) |
---|
530 | { |
---|
531 | p.Destroy(); |
---|
532 | } |
---|
533 | void damagePlayerEnemyShip(enemy b, player p) |
---|
534 | { |
---|
535 | p.health.Value = p.health.Value - 10; |
---|
536 | b.Destroy(); |
---|
537 | } |
---|
538 | void damagePlayerBullet(bullet b, player p) |
---|
539 | { |
---|
540 | p.health.Value = p.health.Value - b.damage; |
---|
541 | b.Destroy(); |
---|
542 | } |
---|
543 | void damageEnemy(bullet b, enemy e) |
---|
544 | { |
---|
545 | e.health.Value = e.health.Value - b.damage; |
---|
546 | b.Destroy(); |
---|
547 | } |
---|
548 | } |
---|