69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace SemiColinGames {
|
|
public sealed class ShmupWorld : IWorld {
|
|
public class ShmupPlayer {
|
|
public TextureRef Texture = Textures.Yellow2;
|
|
// Center of player sprite.
|
|
public Vector2 Position = new Vector2(48, 1080 / 8);
|
|
public Vector2 HalfSize = new Vector2(16, 10);
|
|
public float Speed = 150f;
|
|
}
|
|
|
|
public class Shot {
|
|
public TextureRef Texture = Textures.Projectile1;
|
|
public Vector2 Position;
|
|
public Vector2 HalfSize = new Vector2(11, 8);
|
|
public Vector2 Velocity;
|
|
public Shot(Vector2 position, Vector2 velocity) {
|
|
Position = position;
|
|
Velocity = velocity;
|
|
}
|
|
}
|
|
|
|
public readonly Point Size;
|
|
public readonly ShmupPlayer Player;
|
|
public readonly ProfilingList<Shot> Shots;
|
|
|
|
public ShmupWorld() {
|
|
Size = new Point(1920 / 4, 1080 / 4);
|
|
Player = new ShmupPlayer();
|
|
Shots = new ProfilingList<Shot>(100, "shots");
|
|
Vector2 velocity = new Vector2(100, 0);
|
|
Shots.Add(new Shot(new Vector2(96, 1080 / 8), velocity));
|
|
Shots.Add(new Shot(new Vector2(96 * 2, 1080 / 8), velocity));
|
|
Shots.Add(new Shot(new Vector2(96 * 4, 1080 / 8), velocity));
|
|
}
|
|
|
|
~ShmupWorld() {
|
|
Dispose();
|
|
}
|
|
|
|
public void Dispose() {
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
public void Update(float modelTime, History<Input> input) {
|
|
Vector2 motion = Vector2.Multiply(input[0].Motion, modelTime * Player.Speed);
|
|
Player.Position = Vector2.Add(Player.Position, motion);
|
|
Player.Position.X = Math.Max(Player.Position.X, Player.HalfSize.X);
|
|
Player.Position.X = Math.Min(Player.Position.X, Size.X - Player.HalfSize.X);
|
|
Player.Position.Y = Math.Max(Player.Position.Y, Player.HalfSize.Y);
|
|
Player.Position.Y = Math.Min(Player.Position.Y, Size.Y - Player.HalfSize.Y);
|
|
|
|
foreach (Shot shot in Shots) {
|
|
shot.Position = Vector2.Add(shot.Position, Vector2.Multiply(shot.Velocity, modelTime));
|
|
shot.Position.X = Math.Max(shot.Position.X, shot.HalfSize.X);
|
|
shot.Position.X = Math.Min(shot.Position.X, Size.X - shot.HalfSize.X);
|
|
shot.Position.X = Math.Max(shot.Position.X, shot.HalfSize.X);
|
|
shot.Position.X = Math.Min(shot.Position.X, Size.X - shot.HalfSize.X);
|
|
}
|
|
|
|
// Shots.RemoveAll(shot => shot.Position.X > Size.X);
|
|
}
|
|
}
|
|
}
|