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;
private float momentum = -300; // radians / second * pixels
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) {
radius += 150 * modelTime * input[0].Motion.Y;
radius = Math.Clamp(radius, 50, 200);
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 {
public TextureRef Texture = Textures.Terran;
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 Anchors;
public SpiderWorld() {
Bounds = new Rectangle(0, 0, 1280, 720);
Player = new Spider(200, 720 / 2, 200, 0);
Anchors = new ProfilingList(100, "anchors");
Anchors.Add(new Anchor(200, 720 / 2));
Anchors.Add(new Anchor(600, 720 / 4));
Anchors.Add(new Anchor(800, 640));
}
~SpiderWorld() {
Dispose();
}
public void Dispose() {
GC.SuppressFinalize(this);
}
public void Update(float modelTime, History input) {
Player.Update(modelTime, input);
}
}
}