mv World & Scene to SneakWorld & SneakScene.
This commit is contained in:
parent
56bc1abe06
commit
987c86fae9
@ -7,7 +7,7 @@ namespace SemiColinGames {
|
|||||||
public void Enter();
|
public void Enter();
|
||||||
|
|
||||||
// Returns the name of the new state, or null if we should stay in the same state.
|
// 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> {
|
public class FSM<T> {
|
||||||
@ -23,7 +23,7 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
public IState<T> State { get; private set; }
|
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);
|
string newState = State.Update(modelTime, world, input);
|
||||||
if (newState != null) {
|
if (newState != null) {
|
||||||
Transition(newState);
|
Transition(newState);
|
||||||
|
@ -16,7 +16,7 @@ namespace SemiColinGames {
|
|||||||
timeInState = 0;
|
timeInState = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Update(float modelTime, World world, Object _) {
|
public string Update(float modelTime, SneakWorld world, Object _) {
|
||||||
timeInState += modelTime;
|
timeInState += modelTime;
|
||||||
if (timeInState > 1.0f) {
|
if (timeInState > 1.0f) {
|
||||||
npc.Facing *= -1;
|
npc.Facing *= -1;
|
||||||
@ -35,7 +35,7 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
public void Enter() {}
|
public void Enter() {}
|
||||||
|
|
||||||
public string Update(float modelTime, World world, Object _) {
|
public string Update(float modelTime, SneakWorld world, Object _) {
|
||||||
float moveSpeed = 120;
|
float moveSpeed = 120;
|
||||||
float desiredX = npc.Position.X + moveSpeed * npc.Facing * modelTime;
|
float desiredX = npc.Position.X + moveSpeed * npc.Facing * modelTime;
|
||||||
float testPoint = desiredX + npc.Box.HalfSize.X * npc.Facing;
|
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);
|
fsm.Update(modelTime, world, null);
|
||||||
Box = new AABB(Position, halfSize);
|
Box = new AABB(Position, halfSize);
|
||||||
Debug.AddRect(Box, Color.White);
|
Debug.AddRect(Box, Color.White);
|
||||||
|
@ -24,7 +24,7 @@ namespace SemiColinGames {
|
|||||||
public void Enter() {
|
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() {
|
result = new Vector2() {
|
||||||
X = input[0].Motion.X * moveSpeed * modelTime
|
X = input[0].Motion.X * moveSpeed * modelTime
|
||||||
};
|
};
|
||||||
@ -120,7 +120,7 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
public Vector2 Position { get { return position; } }
|
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) {
|
AABB BoxOffset(Vector2 position, int yOffset) {
|
||||||
return new AABB(new Vector2(position.X, position.Y + yOffset), halfSize);
|
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.
|
// 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);
|
fsm.Update(modelTime, world, input);
|
||||||
// TODO: remove ugly cast.
|
// TODO: remove ugly cast.
|
||||||
return ((IPlayerState) fsm.State).Movement;
|
return ((IPlayerState) fsm.State).Movement;
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)IWorld.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)IWorld.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)NPC.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)NPC.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ProfilingList.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ProfilingList.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)SneakScene.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)SneakWorld.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)SoundEffects.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)SoundEffects.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Sprites.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Sprites.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Strings.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Strings.cs" />
|
||||||
@ -31,11 +33,9 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Line.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Line.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)LinesOfSight.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)LinesOfSight.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Player.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Player.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Scene.cs" />
|
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)SneakGame.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)SneakGame.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Timer.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Timer.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)TreeScene.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)TreeScene.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)TreeWorld.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)TreeWorld.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)World.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -64,11 +64,11 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
private void LoadLevel() {
|
private void LoadLevel() {
|
||||||
world?.Dispose();
|
world?.Dispose();
|
||||||
// world = new World(GraphicsDevice, Content.LoadString("levels/demo.json"));
|
world = new SneakWorld(GraphicsDevice, Content.LoadString("levels/demo.json"));
|
||||||
world = new TreeWorld();
|
// world = new TreeWorld();
|
||||||
scene?.Dispose();
|
scene?.Dispose();
|
||||||
// scene = new Scene(GraphicsDevice, ((World) world).Camera);
|
scene = new SneakScene(GraphicsDevice, ((SneakWorld) world).Camera);
|
||||||
scene = new TreeScene(GraphicsDevice);
|
// scene = new TreeScene(GraphicsDevice);
|
||||||
|
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
GC.WaitForPendingFinalizers();
|
GC.WaitForPendingFinalizers();
|
||||||
|
@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public sealed class Scene : IScene {
|
public sealed class SneakScene : IScene {
|
||||||
const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f;
|
const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f;
|
||||||
|
|
||||||
private readonly Color backgroundColor = Color.CornflowerBlue;
|
private readonly Color backgroundColor = Color.CornflowerBlue;
|
||||||
@ -22,7 +22,7 @@ namespace SemiColinGames {
|
|||||||
// frames can be really slow to draw.
|
// frames can be really slow to draw.
|
||||||
private int framesToSuppress = 2;
|
private int framesToSuppress = 2;
|
||||||
|
|
||||||
public Scene(GraphicsDevice graphics, Camera camera) {
|
public SneakScene(GraphicsDevice graphics, Camera camera) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ namespace SemiColinGames {
|
|||||||
music.Volume = 0.1f;
|
music.Volume = 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Scene() {
|
~SneakScene() {
|
||||||
Dispose();
|
Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ namespace SemiColinGames {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) {
|
public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) {
|
||||||
World world = (World) iworld;
|
SneakWorld world = (SneakWorld) iworld;
|
||||||
graphics.SetRenderTarget(null);
|
graphics.SetRenderTarget(null);
|
||||||
graphics.Clear(backgroundColor);
|
graphics.Clear(backgroundColor);
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
|
|
||||||
public sealed class World : IWorld {
|
public sealed class SneakWorld : IWorld {
|
||||||
|
|
||||||
// Size of World in terms of tile grid.
|
// Size of World in terms of tile grid.
|
||||||
private int gridWidth;
|
private int gridWidth;
|
||||||
@ -27,7 +27,7 @@ namespace SemiColinGames {
|
|||||||
public readonly int Height;
|
public readonly int Height;
|
||||||
|
|
||||||
// TODO: it seems weird that World takes in a GraphicsDevice. Remove it?
|
// 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();
|
Camera = new Camera();
|
||||||
LinesOfSight = new LinesOfSight(graphics);
|
LinesOfSight = new LinesOfSight(graphics);
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ namespace SemiColinGames {
|
|||||||
new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue));
|
new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
~World() {
|
~SneakWorld() {
|
||||||
Dispose();
|
Dispose();
|
||||||
}
|
}
|
||||||
|
|
@ -14,6 +14,10 @@ namespace SemiColinGames {
|
|||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~TreeScene() {
|
||||||
|
Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,13 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
public sealed class TreeWorld : IWorld {
|
public sealed class TreeWorld : IWorld {
|
||||||
|
public TreeWorld() {
|
||||||
|
}
|
||||||
|
|
||||||
|
~TreeWorld() {
|
||||||
|
Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user