mv World & Scene to SneakWorld & SneakScene.

This commit is contained in:
Colin McMillen 2020-07-15 15:17:19 -04:00
parent 56bc1abe06
commit 987c86fae9
9 changed files with 32 additions and 21 deletions

View File

@ -7,7 +7,7 @@ namespace SemiColinGames {
public void Enter();
// Returns the name of the new state, or null if we should stay in the same state.
public string Update(float modelTime, World world, T input);
public string Update(float modelTime, SneakWorld world, T input);
}
public class FSM<T> {
@ -23,7 +23,7 @@ namespace SemiColinGames {
public IState<T> State { get; private set; }
public void Update(float modelTime, World world, T input) {
public void Update(float modelTime, SneakWorld world, T input) {
string newState = State.Update(modelTime, world, input);
if (newState != null) {
Transition(newState);

View File

@ -16,7 +16,7 @@ namespace SemiColinGames {
timeInState = 0;
}
public string Update(float modelTime, World world, Object _) {
public string Update(float modelTime, SneakWorld world, Object _) {
timeInState += modelTime;
if (timeInState > 1.0f) {
npc.Facing *= -1;
@ -35,7 +35,7 @@ namespace SemiColinGames {
public void Enter() {}
public string Update(float modelTime, World world, Object _) {
public string Update(float modelTime, SneakWorld world, Object _) {
float moveSpeed = 120;
float desiredX = npc.Position.X + moveSpeed * npc.Facing * modelTime;
float testPoint = desiredX + npc.Box.HalfSize.X * npc.Facing;
@ -110,7 +110,7 @@ namespace SemiColinGames {
}
}
public void Update(float modelTime, World world) {
public void Update(float modelTime, SneakWorld world) {
fsm.Update(modelTime, world, null);
Box = new AABB(Position, halfSize);
Debug.AddRect(Box, Color.White);

View File

@ -24,7 +24,7 @@ namespace SemiColinGames {
public void Enter() {
}
public string Update(float modelTime, World world, History<Input> input) {
public string Update(float modelTime, SneakWorld world, History<Input> input) {
result = new Vector2() {
X = input[0].Motion.X * moveSpeed * modelTime
};
@ -120,7 +120,7 @@ namespace SemiColinGames {
public Vector2 Position { get { return position; } }
public void Update(float modelTime, World world, History<Input> input) {
public void Update(float modelTime, SneakWorld world, History<Input> input) {
AABB BoxOffset(Vector2 position, int yOffset) {
return new AABB(new Vector2(position.X, position.Y + yOffset), halfSize);
}
@ -224,7 +224,7 @@ namespace SemiColinGames {
}
// Returns the desired (dx, dy) for the player to move this frame.
Vector2 HandleInput(float modelTime, World world, History<Input> input) {
Vector2 HandleInput(float modelTime, SneakWorld world, History<Input> input) {
fsm.Update(modelTime, world, input);
// TODO: remove ugly cast.
return ((IPlayerState) fsm.State).Movement;

View File

@ -16,6 +16,8 @@
<Compile Include="$(MSBuildThisFileDirectory)IWorld.cs" />
<Compile Include="$(MSBuildThisFileDirectory)NPC.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProfilingList.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SneakScene.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SneakWorld.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SoundEffects.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Sprites.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Strings.cs" />
@ -31,11 +33,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Line.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LinesOfSight.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Player.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Scene.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SneakGame.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Timer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TreeScene.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TreeWorld.cs" />
<Compile Include="$(MSBuildThisFileDirectory)World.cs" />
</ItemGroup>
</Project>

View File

@ -64,11 +64,11 @@ namespace SemiColinGames {
private void LoadLevel() {
world?.Dispose();
// world = new World(GraphicsDevice, Content.LoadString("levels/demo.json"));
world = new TreeWorld();
world = new SneakWorld(GraphicsDevice, Content.LoadString("levels/demo.json"));
// world = new TreeWorld();
scene?.Dispose();
// scene = new Scene(GraphicsDevice, ((World) world).Camera);
scene = new TreeScene(GraphicsDevice);
scene = new SneakScene(GraphicsDevice, ((SneakWorld) world).Camera);
// scene = new TreeScene(GraphicsDevice);
GC.Collect();
GC.WaitForPendingFinalizers();

View File

@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
using System;
namespace SemiColinGames {
public sealed class Scene : IScene {
public sealed class SneakScene : IScene {
const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f;
private readonly Color backgroundColor = Color.CornflowerBlue;
@ -22,7 +22,7 @@ namespace SemiColinGames {
// frames can be really slow to draw.
private int framesToSuppress = 2;
public Scene(GraphicsDevice graphics, Camera camera) {
public SneakScene(GraphicsDevice graphics, Camera camera) {
this.graphics = graphics;
this.camera = camera;
@ -43,7 +43,7 @@ namespace SemiColinGames {
music.Volume = 0.1f;
}
~Scene() {
~SneakScene() {
Dispose();
}
@ -57,7 +57,7 @@ namespace SemiColinGames {
}
public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) {
World world = (World) iworld;
SneakWorld world = (SneakWorld) iworld;
graphics.SetRenderTarget(null);
graphics.Clear(backgroundColor);

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace SemiColinGames {
public sealed class World : IWorld {
public sealed class SneakWorld : IWorld {
// Size of World in terms of tile grid.
private int gridWidth;
@ -27,7 +27,7 @@ namespace SemiColinGames {
public readonly int Height;
// TODO: it seems weird that World takes in a GraphicsDevice. Remove it?
public World(GraphicsDevice graphics, string json) {
public SneakWorld(GraphicsDevice graphics, string json) {
Camera = new Camera();
LinesOfSight = new LinesOfSight(graphics);
@ -90,7 +90,7 @@ namespace SemiColinGames {
new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue));
}
~World() {
~SneakWorld() {
Dispose();
}

View File

@ -14,6 +14,10 @@ namespace SemiColinGames {
this.graphics = graphics;
}
~TreeScene() {
Dispose();
}
public void Dispose() {
GC.SuppressFinalize(this);
}

View File

@ -5,6 +5,13 @@ using System.Collections.Generic;
namespace SemiColinGames {
public sealed class TreeWorld : IWorld {
public TreeWorld() {
}
~TreeWorld() {
Dispose();
}
public void Dispose() {
GC.SuppressFinalize(this);
}