diff --git a/Shared/NPC.cs b/Shared/NPC.cs index 0d5a254..d7af36f 100644 --- a/Shared/NPC.cs +++ b/Shared/NPC.cs @@ -1,7 +1,5 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using System; -using System.Collections.Generic; namespace SemiColinGames { class NPC { diff --git a/Shared/Scene.cs b/Shared/Scene.cs index faaaad0..109764b 100644 --- a/Shared/Scene.cs +++ b/Shared/Scene.cs @@ -56,8 +56,7 @@ namespace SemiColinGames { GC.SuppressFinalize(this); } - public void Draw( - bool isRunningSlowly, World world, Player player, LinesOfSight linesOfSight, bool paused) { + public void Draw(bool isRunningSlowly, World world, LinesOfSight linesOfSight, bool paused) { graphics.SetRenderTarget(null); graphics.Clear(backgroundColor); @@ -100,7 +99,7 @@ namespace SemiColinGames { world.DrawBackground(spriteBatch); // Draw player. - player.Draw(spriteBatch); + world.Player.Draw(spriteBatch); // Draw foreground tiles. world.DrawForeground(spriteBatch); @@ -112,9 +111,9 @@ namespace SemiColinGames { // Draw in-world UI on top of everything. spriteBatch.Begin( SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null); - for (int i = 0; i < player.MaxHealth; i++) { + for (int i = 0; i < world.Player.MaxHealth; i++) { Vector2 pos = new Vector2(16 + 15 * i, 8); - if (player.Health > i) { + if (world.Player.Health > i) { spriteBatch.Draw(Textures.Heart.Get, pos, new Rectangle(0, 0, 16, 16), Color.White); } else { spriteBatch.Draw(Textures.Heart.Get, pos, new Rectangle(16, 0, 16, 16), Color.White); diff --git a/Shared/SneakGame.cs b/Shared/SneakGame.cs index 9515d29..52f9314 100644 --- a/Shared/SneakGame.cs +++ b/Shared/SneakGame.cs @@ -23,7 +23,6 @@ namespace SemiColinGames { int levelIdx = -1; Scene scene; - Player player; World world; LinesOfSight linesOfSight; Camera camera = new Camera(); @@ -68,7 +67,6 @@ namespace SemiColinGames { private void LoadLevel() { camera = new Camera(); - player = new Player(); levelIdx++; world = new World(Levels.ALL_LEVELS[levelIdx % Levels.ALL_LEVELS.Length]); scene?.Dispose(); @@ -115,14 +113,9 @@ namespace SemiColinGames { if (!paused) { float modelTime = (float) gameTime.ElapsedGameTime.TotalSeconds; Clock.AddModelTime(modelTime); - player.Update(modelTime, input, world.CollisionTargets); - world.Update(modelTime); - linesOfSight.Update(player, world.CollisionTargets); - camera.Update(player.Position, world.Width); - if (player.Health <= 0) { - world = new World(Levels.ALL_LEVELS[levelIdx % Levels.ALL_LEVELS.Length]); - player = new Player(); - } + world.Update(modelTime, input); + linesOfSight.Update(world.Player, world.CollisionTargets); + camera.Update(world.Player.Position, world.Width); } base.Update(gameTime); @@ -144,7 +137,7 @@ namespace SemiColinGames { Debug.SetFpsText(fpsText); - scene.Draw(gameTime.IsRunningSlowly, world, player, linesOfSight, paused); + scene.Draw(gameTime.IsRunningSlowly, world, linesOfSight, paused); base.Draw(gameTime); drawTimer.Stop(); diff --git a/Shared/World.cs b/Shared/World.cs index 6e20cdc..0f9ccd2 100644 --- a/Shared/World.cs +++ b/Shared/World.cs @@ -91,12 +91,17 @@ namespace SemiColinGames { readonly Tile[] tiles; readonly Tile[] decorations; + Player player; readonly NPC[] npcs = new NPC[1]; // Size of World in terms of tile grid. private readonly int tileWidth; private readonly int tileHeight; + public Player Player { + get { return player; } + } + // Size of World in pixels. public int Width { get { return tileWidth * TileSize; } @@ -107,6 +112,7 @@ namespace SemiColinGames { } public World(string levelSpecification) { + player = new Player(); npcs[0] = new NPC(new Point(16 * 38, 16 * 12)); var tilesList = new List(); var decorationsList = new List(); @@ -155,10 +161,18 @@ namespace SemiColinGames { new Vector2(Width + 1, 0), new Vector2(1, float.MaxValue)); } - public void Update(float modelTime) { + public void Update(float modelTime, History input) { + player.Update(modelTime, input, CollisionTargets); foreach (NPC npc in npcs) { npc.Update(modelTime); } + if (player.Health <= 0) { + Reset(); + } + } + + void Reset() { + player = new Player(); } public void DrawBackground(SpriteBatch spriteBatch) {