public void Draw(Graphics g, View view, World world, float delta) { Chunk cUp = world.GetChunk(this.x, this.y - 1); Chunk cDown = world.GetChunk(this.x, this.y + 1); Chunk cLeft = world.GetChunk(this.x - 1, this.y); Chunk cRight = world.GetChunk(this.x + 1, this.y); int X = this.x * Chunk.size; int Y = this.y * Chunk.size; for (int y = 0; y < Chunk.size; y++) { for (int x = 0; x < Chunk.size; x++) { int up = (y > 0 ? this.tiles[this.ToIndex(x, y - 1)] : (cUp == null ? 0 : cUp.GetTile(x, y - 1))); int down = (y < Chunk.size - 1 ? this.tiles[this.ToIndex(x, y + 1)] : (cDown == null ? 0 : cDown.GetTile(x, y + 1))); int left = (x > 0 ? this.tiles[this.ToIndex(x - 1, y)] : (cLeft == null ? 0 : cLeft.GetTile(x - 1, y))); int right = (x < Chunk.size - 1 ? this.tiles[this.ToIndex(x + 1, y)] : (cRight == null ? 0 : cRight.GetTile(x + 1, y))); Tile.GetTile(this.tiles[this.ToIndex(x, y)]).Draw(g, view, world, X + x, Y + y, up, down, left, right); } } }
public void CheckEntityPosition(World world) { List<Entity> remove = new List<Entity>(); foreach (Entity entity in this.entities) { int x = (int)Math.Floor((double)entity.X / (double)Chunk.size); int y = (int)Math.Floor((double)entity.Y / (double)Chunk.size); if (this.x != x || this.y != y) { Chunk chunk = world.GetChunk(x, y); if (chunk != null) { remove.Add(entity); chunk.AddEntity(entity); } } } foreach (Entity entity in remove) { this.entities.Remove(entity); } }