// Update object public override void update(Tile [,] map) { if (!exists) return; int getImageFromHeight = 0; if (animationChoice < animationSpeed / 4) getImageFromHeight = 0; else if (animationChoice < 2 * animationSpeed / 4) getImageFromHeight = 300; else if (animationChoice < 3 * animationSpeed / 4) getImageFromHeight = 600; else getImageFromHeight = 300; newState = Keyboard.GetState(); velocity.X = 0; velocity.Y = 0; if (newState.IsKeyDown(Keys.Right)) { velocity.X += 1; image = new Rectangle(600, getImageFromHeight, 300, 300); } if (newState.IsKeyDown(Keys.Left)) { velocity.X -= 1; image = new Rectangle(900, getImageFromHeight, 300, 300); } if (newState.IsKeyDown(Keys.Up)) { velocity.Y -= 1; image = new Rectangle(300, getImageFromHeight, 300, 300); } if (newState.IsKeyDown(Keys.Down)) { velocity.Y += 1; image = new Rectangle(0, getImageFromHeight, 300, 300); } velocity.Normalize(); velocity.X *= speed; velocity.Y *= speed; animationChoice++; if (animationChoice >= animationSpeed) animationChoice = 0; mapCollide(map); }
// Update object public void update(Tile[,] map, Vector2 heroPosition) { if (!exists) return; velocity.X = position.X - heroPosition.X; velocity.Y = position.Y - heroPosition.Y; velocity.Normalize(); velocity.X *= speed; velocity.Y *= speed; mapCollide(map); }
// Update object public void update(Tile[,] map, Vector2 heroPosition) { if (!exists) return; velocity.X = destX - position.X; velocity.Y = destY - position.Y; velocity.Normalize(); velocity.X *= speed; velocity.Y *= speed; mapCollide(map); // Check if guard has reached destination if ((velocity.X >= 0 && position.X >= destX - 1) || (velocity.X <= 0 && position.X <= destX + 1)) { if ((velocity.Y >= 0 && position.Y >= destY - 1) || (velocity.Y <= 0 && position.Y <= destY + 1)) { int tempDestX = destX; int tempDestY = destY; destX = srcX; destY = srcY; srcX = tempDestX; srcY = tempDestY; } } if (velocity.Y > 0) image = new Rectangle(0, 0, 300, 300); else if (velocity.Y < 0) image = new Rectangle(300, 0, 300, 300); if (velocity.X > 0 && Math.Abs(velocity.X) > Math.Abs(velocity.Y)) image = new Rectangle(600, 0, 300, 300); else if (velocity.X < 0 && Math.Abs(velocity.X) > Math.Abs(velocity.Y)) image = new Rectangle(900, 0, 300, 300); }
public Map() { level = 0; tiles = new Tile[MAP_ROWS, MAP_COLS]; for (int i = 0; i < MAP_ROWS; ++i) for (int j = 0; j < MAP_COLS; ++j) { tiles[i, j] = new Tile(); tiles[i, j].location = new Rectangle(j * Fired.TILE_SIZE, i * Fired.TILE_SIZE, Fired.TILE_SIZE, Fired.TILE_SIZE); } levelFinished = true; openWindow = false; loseGame = winGame = false; hero = new Hero(0, 0, 3); employees = new List<Employee>(); swat = new List<Swat>(); guard = new List<SecurityGuard>(); boss = new List<Boss>(); sucker = new List<SewageSucker>(); carcass = new List<Carcass>(); stairs = new Rectangle(); window = new Rectangle(2000, 2000, 1, 1); }
// Update object public void update(Tile[,] map, Vector2 heroPosition) { if (!exists) return; velocity.X = heroPosition.X - position.X; velocity.Y = heroPosition.Y - position.Y; velocity.Normalize(); velocity.X *= speed; velocity.Y *= speed; if (velocity.Y > 0) image = new Rectangle(0, 0, 300, 300); else if (velocity.Y < 0) image = new Rectangle(300, 0, 300, 300); if (velocity.X > 0 && Math.Abs(velocity.X) > Math.Abs(velocity.Y)) image = new Rectangle(600, 0, 300, 300); else if (velocity.X < 0 && Math.Abs(velocity.X) > Math.Abs(velocity.Y)) image = new Rectangle(900, 0, 300, 300); mapCollide(map); }
// Update object public virtual void update(Tile[,] map) { }
// Handle collisions with map tiles public virtual void mapCollide(Tile[,] map) { }
// Update object public void update(Tile[,] map, Vector2 heroPosition) { if (!exists) return; }
public override void mapCollide(Tile[,] tiles) { //The location a player would end up without collisions Vector2 finalLocation = new Vector2(position.X + velocity.X, position.Y + velocity.Y); IntVector tile = new IntVector(); int tileSize = Fired.TILE_SIZE; //Check top collisions if (velocity.Y > 0) while (position.Y < finalLocation.Y) { position.Y += 0.1f; tile = currentTile(position.X + Fired.CHAR_SIZE, position.Y + Fired.CHAR_SIZE); if (tiles[tile.Y, tile.X].type == TileType.Collision) { position.Y = tiles[tile.Y, tile.X].location.Y - Fired.CHAR_SIZE; break; } tile = currentTile(position.X, position.Y + Fired.CHAR_SIZE); if (tiles[tile.Y, tile.X].type == TileType.Collision) { position.Y = tiles[tile.Y, tile.X].location.Y - Fired.CHAR_SIZE; break; } } //Check bottom collisions else if (velocity.Y < 0) while (position.Y > finalLocation.Y) { position.Y -= 0.1f; tile = currentTile(position.X + Fired.CHAR_SIZE, position.Y); if (tiles[tile.Y, tile.X].type == TileType.Collision) { position.Y = tiles[tile.Y, tile.X].location.Y + tileSize + 0.1f; break; } tile = currentTile(position.X, position.Y); if (tiles[tile.Y, tile.X].type == TileType.Collision) { position.Y = tiles[tile.Y, tile.X].location.Y + tileSize + 0.1f; break; } } else { } //Reset the y position so there are no erroneous tile collisions //location = finalLocation; //Check right collisions if (velocity.X > 0) while (position.X < finalLocation.X) { position.X += 0.1f; tile = currentTile(position.X + Fired.CHAR_SIZE, position.Y + Fired.CHAR_SIZE); if (tiles[tile.Y, tile.X].type == TileType.Collision) { position.X = tiles[tile.Y, tile.X].location.X - Fired.CHAR_SIZE; break; } tile = currentTile(position.X + Fired.CHAR_SIZE, position.Y); if (tiles[tile.Y, tile.X].type == TileType.Collision) { position.X = tiles[tile.Y, tile.X].location.X - Fired.CHAR_SIZE; break; } } //Check left collisions else if (velocity.X < 0) while (position.X > finalLocation.X) { position.X -= 0.1f; tile = currentTile(position.X, position.Y); if (tiles[tile.Y, tile.X].type == TileType.Collision) { position.X = tiles[tile.Y, tile.X].location.X + tileSize + 0.1f; break; } tile = currentTile(position.X, position.Y + Fired.CHAR_SIZE); if (tiles[tile.Y, tile.X].type == TileType.Collision) { position.X = tiles[tile.Y, tile.X].location.X + tileSize + 0.1f; break; } } else { } //Set locations hitBox.X = (int)position.X; hitBox.Y = (int)position.Y; }