public void RemoveStructure(Vector2 position) { Structure structure = Structures.FirstOrDefault(x => x.Position == position); Structures.Remove(structure); if (CollisionPositions.Contains(position)) { CollisionPositions.Remove(position); } if (FlooringPositions.Contains(position)) { FlooringPositions.Remove(position); } }
public void AddStructure(Vector2 position, string type) { if (type == "wall") { Structures.Add(new Structure(position, content.Load <Texture2D>("wall"), "wall")); CollisionPositions.Add(position); } if (type == "wall2") { Structures.Add(new Structure(position, content.Load <Texture2D>("wall2"), "wall2")); CollisionPositions.Add(position); } if (type == "wall3") { Structures.Add(new Structure(position, content.Load <Texture2D>("wall3"), "wall3")); CollisionPositions.Add(position); } if (type == "sandstonebasewall") { Structures.Add(new Structure(position, content.Load <Texture2D>("sandstonebasewall"), "sandstonebasewall")); CollisionPositions.Add(position); } if (type == "door") { Structures.Add(new Structure(position, content.Load <Texture2D>("sandstonedoorway"), "door")); } if (type == "flooring") { Structures.Add(new Structure(position, content.Load <Texture2D>("sandstonefloor"), "flooring")); FlooringPositions.Add(position); } }
public void GiveOrders(GameTime gameTime) { mousePreviousState = Mouse.GetState(); mouseNewState = mousePreviousState; var mstate = Mouse.GetState(); foreach (var aiUnit in AiUnits) { bool collision; if (CollisionPositions.Contains(camera.GetNearestGrid32(camera.GetMapCords(), 32)) || aiUnit.Position == camera.GetNearestGrid32(camera.GetMapCords(), 32)) { collision = true; } else { collision = false; } if (aiUnit.Selected && mstate.RightButton == ButtonState.Pressed) { if (aiUnit.CurrentWaypoint == null || aiUnit.CurrentWaypoint.PathActive == false) { if (collision == false) { aiUnit.IsMoving = true; aiUnit.Destination = camera.GetNearestGrid32(camera.GetMapCords(), 32); aiUnit.CurrentWaypoint = new WayPoint(grid, game, aiUnit); } } } if (aiUnit.IsMoving) { if (!collision && aiUnit.Selected && mstate.RightButton == ButtonState.Pressed && !aiUnit.Interrupt) { aiUnit.Interrupt = true; } if (aiUnit.Interrupt && mstate.RightButton == ButtonState.Released) { aiUnit.Position = MoveToThisPos(aiUnit.Position, aiUnit.CurrentWaypoint.CurrentPos, gameTime, aiUnit.Speed); if (Vector2.Distance(aiUnit.Position, aiUnit.CurrentWaypoint.CurrentPos) < 1) { aiUnit.Position = aiUnit.CurrentWaypoint.CurrentPos; aiUnit.IsMoving = true; aiUnit.Destination = camera.GetNearestGrid32(camera.GetMapCords(), 32); aiUnit.CurrentWaypoint = new WayPoint(grid, game, aiUnit); aiUnit.Interrupt = false; } } else { aiUnit.Position = MoveToThisPos(aiUnit.Position, aiUnit.CurrentWaypoint.CurrentPos, gameTime, aiUnit.Speed); if (Vector2.Distance(aiUnit.Position, aiUnit.CurrentWaypoint.CurrentPos) < 1) { aiUnit.Position = aiUnit.CurrentWaypoint.CurrentPos; if (aiUnit.CurrentWaypoint.X < aiUnit.CurrentWaypoint.Paths.Count() - 1) { aiUnit.CurrentWaypoint.X += 1; } aiUnit.CurrentWaypoint.CurrentPos = aiUnit.CurrentWaypoint.Paths[aiUnit.CurrentWaypoint.X]; } if (Vector2.Distance(aiUnit.Position, aiUnit.CurrentWaypoint.Paths.Last()) < 1) { aiUnit.Position = aiUnit.CurrentWaypoint.Paths.Last(); aiUnit.IsMoving = false; aiUnit.CurrentWaypoint.PathActive = false; } } } } }