diff --git a/Shared/NPC.cs b/Shared/NPC.cs
index bbf6d66..cbca207 100644
--- a/Shared/NPC.cs
+++ b/Shared/NPC.cs
@@ -15,14 +15,24 @@ namespace SemiColinGames {
public int Facing { get; private set; } = 1;
- public void Update(float modelTime) {
- if (Facing == 1 && position.X > 16 * 39) {
- Facing = -1;
+ public void Update(float modelTime, AABB[] collisionTargets) {
+ int moveSpeed = 120;
+ int desiredX = position.X + (int) (moveSpeed * Facing * modelTime);
+ // TODO: define the box modularly & correctly.
+ AABB npcBox = new AABB(new Vector2(desiredX, position.Y), new Vector2(11, 33));
+ Debug.AddRect(npcBox, Color.Cyan);
+ bool foundBox = false;
+ foreach (AABB box in collisionTargets) {
+ if (box.Intersect(npcBox) != null) {
+ foundBox = true;
+ break;
+ }
}
- if (Facing == -1 && position.X < 16 * 24) {
- Facing = 1;
+
+ if (!foundBox) {
+ Facing *= -1;
}
- position.X += (int) (120 * Facing * modelTime);
+ position.X = desiredX;
}
public void Draw(SpriteBatch spriteBatch) {
diff --git a/Shared/Player.cs b/Shared/Player.cs
index 7f0f438..2591abb 100644
--- a/Shared/Player.cs
+++ b/Shared/Player.cs
@@ -48,7 +48,7 @@ namespace SemiColinGames {
public Point Position { get { return position; } }
- public void Update(float modelTime, History input, AABB[] collisionTargets) {
+ public void Update(float modelTime, AABB[] collisionTargets, History input) {
AABB BoxOffset(Point position, int yOffset) {
return new AABB(new Vector2(position.X, position.Y + yOffset), halfSize);
}
diff --git a/Shared/World.cs b/Shared/World.cs
index 1a8704c..d752231 100644
--- a/Shared/World.cs
+++ b/Shared/World.cs
@@ -90,7 +90,7 @@ namespace SemiColinGames {
public const int TileSize = 16;
readonly Tile[] tiles;
readonly Tile[] decorations;
- readonly NPC[] npcs = new NPC[1];
+ readonly NPC[] npcs = new NPC[4];
// Size of World in terms of tile grid.
private readonly int tileWidth;
@@ -109,7 +109,11 @@ namespace SemiColinGames {
public World(string levelSpecification) {
Player = new Player();
- npcs[0] = new NPC(new Point(16 * 38, 16 * 12));
+ npcs[0] = new NPC(new Point(16 * 8, 16 * 6));
+ npcs[1] = new NPC(new Point(16 * 28, 16 * 6));
+ npcs[2] = new NPC(new Point(16 * 36, 16 * 6));
+ npcs[3] = new NPC(new Point(16 * 36, 16 * 12));
+
var tilesList = new List();
var decorationsList = new List();
string[] worldDesc = levelSpecification.Substring(1).Split('\n');
@@ -158,9 +162,9 @@ namespace SemiColinGames {
}
public void Update(float modelTime, History input) {
- Player.Update(modelTime, input, CollisionTargets);
+ Player.Update(modelTime, CollisionTargets, input);
foreach (NPC npc in npcs) {
- npc.Update(modelTime);
+ npc.Update(modelTime, CollisionTargets);
}
if (Player.Health <= 0) {
Reset();