public void CreateEmptyMap(int width, int height) { AppFramework.PhysicsSimulator.Clear(); this.width = width; this.height = height; map = new Tile[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Vector2 size = new Vector2(Tile.Width, Tile.Height); Vector2 position = new Vector2(x * size.X, y * size.Y); map[y * width + x] = new Tile(0, position, size, 0, x, y); if (y * width + x < 16) { startPositions[y * width + x] = map[y * width + x]; } else if (y * width + x > 32) { endPositions[y * width + x - 16] = map[y * width + x]; } } } }
private void UpdateClick(GameTime gameTime) { if (Mouse.GetState().LeftButton == ButtonState.Pressed) { Vector2 position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); Tile tile = map.GetTileForPosition(position + camera.TopLeft); if (tile != tile_changed_last_frame) { mouse_not_down_last_frame = true; } if (mouse_not_down_last_frame && tile != null) { tile.type += 1; if (tile.type == TileType.NumberOfTypes) { tile.type = TileType.Empty; } tile_changed_last_frame = tile; } mouse_not_down_last_frame = false; } else if (Mouse.GetState().RightButton == ButtonState.Pressed) { Vector2 position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); Tile tile = map.GetTileForPosition(position + camera.TopLeft); if (tile != tile_changed_last_frame) { mouse_not_down_last_frame = true; } if (mouse_not_down_last_frame && tile != null) { if (tile.type != TileType.End && tile.type != TileType.Start) { tile.type = TileType.Start; tile.player = 0; } else { tile.player += 1; tile.player %= 16; } tile_changed_last_frame = tile; } mouse_not_down_last_frame = false; } else { mouse_not_down_last_frame = true; tile_changed_last_frame = null; } previousMouseState = Mouse.GetState(); }
public void LoadMap(Map newMap) { width = newMap.width; height = newMap.height; startPositions = new Dictionary<int, Tile>(); map = new Tile[width * height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { map[y * width + x] = new Tile(newMap.map[y * width + x].type, newMap.map[y * width + x].position, newMap.map[y * width + x].size, newMap.map[y * width + x].player, x, y); if (map[y * width + x].type == TileType.Start) { if (!startPositions.ContainsKey(map[y * width + x].player)) { startPositions[map[y * width + x].player] = map[y * width + x]; } } if (map[y * width + x].type == TileType.End) { if (!endPositions.ContainsKey(map[y * width + x].player)) { endPositions[map[y * width + x].player] = map[y * width + x]; } } map[y * width + x].InitialisePhysics(); } } }
private bool CollideWithTile(Tile tile) { switch (tile.type) { case TileType.Filled: return true; case TileType.Empty: case TileType.Start: return false; case TileType.End: if (tile.player == player && state == State.Playing) state = State.Finished; return false; default: return true; } }