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.

85 lines
2.5 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.Clamp(radius, 50, 200);
  23. float angleChange = modelTime * momentum / radius;
  24. angle += angleChange;
  25. float x = anchor.X + radius * (float) Math.Sin(angle);
  26. float y = anchor.Y + radius * (float) Math.Cos(angle);
  27. Position.X = x;
  28. Position.Y = y;
  29. }
  30. public void Draw(SpriteBatch spriteBatch) {
  31. Texture2D texture = Texture.Get;
  32. Vector2 spriteCenter = new Vector2(texture.Width / 2, texture.Height / 2);
  33. Vector2 drawPos = Vector2.Floor(Vector2.Subtract(Position, spriteCenter));
  34. spriteBatch.Draw(texture, drawPos, Color.White);
  35. }
  36. }
  37. public class Anchor {
  38. public TextureRef Texture = Textures.Terran;
  39. public Vector2 Position;
  40. public Anchor(float x, float y) {
  41. Position = new Vector2(x, y);
  42. }
  43. public void Draw(SpriteBatch spriteBatch) {
  44. Texture2D texture = Texture.Get;
  45. Vector2 spriteCenter = new Vector2(texture.Width / 2, texture.Height / 2);
  46. Vector2 drawPos = Vector2.Floor(Vector2.Subtract(Position, spriteCenter));
  47. spriteBatch.Draw(texture, drawPos, Color.White);
  48. }
  49. }
  50. public readonly Rectangle Bounds;
  51. public Spider Player;
  52. public ProfilingList<Anchor> Anchors;
  53. public SpiderWorld() {
  54. Bounds = new Rectangle(0, 0, 1280, 720);
  55. Player = new Spider(200, 720 / 2, 200, 0);
  56. Anchors = new ProfilingList<Anchor>(100, "anchors");
  57. Anchors.Add(new Anchor(200, 720 / 2));
  58. Anchors.Add(new Anchor(600, 720 / 4));
  59. Anchors.Add(new Anchor(800, 640));
  60. }
  61. ~SpiderWorld() {
  62. Dispose();
  63. }
  64. public void Dispose() {
  65. GC.SuppressFinalize(this);
  66. }
  67. public void Update(float modelTime, History<Input> input) {
  68. Player.Update(modelTime, input);
  69. }
  70. }
  71. }