A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.4 KiB

  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace SemiColinGames {
  6. public sealed class ShmupWorld : IWorld {
  7. public class ShmupPlayer {
  8. public TextureRef Texture = Textures.Yellow2;
  9. // Center of player sprite.
  10. public Vector2 Position = new Vector2(48, 1080 / 8);
  11. public Vector2 HalfSize = new Vector2(16, 10);
  12. public float Speed = 150f;
  13. }
  14. public class Shot {
  15. public TextureRef Texture = Textures.Projectile1;
  16. public Vector2 Position;
  17. public Vector2 HalfSize = new Vector2(11, 8);
  18. public Vector2 Velocity;
  19. public Shot(Vector2 position, Vector2 velocity) {
  20. Position = position;
  21. Velocity = velocity;
  22. }
  23. }
  24. public readonly Point Size;
  25. public readonly ShmupPlayer Player;
  26. public readonly ProfilingList<Shot> Shots;
  27. public ShmupWorld() {
  28. Size = new Point(1920 / 4, 1080 / 4);
  29. Player = new ShmupPlayer();
  30. Shots = new ProfilingList<Shot>(100, "shots");
  31. Vector2 velocity = new Vector2(100, 0);
  32. Shots.Add(new Shot(new Vector2(96, 1080 / 8), velocity));
  33. Shots.Add(new Shot(new Vector2(96 * 2, 1080 / 8), velocity));
  34. Shots.Add(new Shot(new Vector2(96 * 4, 1080 / 8), velocity));
  35. }
  36. ~ShmupWorld() {
  37. Dispose();
  38. }
  39. public void Dispose() {
  40. GC.SuppressFinalize(this);
  41. }
  42. public void Update(float modelTime, History<Input> input) {
  43. Vector2 motion = Vector2.Multiply(input[0].Motion, modelTime * Player.Speed);
  44. Player.Position = Vector2.Add(Player.Position, motion);
  45. Player.Position.X = Math.Max(Player.Position.X, Player.HalfSize.X);
  46. Player.Position.X = Math.Min(Player.Position.X, Size.X - Player.HalfSize.X);
  47. Player.Position.Y = Math.Max(Player.Position.Y, Player.HalfSize.Y);
  48. Player.Position.Y = Math.Min(Player.Position.Y, Size.Y - Player.HalfSize.Y);
  49. foreach (Shot shot in Shots) {
  50. shot.Position = Vector2.Add(shot.Position, Vector2.Multiply(shot.Velocity, modelTime));
  51. shot.Position.X = Math.Max(shot.Position.X, shot.HalfSize.X);
  52. shot.Position.X = Math.Min(shot.Position.X, Size.X - shot.HalfSize.X);
  53. shot.Position.X = Math.Max(shot.Position.X, shot.HalfSize.X);
  54. shot.Position.X = Math.Min(shot.Position.X, Size.X - shot.HalfSize.X);
  55. }
  56. // Shots.RemoveAll(shot => shot.Position.X > Size.X);
  57. }
  58. }
  59. }