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.

86 lines
2.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  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 SpiderWorld : IWorld {
  7. public class Spider {
  8. public TextureRef Texture = Textures.Yellow2;
  9. public Vector2 Position;
  10. private Vector2 anchor;
  11. private float radius;
  12. private float angle;
  13. private float momentum = -300; // radians / second * pixels
  14. public Spider(float x, float y, float radius, float angle) {
  15. Position = new Vector2();
  16. anchor = new Vector2(x, y);
  17. this.angle = angle;
  18. this.radius = radius;
  19. }
  20. public void Update(float modelTime, History<Input> input) {
  21. radius += 150 * modelTime * input[0].Motion.Y;
  22. radius = Math.Min(radius, 200);
  23. radius = Math.Max(radius, 50);
  24. float angleChange = modelTime * momentum / radius;
  25. angle += angleChange;
  26. float x = anchor.X + radius * (float) Math.Sin(angle);
  27. float y = anchor.Y + radius * (float) Math.Cos(angle);
  28. Position.X = x;
  29. Position.Y = y;
  30. }
  31. public void Draw(SpriteBatch spriteBatch) {
  32. Texture2D texture = Texture.Get;
  33. Vector2 spriteCenter = new Vector2(texture.Width / 2, texture.Height / 2);
  34. Vector2 drawPos = Vector2.Floor(Vector2.Subtract(Position, spriteCenter));
  35. spriteBatch.Draw(texture, drawPos, Color.White);
  36. }
  37. }
  38. public class Anchor {
  39. public TextureRef Texture = Textures.Terran;
  40. public Vector2 Position;
  41. public Anchor(float x, float y) {
  42. Position = new Vector2(x, y);
  43. }
  44. public void Draw(SpriteBatch spriteBatch) {
  45. Texture2D texture = Texture.Get;
  46. Vector2 spriteCenter = new Vector2(texture.Width / 2, texture.Height / 2);
  47. Vector2 drawPos = Vector2.Floor(Vector2.Subtract(Position, spriteCenter));
  48. spriteBatch.Draw(texture, drawPos, Color.White);
  49. }
  50. }
  51. public readonly Rectangle Bounds;
  52. public Spider Player;
  53. public ProfilingList<Anchor> Anchors;
  54. public SpiderWorld() {
  55. Bounds = new Rectangle(0, 0, 1280, 720);
  56. Player = new Spider(200, 720 / 2, 200, 0);
  57. Anchors = new ProfilingList<Anchor>(100, "anchors");
  58. Anchors.Add(new Anchor(200, 720 / 2));
  59. Anchors.Add(new Anchor(600, 720 / 4));
  60. Anchors.Add(new Anchor(800, 640));
  61. }
  62. ~SpiderWorld() {
  63. Dispose();
  64. }
  65. public void Dispose() {
  66. GC.SuppressFinalize(this);
  67. }
  68. public void Update(float modelTime, History<Input> input) {
  69. Player.Update(modelTime, input);
  70. }
  71. }
  72. }