public bool AddBlock(Block block) { if (block != null) { this.blocks.Add(block); TileMap.getTileByIndex((int)block.Index.X, (int)block.Index.Y).AddBlock(block); block.HandleInteraction(); return true; } return false; }
public bool AddBlock(Block block) { if (this.block == null) { this.block = block; UpdatePassability(); block.Position = this.position; return true; } return false; }
private Lizard(Vector2 position) { this.tile = TileMap.getTileAtPos(position); this.isSelected = false; this.position = position; pickup = false; this.path = new List<Tile>(); this.targetTile = tile; this.nextTile = tile; Path(targetTile); this.block = null; this.rotation = 0f; }
public Block RemoveBlock() { if (this.block == null) { return null; } Block block = this.block; this.block = null; world.RemoveBlock(block); UpdatePassability(); return block; }
public void Update(GameTime gameTime) { //move through list if (this.targetTile != null && this.targetTile == this.tile) { //hit our target, move on if (this.path.Count > 1) { this.path.Remove(this.targetTile); this.targetTile = this.path.First(); } else if ((this.targetTile.position - this.position).Length() < TileMap.TILESIZE)//try to get a block or put one down { //todo decide how blocks work here //if no block, pick up if (this.block == null && targetTile.block == this.pickupBlock) { this.block = targetTile.RemoveBlock(); this.pickupBlock = null; } } if (this.dropTile != null && (this.dropTile.position - this.position).Length() < TileMap.TILESIZE * 2) { this.block.Position = dropTile.position; dropTile.world.AddBlock(this.block); this.block = null; this.dropTile = null; } } //if we have somewhere to move if (targetTile != null && position != targetTile.position + new Vector2(16)) { //get the direction vector to it Vector2 dir = targetTile.position - this.position + new Vector2(16); //clip it to 3 max if (dir.Length() > 3f) { dir.Normalize(); dir *= 3f; } //advance position += dir; //if we move, rotate to that way if (dir.Length() > 0.01) { this.rotation = angerp(this.rotation,(float)Math.Atan2(dir.Y, dir.X),0.25f); } //get the tile at the new position Tile currTile = TileMap.getTileAtPos(this.position); if (currTile == this.tile)//if we don't change tiles { } else if(currTile.lizard == null && currTile.block == null)//if we advance onto a free tile { this.tile.RemoveLizard(this); this.tile = currTile; this.tile.AddLizard(this); } else if (currTile.block != null && currTile.block == this.pickupBlock)// if we hit the block to pick up { this.block = currTile.RemoveBlock(); this.pickupBlock = null; this.tile.RemoveLizard(this); this.tile = currTile; this.tile.AddLizard(this); } else if (currTile.lizard != null || currTile.block != null)//if we collide with a block or lizard { //unmove, repath this.position -= dir; Tile thing2 = TileMap.getTileAtPos(this.position); if (!Path(this.path.Last())) { Path(thing2); } } } }
public Block RemoveBlock(Block block) { if (block != null) { this.blocks.Remove(block); } return block; }