public void generate(World world, int xPos, int yPos) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (world.getTile(xPos + x, yPos + y) != null && !shouldReplaceTiles) { break; } world.setTile(tiles[x + y * width], xPos + x, yPos + y); } } }
public override Boolean move(World world, int xMove, int yMove) { int xAfterMove = bounds.X + xMove; int yAfterMove = bounds.Y + yMove; int widthInTiles = bounds.Width / Tile.Tile_Width + 2; int heightInTiles = bounds.Height / Tile.Tile_Width + 2; int xPosInTiles = xAfterMove / Tile.Tile_Width - 1; int yPosInTiles = yAfterMove / Tile.Tile_Width - 1; Boolean hasCollided = false; for (int x = xPosInTiles; x < xPosInTiles + widthInTiles; x++) { for (int y = yPosInTiles; y < yPosInTiles + heightInTiles; y++) { Tile tile = world.getTile(x, y); if (tile != null && tile.isSolid) { Rectangle boundsAfterMovement = new Rectangle(xAfterMove, yAfterMove, bounds.Width, bounds.Height); Rectangle tileRect = new Rectangle(x * Tile.Tile_Width, y * Tile.Tile_Width, Tile.Tile_Width, Tile.Tile_Width); if (tileRect.Intersects(boundsAfterMovement)) { hasCollided = true; onCollision(); return true; } } } } if (!hasCollided) { bounds.X = xAfterMove; bounds.Y = yAfterMove; } //TODO Fix this LATER /* if(xMove <= 5 && xMove >= -5 && yMove <= 5 && yMove >= -5) { Boolean isMovingOnX = true; Boolean isMovingOnY = true; if (xMove == 0) { isMovingOnX = false; } if (yMove == 0) { isMovingOnY = false; } int newXMove = xMove - 1; int newYMove = yMove - 1; if (xMove < 0) { newXMove += 2; } if (yMove < 0) { newYMove += 2; } if (!isMovingOnX) { newXMove = 0; } if (!isMovingOnY) { newYMove = 0; } move(world, newXMove, newYMove); } */ return false; }
public override void tick(World world, int xPos, int yPos) { Random chance = new Random(); if (world.getTile(xPos, yPos - 1) != null) { if (chance.Next(800) == 0) { world.setTile(new TileDirt(), xPos, yPos); } } else { /* * A B * CXD * E F */ //ABCDEF are tiles being checked. X is the grass bloc Random random = new Random(); //A { int x = xPos - 1; int y = yPos - 1; if (world.getTile(x, y) != null && world.getTile(x, y).ID == 1) { if (world.getTile(x, y - 1) == null || world.getTile(x, y - 1).isTransparent) { if (random.Next(1000) == 0) { world.setTile(new TileGrass(), x, y); } } } } //B { int x = xPos + 1; int y = yPos - 1; if (world.getTile(x, y) != null && world.getTile(x, y).ID == 1) { if (world.getTile(x, y - 1) == null || world.getTile(x, y - 1).isTransparent) { if (random.Next(1000) == 0) { world.setTile(new TileGrass(), x, y); } } } } //C { int x = xPos - 1; int y = yPos; if (world.getTile(x, y) != null && world.getTile(x, y).ID == 1) { if (world.getTile(x, y - 1) == null || world.getTile(x, y - 1).isTransparent) { if (random.Next(1000) == 0) { world.setTile(new TileGrass(), x, y); } } } } //D { int x = xPos + 1; int y = yPos; if (world.getTile(x, y) != null && world.getTile(x, y).ID == 1) { if (world.getTile(x, y - 1) == null || world.getTile(x, y - 1).isTransparent) { if (random.Next(1000) == 0) { world.setTile(new TileGrass(), x, y); } } } } //E { int x = xPos - 1; int y = yPos + 1; if (world.getTile(x, y) != null && world.getTile(x, y).ID == 1) { if (world.getTile(x, y - 1) == null || world.getTile(x, y - 1).isTransparent) { if (random.Next(1000) == 0) { world.setTile(new TileGrass(), x, y); } } } } //F { int x = xPos + 1; int y = yPos + 1; if (world.getTile(x, y) != null && world.getTile(x, y).ID == 1) { if (world.getTile(x, y - 1) == null || world.getTile(x, y - 1).isTransparent) { if (random.Next(1000) == 0) { world.setTile(new TileGrass(), x, y); } } } } } }