2021-02-08 22:26:40 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace SemiColinGames {
|
|
|
|
|
public sealed class SpiderWorld : IWorld {
|
|
|
|
|
|
|
|
|
|
public class Spider {
|
|
|
|
|
public TextureRef Texture = Textures.Yellow2;
|
|
|
|
|
public Vector2 Position;
|
|
|
|
|
private Vector2 anchor;
|
|
|
|
|
private float radius;
|
|
|
|
|
private float angle;
|
2021-07-12 18:57:22 +00:00
|
|
|
|
private float momentum = -300; // radians / second * pixels
|
2021-02-08 22:26:40 +00:00
|
|
|
|
|
|
|
|
|
public Spider(float x, float y, float radius, float angle) {
|
|
|
|
|
Position = new Vector2();
|
|
|
|
|
anchor = new Vector2(x, y);
|
|
|
|
|
this.angle = angle;
|
|
|
|
|
this.radius = radius;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(float modelTime, History<Input> input) {
|
2021-07-12 18:57:22 +00:00
|
|
|
|
radius += 150 * modelTime * input[0].Motion.Y;
|
|
|
|
|
radius = Math.Clamp(radius, 50, 200);
|
2021-02-08 22:26:40 +00:00
|
|
|
|
float angleChange = modelTime * momentum / radius;
|
|
|
|
|
angle += angleChange;
|
|
|
|
|
float x = anchor.X + radius * (float) Math.Sin(angle);
|
|
|
|
|
float y = anchor.Y + radius * (float) Math.Cos(angle);
|
|
|
|
|
Position.X = x;
|
|
|
|
|
Position.Y = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Draw(SpriteBatch spriteBatch) {
|
|
|
|
|
Texture2D texture = Texture.Get;
|
|
|
|
|
Vector2 spriteCenter = new Vector2(texture.Width / 2, texture.Height / 2);
|
|
|
|
|
Vector2 drawPos = Vector2.Floor(Vector2.Subtract(Position, spriteCenter));
|
|
|
|
|
spriteBatch.Draw(texture, drawPos, Color.White);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Anchor {
|
2021-07-12 18:57:22 +00:00
|
|
|
|
public TextureRef Texture = Textures.Terran;
|
2021-02-08 22:26:40 +00:00
|
|
|
|
public Vector2 Position;
|
|
|
|
|
|
|
|
|
|
public Anchor(float x, float y) {
|
|
|
|
|
Position = new Vector2(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Draw(SpriteBatch spriteBatch) {
|
|
|
|
|
Texture2D texture = Texture.Get;
|
|
|
|
|
Vector2 spriteCenter = new Vector2(texture.Width / 2, texture.Height / 2);
|
|
|
|
|
Vector2 drawPos = Vector2.Floor(Vector2.Subtract(Position, spriteCenter));
|
|
|
|
|
spriteBatch.Draw(texture, drawPos, Color.White);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public readonly Rectangle Bounds;
|
|
|
|
|
public Spider Player;
|
|
|
|
|
public ProfilingList<Anchor> Anchors;
|
|
|
|
|
|
|
|
|
|
public SpiderWorld() {
|
|
|
|
|
Bounds = new Rectangle(0, 0, 1280, 720);
|
2021-07-12 18:57:22 +00:00
|
|
|
|
Player = new Spider(200, 720 / 2, 200, 0);
|
2021-02-08 22:26:40 +00:00
|
|
|
|
|
|
|
|
|
Anchors = new ProfilingList<Anchor>(100, "anchors");
|
2021-07-12 18:57:22 +00:00
|
|
|
|
Anchors.Add(new Anchor(200, 720 / 2));
|
|
|
|
|
Anchors.Add(new Anchor(600, 720 / 4));
|
|
|
|
|
Anchors.Add(new Anchor(800, 640));
|
2021-02-08 22:26:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~SpiderWorld() {
|
|
|
|
|
Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose() {
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(float modelTime, History<Input> input) {
|
|
|
|
|
Player.Update(modelTime, input);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|