public ScreenWorld(World world) : base(null) { this.world = world; player = new PlayerCreative(new Vector2(Tile.Tile_Width * 20, Tile.Tile_Width * 18), "technorover"); world.entities.Add(player); }
public static World generateWorld(int width, int height) { World world = new World(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { //World Generation logic here if (y == 20) { world.setTile(new TileGrass(), x, y); world.setBackground(new BackgroundDirt(), x, y); } if (y > 20) { world.setTile(new TileDirt(), x, y); world.setBackground(new BackgroundDirt(), x, y); } if (y > 23) { world.setTile(new TileStone(), x, y); world.setBackground(new BackgroundStone(), x, y); } } } return world; }
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 void moveDown(World world) { move(world, 0, (int)movementSpeed); }
public abstract void tick(World world);
public abstract void tick(World world, int xPos, int yPos);
public void updateJumpAndGrav(World world) { Boolean doGravityThisTick = true; if (move(world, 0, forceOfGrav)) { g = true; } else { g = false; move(world, 0, -forceOfGrav); } if (jumpVelocity > 0) { doGravityThisTick = false; jumpVelocity -= (int)movementSpeed; if (jumpVelocity < 0) { jumpVelocity = 0; } move(world, 0, -(int)movementSpeed); } if (doGravityThisTick) { move(world, 0, forceOfGrav); } }
public abstract Boolean move(World world, int xMove, int yMove);
public void moveRight(World world) { move(world, (int) movementSpeed, 0); }
public void moveUp(World world) { move(world, 0, (int)-movementSpeed); }
public virtual void onPlace(World world, int xTile, int yTile) { }
public void moveLeft(World world) { move(world, (int)-movementSpeed, 0); }
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 void startGame(World world) { screen = new ScreenWorld(world); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here screenWidth = graphics.GraphicsDevice.Viewport.Width; screenHeight = graphics.GraphicsDevice.Viewport.Height; Textures.LoadContent(this); InputHandler.handler = new InputHandler(); world = WorldGeneratorNormal.generateWorld(100, 100); //this.IsMouseVisible = true; base.Initialize(); }
public override void tick(World world, int xPos, int yPos) { }
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); } } } } } }