-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
240 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using BigWorld.Map; | ||
using engenious; | ||
|
||
namespace BigWorld | ||
{ | ||
public abstract class Entity | ||
{ | ||
public Vector2 CmdMoveDirection { get; set; } | ||
|
||
public Point CurrentRoom { get; set; } | ||
public Vector2 RoomPosition { get; set; } | ||
|
||
public virtual void Update(GameTime gameTime) | ||
{ | ||
RoomPosition = RoomPosition + CmdMoveDirection * (float)gameTime.ElapsedGameTime.TotalSeconds * 4; | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace BigWorld | ||
{ | ||
public class Player :Entity | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using BigWorld.Map; | ||
using engenious; | ||
|
||
namespace BigWorld.Services | ||
{ | ||
public abstract class BaseService | ||
{ | ||
public abstract void Update(Entity entity,World world, GameTime gameTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Runtime.ExceptionServices; | ||
using BigWorld.Map; | ||
using engenious; | ||
|
||
namespace BigWorld.Services | ||
{ | ||
public class BlockCollisionService : BaseService | ||
{ | ||
public override void Update(Entity entity, World world, GameTime gameTime) | ||
{ | ||
Room room; | ||
if (!world.TryGetRoom(entity.CurrentRoom,out room)) | ||
return; | ||
|
||
foreach (var value in room.BlockLayer.GetPositivValues()) | ||
{ | ||
if (value.Value) | ||
{ | ||
var distance = entity.RoomPosition - value.Key.ToVector2(); | ||
|
||
if ((distance.X > -1 && distance.X < 1) && (distance.Y > -1 && distance.Y < 1)) | ||
{ | ||
float x = distance.X < 0 ? distance.X : 1 - distance.X; | ||
float y = distance.Y < 0 ? 1 + distance.Y : 1 - distance.Y; | ||
|
||
var corr = new Vector2(x, y); | ||
entity.RoomPosition += corr; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using BigWorld.Map; | ||
using engenious; | ||
|
||
namespace BigWorld.Services | ||
{ | ||
public class RoomCollisionService : BaseService | ||
{ | ||
public override void Update(Entity entity, World world, GameTime gameTime) | ||
{ | ||
if (entity.RoomPosition.X < 0) | ||
{ | ||
entity.RoomPosition = new Vector2(0,entity.RoomPosition.Y); | ||
} | ||
else if (entity.RoomPosition.X > Room.SizeX -1) | ||
{ | ||
entity.RoomPosition = new Vector2(Room.SizeX -1,entity.RoomPosition.Y); | ||
} | ||
|
||
if (entity.RoomPosition.Y < 0) | ||
{ | ||
entity.RoomPosition = new Vector2(entity.RoomPosition.X,0); | ||
} | ||
else if (entity.RoomPosition.Y > Room.SizeY -1) | ||
{ | ||
entity.RoomPosition = new Vector2(entity.RoomPosition.X,Room.SizeY -1); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections.Generic; | ||
using BigWorld.Map; | ||
using BigWorld.Services; | ||
using engenious; | ||
|
||
namespace BigWorld | ||
{ | ||
public class Simulation | ||
{ | ||
public World CurrentWorld { get; private set; } | ||
|
||
public bool IsRunning { get; private set; } | ||
|
||
private readonly List<Entity> entities = new List<Entity>(); | ||
public IEnumerable<Entity> Entities => entities; | ||
|
||
private readonly List<BaseService> services = new List<BaseService>() | ||
{ | ||
new RoomCollisionService(), | ||
new BlockCollisionService(), | ||
}; | ||
|
||
public void Start(World world) | ||
{ | ||
CurrentWorld = world ; | ||
entities.Clear(); | ||
|
||
|
||
IsRunning = true; | ||
} | ||
|
||
public Player AddPlayer() | ||
{ | ||
Player player = new Player(); | ||
|
||
entities.Add(player); | ||
|
||
return player; | ||
} | ||
|
||
public void Stop() | ||
{ | ||
IsRunning = false; | ||
} | ||
|
||
public void Update(GameTime gameTime) | ||
{ | ||
if(!IsRunning) | ||
return; | ||
|
||
foreach (var entity in entities) | ||
{ | ||
entity.Update(gameTime); | ||
foreach (var service in services) | ||
{ | ||
service.Update(entity,CurrentWorld,gameTime); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.