public async Task <RetroGame> CreateRetroGameAsync(string name, string template, int teamId) { RetroGame game = await _context.RetroGames.FirstOrDefaultAsync(rg => rg.Name == name && rg.TeamId == teamId); if (game != null) { return(null); } var newGame = new RetroGame() { Name = name, Template = template, CreationDate = DateTime.Now, LastModified = DateTime.Now, Notes = new List <Note>(), TeamId = teamId, Url = Guid.NewGuid().ToString() }; _context.RetroGames.Add(newGame); await _context.SaveChangesAsync(); return(await _context.RetroGames.FirstOrDefaultAsync(rg => rg.Name == name)); }
public bool attemptDie() { //On-death powerup activation if (HasPowerup("Retro")) { if (Powerups["Retro"] is RetroPort && History.CanRevert() && RetroGame.AvailableSand > 0) { Powerups["Retro"].Activate(InputAction.None); return(false); } } else if (HasPowerup("Health")) { if (Powerups["Health"] is FullHealthPickup) { Powerups["Health"].Activate(InputAction.None); return(false); } } SoundManager.PlaySoundOnce("PlayerDead", playInReverseDuringReverse: true); Alive = false; if (RetroGame.getMainLiveHero() == null) { RetroGame.GameOver(); return(true); } LevelManager levelManager = RetroGame.EscapeScreen.levelManager; levelManager.SetCameraMode(RetroGame.EscapeScreen.levelManager.CameraMode); return(true); }
public void Initialize() { #if DEBUG AddPowerup(typeof(Flamethrower)); AddPowerup(typeof(TimedSpeedBoost)); AddPowerup(typeof(AdrenalinePickup)); AddPowerup(typeof(FireChains)); AddPowerup(typeof(DrillFast)); AddPowerup(typeof(RocketBurst)); Inventory.StorePowerup(new DrillTriple(this)); Inventory.StorePowerup(new ShieldSlow(this)); Inventory.StorePowerup(new ShieldDamage(this)); Inventory.StorePowerup(new BombTimed(this)); Inventory.StorePowerup(new BombSet(this)); AddPowerup(typeof(RescuePowerup)); if (this == RetroGame.getHeroes()[0]) { AddPowerup(typeof(FireChains)); } #endif color = NEW_HERO_COLORS[playerIndex]; maskingColor = color; prisonerName = NEW_HERO_NAMES[playerIndex]; prisonerID = NEW_HERO_IDS[playerIndex]; Prisoner.TAKEN_IDS[prisonerID] = true; History.RegisterReversible(this); }
public static void PreDraw() { float storeCharge = RetroGame.StoreCharge; Color unchargedColor = STORE_UNCHARGED_COLOR; Color storeColor = (storeCharge >= 1) ? STORE_FULLYCHARGED_COLOR : STORE_PARTLYCHARGED_COLOR; graphicsDevice.SetRenderTarget(storeIconTarget); graphicsDevice.Clear(Color.Transparent); Effect effect = Effects.StoreIconShading; effect.Parameters["unchargedColor"].SetValue(unchargedColor.ToVector4()); effect.Parameters["chargedColor"].SetValue(storeColor.ToVector4()); effect.Parameters["shadingPercentage"].SetValue(storeCharge); if (storeCharge >= 1) { storeSpriteBatch.Begin(); byte alpha = (byte)(storeBorderInterp * 255); storeSpriteBatch.Draw(storeIconBorder, Vector2.Zero, STORE_FULLYCHARGED_COLOR.withAlpha(alpha)); Hero mainPlayer = RetroGame.getMainLiveHero(); if (mainPlayer != null) { SpriteFont startFont = (mainPlayer.currentInputType == InputType.Keyboard) ? RetroGame.FONT_HUD_KEYS : RetroGame.FONT_HUD_XBOX; string startString = mainPlayer.bindings.getHUDIconCharacter(mainPlayer.currentInputType, InputAction.Start); float storeStartScale = (mainPlayer.currentInputType == InputType.Keyboard) ? STORE_START_KEY_SCALE : STORE_START_BUTTON_SCALE; storeSpriteBatch.DrawString(startFont, startString, new Vector2(storeIconTarget.Width / 2f, storeIconTarget.Height / 2f), Color.White.withAlpha(alpha), 0, new Vector2(startFont.MeasureString(startString).X / 2, 0), storeStartScale, SpriteEffects.None, 0); } storeSpriteBatch.End(); } storeSpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, effect); storeSpriteBatch.Draw(storeIcon, new Vector2(storeIconTarget.Width / 2f, storeIconTarget.Height / 4f), null, Color.White, 0, new Vector2(storeIcon.Width / 2f, storeIcon.Height / 2f), 1, SpriteEffects.None, 0); storeSpriteBatch.End(); }
public override void OnInputAction(InputAction action, bool pressedThisFrame) { switch (action) { case InputAction.Action1: //default P1 - Space, P2 - NumPad0, 360 - A case InputAction.Action2: //default P1 - Q, P2 - NumPad9, 360 - B case InputAction.Action3: //default P1 - LeftShift, P2 - Enter, 360 - X case InputAction.Action4: //default P1 - LeftControl, P2 - Plus, 360 - Y Inventory.ActivatePowerup(playerIndex, action); break; case InputAction.Start: //default P1 - T, P2 - T, 360 - Start if (pressedThisFrame) { RetroGame.PauseGame(this); } break; case InputAction.Escape: //default P1 - Escape, P2 - Escape, 360 - Back if (pressedThisFrame) { RetroGame.PauseGame(this); } break; default: break; } }
public static void UpdateForward(GameTime gameTime) { float seconds = gameTime.getSeconds(); secsSinceLastRetroPort += seconds; History history = new History(); foreach (IReversible reversible in registeredReversibles) { history.mementos[reversible] = reversible.GenerateMementoFromCurrentFrame(); } history.retroGameMemento = RetroGame.GenerateMementoFromCurrentFrame(); history.riotGuardWallMemento = RiotGuardWall.GenerateMementoFromCurrentFrame(); history.soundManagerMemento = SoundManager.GenerateMementoFromCurrentFrame(); histories.Enqueue(history); if (secsSinceLastRetroPort >= RETROPORT_BASE_SECS) { LastHistory = histories.Dequeue(); } else { LastHistory = null; } }
public async Task <ResultData <RetroGame> > CreateRetroGameAsync(string name, string template, int teamId) { if (string.IsNullOrEmpty(name)) { return(new ResultData <RetroGame>(InvalidRetroGameNameMessage, false)); } if (string.IsNullOrEmpty(template)) { return(new ResultData <RetroGame>(InvalidRetroGameTemplateMessage, false)); } if (!_teamsRepository.TeamExists(teamId)) { string errorMessage = string.Format(TeamDoesntExistMessage, teamId); return(new ResultData <RetroGame>(errorMessage, false)); } RetroGame game = await _retroGameRepository.CreateRetroGameAsync(name, template, teamId); if (game == null) { string errorMessage = string.Format(TeamHasGameWithSameNameMessage, name); return(new ResultData <RetroGame>(errorMessage, false)); } string message = string.Format(RetroGameCreationSuccessMessage, game.Name); return(new ResultData <RetroGame>(message, true, game)); }
public static void ActivateRevert(Hero controllingHero, InputAction cancelAction) { LastState = RetroGame.State; RetroGame.AddScreen(new RetroPortScreen(controllingHero, cancelAction), true); SoundManager.SetMusicReverse(true); SoundManager.SetLoopingSoundsReverse(true); }
public static void CancelRevert() { Clear(); if (RetroGame.TopScreen is RetroPortScreen) { RetroGame.PopScreen(true); } SoundManager.SetMusicReverse(false); SoundManager.SetLoopingSoundsReverse(false); }
public override bool collectedBy(Entity e) { bool baseCollectedBy = base.collectedBy(e); if (baseCollectedBy) { RetroGame.AddGem(); ((Hero)e).CollectedGems++; } return(baseCollectedBy); }
private void die() { level.enemyGrid[tileX, tileY] = null; RetroGame.AddScore(ENEMY_KILL_SCORE); dying = true; double chance = RetroGame.rand.NextDouble(); if (chance < CHANCE_TO_SPAWN_SAND_ON_DEATH || forceSandToSpawn) { int i = tileX; int j = tileY; level.collectables.Add(new Sand(Level.TEX_SIZE * level.xPos + i * Level.TILE_SIZE + 16, Level.TEX_SIZE * level.yPos + j * Level.TILE_SIZE + 16, level.xPos, level.yPos, i, j)); } }
public void SetCameraMode(CameraMode mode) { switch (mode) { case CameraMode.Arena: ArenaCamera arenaCamera = new ArenaCamera(new Vector2((RetroGame.getMainLiveHero().levelX + 0.5f) * Level.TEX_SIZE + Level.TILE_SIZE / 2, (RetroGame.getMainLiveHero().levelY + 0.5f) * Level.TEX_SIZE + Level.TILE_SIZE / 2)); arenaCamera.Initialize(); if (Camera != null) { arenaCamera.InitializeWithCamera(Camera); } Camera = arenaCamera; break; case CameraMode.Escape: EscapeCamera escapeCamera; if (RetroGame.NUM_PLAYERS == 1) { escapeCamera = new EscapeCamera(RetroGame.getMainLiveHero()); } else //if (RetroGame.NUM_PLAYERS == 2) { int liveHeroes = 0; foreach (Hero hero in RetroGame.getHeroes()) { if (hero.Alive) { liveHeroes++; } } if (liveHeroes == 1) { escapeCamera = new EscapeCamera(RetroGame.getMainLiveHero()); } else { escapeCamera = new CoopEscapeCamera(RetroGame.getHeroes()[0], RetroGame.getHeroes()[1]); } } escapeCamera.Initialize(); if (Camera != null) { escapeCamera.InitializeWithCamera(Camera); } Camera = escapeCamera; break; } CameraMode = mode; }
public Color getTileColor(int tileX, int tileY) { Color tileColor = Color.White; int xFragment = tileX / (LevelContent.LEVEL_SIZE_HALF); int yFragment = tileY / (LevelContent.LEVEL_SIZE_HALF); if (tileX == 0 || tileY == 0) { if (xPos == 0 || yPos == 0) { tileColor = Color.White; } else if (tileX == 0 && tileY == 0) // tile at topleft corner between levels { Color leftColor = RetroGame.getLevels()[xPos - 1, yPos].getTileColor(GRID_SIZE - 1, tileY); Color topColor = RetroGame.getLevels()[xPos, yPos - 1].getTileColor(tileX, GRID_SIZE - 1); Color cornerColor = RetroGame.getLevels()[xPos - 1, yPos - 1].getTileColor(GRID_SIZE - 1, GRID_SIZE - 1); tileColor = Color.Lerp(Color.Lerp(leftColor, topColor, 0.5f), Color.Lerp(cornerColor, getTileColor(1, 1), 0.5f), 0.5f); } else if (tileX == 0) // tile in between levels on left { tileColor = Color.Lerp(RetroGame.getLevels()[xPos - 1, yPos].getTileColor(GRID_SIZE - 1, tileY), getTileColor(1, tileY), 0.5f); } else if (tileY == 0) // tile in between levels on top { tileColor = Color.Lerp(RetroGame.getLevels()[xPos, yPos - 1].getTileColor(tileX, GRID_SIZE - 1), getTileColor(tileX, 1), 0.5f); } } else if (tileX == LevelContent.LEVEL_SIZE_HALF - 1 && tileY == LevelContent.LEVEL_SIZE_HALF - 1) // tile at center of 4 fragments { tileColor = Color.Lerp(Color.Lerp(fragmentGrid[0, 0].color, fragmentGrid[1, 0].color, 0.5f), Color.Lerp(fragmentGrid[0, 1].color, fragmentGrid[1, 1].color, 0.5f), 0.5f); } else if (tileX == LevelContent.LEVEL_SIZE_HALF - 1) // tile in between fragments { tileColor = Color.Lerp(fragmentGrid[0, yFragment].color, fragmentGrid[1, yFragment].color, 0.5f); } else if (tileY == LevelContent.LEVEL_SIZE_HALF - 1) // tile in between fragments { tileColor = Color.Lerp(fragmentGrid[xFragment, 0].color, fragmentGrid[xFragment, 1].color, 0.5f); } else { tileColor = fragmentGrid[xFragment, yFragment].color; } return(tileColor); }
public virtual bool collectedBy(Entity e) { if (!dying && ableToBeCollected) { collectedTime = latestGameTime.TotalGameTime.TotalMilliseconds; float randomScoreBonus = ((float)RetroGame.rand.NextDouble() - 0.5f) * (baseScore * COLLECTABLE_SCORE_RANDOM_BONUS_PERCENTAGE); if (baseScore > 0) RetroGame.AddScore((int)(baseScore + rampUpScoreBonus + randomScoreBonus)); dying = true; ableToBeCollected = false; collectedByEntity = e; if (!string.IsNullOrEmpty(CollectedSound)) SoundManager.PlaySoundOnce(CollectedSound); return true; } return false; }
public virtual bool drillWall(int tileX, int tileY) { try { if (grid[tileX, tileY] != LevelContent.LevelTile.Wall) { return(true); } } catch (IndexOutOfRangeException e) { return(false); } if (!drilledWalls.Contains(new Point(tileX, tileY))) { drilledWalls.Add(new Point(tileX, tileY)); } grid[tileX, tileY] = LevelContent.LevelTile.Floor; pathfinding.costGrid[tileX, tileY] = Pathfinding.COST_FLOOR; resetPathfinding(); Color tileColor = getTileColor(tileX, tileY); Color[] tileData = new Color[TILE_SIZE * TILE_SIZE]; texFloor.GetData <Color>(tileData); for (int d = 0; d < tileData.Length; d++) { tileData[d] = tileData[d].Tint(tileColor, WALL_TINT_FACTOR); } levelOverlayTexture.SetData <Color>(0, new Rectangle(tileX * TILE_SIZE, tileY * TILE_SIZE, TILE_SIZE, TILE_SIZE), tileData, 0, TILE_SIZE * TILE_SIZE); double chance = RetroGame.rand.NextDouble(); if (chance < CHANCE_TO_SPAWN_SAND_ON_DRILL) { int i = tileX; int j = tileY; collectables.Add(new Sand(TEX_SIZE * xPos + i * TILE_SIZE + 16, TEX_SIZE * yPos + j * TILE_SIZE + 16, xPos, yPos, i, j)); } RetroGame.AddScore(DRILL_WALL_SCORE); RetroGame.HasDrilled = true; return(true); }
private void createLevel(int x, int y, int levelLayout) { switch (levelLayout) { case 0: levelFull(RetroGame.getRandomLevelFragment(LevelContent.Type.Full), x, y); break; case 1: levelTwoVert(RetroGame.getRandomLevelFragment(LevelContent.Type.HalfVertical), RetroGame.getRandomLevelFragment(LevelContent.Type.HalfVertical), x, y); break; case 2: levelLeftVertTwoCorner(RetroGame.getRandomLevelFragment(LevelContent.Type.HalfVertical), RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), x, y); break; case 3: levelRightVertTwoCorner(RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), RetroGame.getRandomLevelFragment(LevelContent.Type.HalfVertical), x, y); break; case 4: levelTwoHoriz(RetroGame.getRandomLevelFragment(LevelContent.Type.HalfHorizontal), RetroGame.getRandomLevelFragment(LevelContent.Type.HalfHorizontal), x, y); break; case 5: levelTopHorizTwoCorner(RetroGame.getRandomLevelFragment(LevelContent.Type.HalfHorizontal), RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), x, y); break; case 6: levelBottomHorizTwoCorner(RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), RetroGame.getRandomLevelFragment(LevelContent.Type.HalfHorizontal), x, y); break; case 7: levelFourCorner(RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), RetroGame.getRandomLevelFragment(LevelContent.Type.Corner), x, y); break; default: throw new ArgumentException("levelLayout needs to be between 0 and 7", "levelLayout"); } }
public bool collidesWithWall(Vector2 position) { int x = (int)position.X; int y = (int)position.Y; if (x <= 0 || y <= 0) { return(true); } int levelX = x / Level.TEX_SIZE; // get which level you are in int levelY = y / Level.TEX_SIZE; if (levelX >= MAX_LEVELS || levelY >= MAX_LEVELS) { return(true); } Level level = RetroGame.getLevels()[levelX, levelY]; if (level == null) { return(true); } int tileX = (x % Level.TEX_SIZE) / Level.TILE_SIZE; // get which tile you are moving to int tileY = (y % Level.TEX_SIZE) / Level.TILE_SIZE; LevelContent.LevelTile tile = level.grid[tileX, tileY]; switch (tile) { case LevelContent.LevelTile.Wall: return(true); default: break; } return(false); }
public Powerup AddPowerup(Type powerupType, bool automaticallySetPowerupIcon = true) { Powerup powerup = null; if (powerupType.IsSubclassOf(typeof(CoOpPowerup))) { //gets the other hero from the list of heroes (or just another hero if for some reason there are more than 2 heroes) Hero otherHero = null; foreach (Hero h in RetroGame.getHeroes()) { if (h != this) { otherHero = h; break; } } if (otherHero == null) { return(null); } powerup = (Powerup)powerupType.GetConstructor(new Type[] { typeof(Hero), typeof(Hero) }).Invoke(new object[] { this, otherHero }); } else { powerup = (Powerup)powerupType.GetConstructor(new Type[] { typeof(Hero) }).Invoke(new object[] { this }); } if (Inventory.EquipPowerup(powerup, playerIndex, automaticallySetPowerupIcon)) { Powerups.Add(powerup.GenericName, powerup); powerup.OnAddedToHero(); if (powerup is IReversible) { History.RegisterReversible((IReversible)powerup); } History.Clear(); } return(powerup); }
public override void Update(GameTime gameTime) { if (dying) { deathEmitter.position = position; deathEmitter.Update(gameTime); } else { AI ai = null; switch (state) { case EnemyState.Idle: ai = idleAI; idleAI.Update(gameTime); break; case EnemyState.TargetingHero: ai = targetedAI; targetedAI.Update(gameTime); break; } direction = ai.GetNextDirection(this); float moveSpeed = MOVE_SPEED * ai.GetNextMoveSpeedMultiplier(this); float seconds = gameTime.getSeconds((RetroGame.retroStatisActive) ? RetroGame.timeScale / 3 : RetroGame.timeScale); Vector2 movement = direction.toVector() * moveSpeed * globalMoveSpeedMultiplier * seconds; float nextX = position.X + movement.X; float nextY = position.Y + movement.Y; bool moved = true; int n; switch (direction) { case Direction.Up: moved = canMove(new Vector2(0, movement.Y)); if (!moved) { n = (int)position.Y; nextY = n + Level.TILE_SIZE / 2 - (n % Level.TILE_SIZE); } rotation = (float)Math.PI; break; case Direction.Down: moved = canMove(new Vector2(0, movement.Y)); if (!moved) { n = (int)position.Y; nextY = n + Level.TILE_SIZE / 2 - (n % Level.TILE_SIZE); } rotation = 0; break; case Direction.Left: moved = canMove(new Vector2(movement.X, 0)); if (!moved) { n = (int)position.X; nextX = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; } rotation = (float)Math.PI / 2f; break; case Direction.Right: moved = canMove(new Vector2(movement.X, 0)); if (!moved) { n = (int)position.X; nextX = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; } rotation = (float)Math.PI * 3f / 2f; break; default: nextX = position.X; nextY = position.Y; break; } // check corners if (moved && (level.collidesWithAnything(new Vector2(getLeft().X, getTop().Y), this) || //topleft level.collidesWithAnything(new Vector2(getLeft().X, getBottom().Y), this) || //botleft level.collidesWithAnything(new Vector2(getRight().X, getBottom().Y), this) || //botright level.collidesWithAnything(new Vector2(getRight().X, getTop().Y), this))) //top right { Direction directionToCorrect = (direction == Direction.None) ? prevDirection : direction; switch (directionToCorrect) { case Direction.Up: n = (int)position.X; nextX = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; break; case Direction.Down: n = (int)position.X; nextX = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; break; case Direction.Left: n = (int)position.Y; nextY = n + Level.TILE_SIZE / 2 - (n % Level.TILE_SIZE); break; case Direction.Right: n = (int)position.Y; nextY = n + Level.TILE_SIZE / 2 - (n % Level.TILE_SIZE); break; default: break; } } if (direction != Direction.None) { prevDirection = direction; } position = new Vector2(nextX, nextY); level.enemyGrid[tileX, tileY] = null; updateCurrentLevelAndTile(); level.enemyGrid[tileX, tileY] = this; } base.Update(gameTime); if (!dying) { foreach (Hero hero in RetroGame.getHeroes()) { if (hero.Alive && hitbox.intersects(hero.hitbox)) { hero.hitBy(this, ON_HIT_DAMAGE); dieOnHero(hero); } } visionLineNonWalls.Clear(); visionLineWalls.Clear(); if (state == EnemyState.Idle) { heroInVisionPos = Vector2.Zero; searchForHeroes(); } } maskingColor = Color.Lerp(Color.Black, Color.White, health / STARTING_HEALTH); globalMoveSpeedMultiplier = 1f; }
public void searchForHeroes() { const float EPSILON = 0.001f; List <Hero> heroesInVision = new List <Hero>(); visionLineNonWalls.Clear(); visionLineWalls.Clear(); foreach (Hero hero in RetroGame.getHeroes()) { if (hero.Alive && hero.levelX == levelX && hero.levelY == levelY) { Vector2 unitVectorFromEnemyToHero = hero.position - position; unitVectorFromEnemyToHero.Normalize(); if (Math.Abs(unitVectorFromEnemyToHero.X) <= EPSILON) { unitVectorFromEnemyToHero = Vector2.UnitY * Math.Sign(unitVectorFromEnemyToHero.Y); } else if ((1 - Math.Abs(unitVectorFromEnemyToHero.X)) <= EPSILON) { unitVectorFromEnemyToHero = Vector2.UnitX * Math.Sign(unitVectorFromEnemyToHero.X); } if (Math.Abs(unitVectorFromEnemyToHero.Y) <= EPSILON) { unitVectorFromEnemyToHero = Vector2.UnitX * Math.Sign(unitVectorFromEnemyToHero.X); } else if ((1 - Math.Abs(unitVectorFromEnemyToHero.Y)) <= EPSILON) { unitVectorFromEnemyToHero = Vector2.UnitY * Math.Sign(unitVectorFromEnemyToHero.Y); } double angleToHero = unitVectorFromEnemyToHero.getAngleToHorizontal(); bool heroInCone = false; switch (prevDirection) { case Direction.Up: heroInCone = (angleToHero >= (5 * Math.PI / 4) && angleToHero <= (7 * Math.PI / 4)); break; case Direction.Down: heroInCone = (angleToHero >= (1 * Math.PI / 4) && angleToHero <= (3 * Math.PI / 4)); break; case Direction.Left: heroInCone = (angleToHero >= (3 * Math.PI / 4) && angleToHero <= (5 * Math.PI / 4)); break; case Direction.Right: heroInCone = (angleToHero >= (7 * Math.PI / 4) && angleToHero <= (8 * Math.PI / 4)) || (angleToHero >= (0 * Math.PI / 4) && angleToHero <= (1 * Math.PI / 4)); break; } if (heroInCone) { //DDA algorithm in both X and Y directions to check all tiles in line of sight bool canSeeHero = true; const int step = Level.TILE_SIZE; if (unitVectorFromEnemyToHero.X == 0) { int tX = (int)((position.X % Level.TEX_SIZE) / Level.TILE_SIZE); int dir = Math.Sign(hero.position.Y - position.Y); for (float currentY = position.Y; Math.Abs(hero.position.Y - currentY) >= step; currentY += step * dir) { int tY = (int)((currentY % Level.TEX_SIZE) / Level.TILE_SIZE); if (level.grid[tX, tY] == LevelContent.LevelTile.Wall) { canSeeHero = false; visionLineWalls.Add(new Point(tX, tY)); } else { visionLineNonWalls.Add(new Point(tX, tY)); } } } else if (unitVectorFromEnemyToHero.Y == 0) { int tY = (int)((position.Y % Level.TEX_SIZE) / Level.TILE_SIZE); int dir = Math.Sign(hero.position.X - position.X); for (float currentX = position.X; Math.Abs(hero.position.X - currentX) >= step; currentX += step * dir) { int tX = (int)((currentX % Level.TEX_SIZE) / Level.TILE_SIZE); if (level.grid[tX, tY] == LevelContent.LevelTile.Wall) { canSeeHero = false; visionLineWalls.Add(new Point(tX, tY)); } else { visionLineNonWalls.Add(new Point(tX, tY)); } } } else { float m = unitVectorFromEnemyToHero.Y / unitVectorFromEnemyToHero.X; float intercept = ((position.Y % Level.TEX_SIZE) - (m * (position.X % Level.TEX_SIZE))); int xDir = (hero.position.X - position.X >= 0) ? 1 : -1; int yDir = (hero.position.Y - position.Y >= 0) ? 1 : -1; int startX = (int)position.X % Level.TEX_SIZE; int startY = (int)position.Y % Level.TEX_SIZE; int endX = (int)hero.position.X % Level.TEX_SIZE; int endY = (int)hero.position.Y % Level.TEX_SIZE; int nextX = startX + (xDir * step) - (startX % step); int nextY = startY + (yDir * step) - (startY % step); float yk = (m * nextX) + intercept; float xk = (nextY - intercept) / m; for (int i = 0; (yDir == 1 && yk < endY) || (yDir == -1 && yk > endY); i++) { float x = nextX + (i * step * xDir); int tX = (int)(x / Level.TILE_SIZE); int tY = (int)(yk / Level.TILE_SIZE); if (Level.tileWithinBounds(tX, tY)) { if (level.grid[tX, tY] == LevelContent.LevelTile.Wall) { canSeeHero = false; visionLineWalls.Add(new Point(tX, tY)); } else { visionLineNonWalls.Add(new Point(tX, tY)); } } if (Level.tileWithinBounds(tX - 1, tY)) { if (level.grid[tX - 1, tY] == LevelContent.LevelTile.Wall) { canSeeHero = false; visionLineWalls.Add(new Point(tX - 1, tY)); } else { visionLineNonWalls.Add(new Point(tX - 1, tY)); } } yk += Math.Abs(m * step) * yDir; } for (int i = 0; (xDir == 1 && xk < endX) || (xDir == -1 && xk > endX); i++) { float y = nextY + (i * step * yDir); int tX = (int)(xk / Level.TILE_SIZE); int tY = (int)(y / Level.TILE_SIZE); if (Level.tileWithinBounds(tX, tY)) { if (level.grid[tX, tY] == LevelContent.LevelTile.Wall) { canSeeHero = false; visionLineWalls.Add(new Point(tX, tY)); } else { visionLineNonWalls.Add(new Point(tX, tY)); } } if (Level.tileWithinBounds(tX, tY - 1)) { if (level.grid[tX, tY - 1] == LevelContent.LevelTile.Wall) { canSeeHero = false; visionLineWalls.Add(new Point(tX, tY - 1)); } else { visionLineNonWalls.Add(new Point(tX, tY - 1)); } } xk += Math.Abs((1 / m) * step) * xDir; } //end DDA algorithm } if (canSeeHero) { heroesInVision.Add(hero); heroInVisionPos = hero.position; } } } } if (heroesInVision.Count > 0) { heroesInVision.Sort(new Comparison <Hero>((hero1, hero2) => { float dist1 = Vector2.Distance(hero1.position, position); float dist2 = Vector2.Distance(hero2.position, position); return((int)(dist1 - dist2)); })); state = EnemyState.TargetingHero; targetedAI.SetTarget(heroesInVision[0]); } }
public void UpdateDebugKeys() { //update debug keys if (pressedThisFrame(Keys.Y) && this == RetroGame.getHeroes()[0]) { if (GetPowerup("Rocket") is RocketBurst) { RemovePowerup("Rocket"); AddPowerup(typeof(RocketBoost)); } else { if (HasPowerup("Rocket")) { RemovePowerup("Rocket"); } AddPowerup(typeof(RocketBurst)); } } if (pressedThisFrame(Keys.U)) { if (GetPowerup("Gun") is ShotForward) { RemovePowerup("Gun"); AddPowerup(typeof(ShotSide)); } else if (GetPowerup("Gun") is ShotSide) { RemovePowerup("Gun"); AddPowerup(typeof(ShotCharge)); } else if (GetPowerup("Gun") is ShotCharge) { RemovePowerup("Gun"); AddPowerup(typeof(Flamethrower)); } else if (GetPowerup("Flamethrower") is Flamethrower) { RemovePowerup("Flamethrower"); } else { if (HasPowerup("Gun")) { RemovePowerup("Gun"); } AddPowerup(typeof(ShotForward)); } } else if (pressedThisFrame(Keys.I)) { if (GetPowerup("Retro") is RetroPort) { RemovePowerup("Retro"); AddPowerup(typeof(RetroStasis)); } else { if (HasPowerup("Retro")) { RemovePowerup("Retro"); } AddPowerup(typeof(RetroPort)); } } else if (pressedThisFrame(Keys.O)) { if (GetPowerup("Drill") is DrillFast && !(GetPowerup("Drill") is DrillBasic)) { RemovePowerup("Drill"); AddPowerup(typeof(DrillTriple)); } else if (GetPowerup("Drill") is DrillTriple) { RemovePowerup("Drill"); AddPowerup(typeof(DrillBasic)); } else { if (HasPowerup("Drill")) { RemovePowerup("Drill"); } AddPowerup(typeof(DrillFast)); } } else if (pressedThisFrame(Keys.P)) { if (GetPowerup("Radar") is RadarPowerup) { RemovePowerup("Radar"); } else { AddPowerup(typeof(RadarPowerup)); } } else if (pressedThisFrame(Keys.B)) { if (GetPowerup("Bomb") is BombTimed) { RemovePowerup("Bomb"); AddPowerup(typeof(BombSet)); } else { if (HasPowerup("Bomb")) { RemovePowerup("Bomb"); } AddPowerup(typeof(BombTimed)); } } else if (pressedThisFrame(Keys.V)) { if (playerIndex == 0) { if (GetPowerup("Chains") is FireChains) { RemovePowerup("Chains"); } else { AddPowerup(typeof(FireChains)); } } } else if (pressedThisFrame(Keys.OemOpenBrackets)) { RetroGame.AddSand(); RetroGame.AddScore(10000); RetroGame.AddBomb(); for (int i = 0; i < 10; i++) { RetroGame.AddGem(); } } else if (pressedThisFrame(Keys.OemCloseBrackets)) { health -= INITIAL_HEALTH * 0.1f; } else if (pressedThisFrame(Keys.H)) /*MUSICTEST*/ { SoundManager.PlaySoundAsMusic("LowRumble"); } else if (pressedThisFrame(Keys.N)) { SoundManager.StopMusic(); } else if (pressedThisFrame(Keys.J)) { SoundManager.SetMusicReverse(true); } else if (pressedThisFrame(Keys.M)) { SoundManager.SetMusicReverse(false); } else if (pressedThisFrame(Keys.K)) { SoundManager.SetMusicPitch(-1f); } else if (pressedThisFrame(Keys.OemComma)) { SoundManager.SetMusicPitch(1f); } else if (pressedThisFrame(Keys.OemPeriod)) { SoundManager.SetMusicPitch(0f); } }
public override void Update(GameTime gameTime) { //reset per-frame powerup modification fields BEFORE updating controls globalMoveSpeedMultiplier = 1; powerupCooldownModifier = 1; teleportedThisFrame = false; if (!Alive) { Powerups = (from pair in Powerups orderby pair.Value ascending select pair).ToDictionary(pair => pair.Key, pair => pair.Value); foreach (Powerup p in Powerups.Values) { p.Update(gameTime); } return; } UpdateControls(bindings, gameTime); #if DEBUG if (this == RetroGame.getHeroes()[0]) { UpdateDebugKeys(); } #endif //remove expendable powerups for (int i = 0; i < Powerups.Count; i++) { Powerup p = Powerups.Values.ElementAt(i); if (p.toRemove) { RemovePowerup(p.GenericName, false); i--; } } Powerups = (from pair in Powerups orderby pair.Value ascending select pair).ToDictionary(pair => pair.Key, pair => pair.Value); foreach (Powerup p in Powerups.Values) { p.Update(gameTime); } float seconds = gameTime.getSeconds(HERO_TIMESCALE); movement = dirVector * MOVE_SPEED * globalMoveSpeedMultiplier * seconds; updateCurrentLevelAndTile(); Level level = RetroGame.getLevels()[levelX, levelY]; float nextX = position.X + movement.X; float nextY = position.Y + movement.Y; moved = true; int n; if (HERO_TIMESCALE > 0f) { switch (controllerDirection) { case Direction.Up: case Direction.Down: moved = canMove(movement); if (!moved) { n = (int)position.Y; nextY = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; } break; case Direction.Left: case Direction.Right: moved = canMove(new Vector2(movement.X, 0)); if (!moved) { n = (int)position.X; nextX = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; } break; default: nextX = position.X; nextY = position.Y; break; } } if (controllerDirection != Direction.None) { direction = controllerDirection; } rotation = DIR_TO_ROTATION[direction]; position = new Vector2(nextX, nextY); // check corners LevelManager levelManager = RetroGame.TopLevelManagerScreen.levelManager; if (moved && (levelManager.collidesWithWall(new Vector2(getLeft().X, getTop().Y)) || //topleft levelManager.collidesWithWall(new Vector2(getLeft().X, getBottom().Y)) || //botleft levelManager.collidesWithWall(new Vector2(getRight().X, getBottom().Y)) || //botright levelManager.collidesWithWall(new Vector2(getRight().X, getTop().Y)))) //topright { switch (controllerDirection) { case Direction.Up: case Direction.Down: n = (int)position.X; nextX = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; break; case Direction.Left: case Direction.Right: n = (int)position.Y; nextY = n - (n % Level.TILE_SIZE) + Level.TILE_SIZE / 2; break; default: break; } } position = new Vector2(nextX, nextY); nextTileX = -1; nextTileY = -1; switch (direction) { case Direction.Up: nextTileX = tileX; nextTileY = tileY - 1; break; case Direction.Down: nextTileX = tileX; nextTileY = tileY + 1; break; case Direction.Left: nextTileX = tileX - 1; nextTileY = tileY; break; case Direction.Right: nextTileX = tileX + 1; nextTileY = tileY; break; } nextLevelX = -1; nextLevelY = -1; nextLevel = null; if (nextTileX < 0) { nextLevelX = levelX - 1; nextLevelY = levelY; if (nextLevelX >= 0) { nextLevel = RetroGame.getLevels()[nextLevelX, nextLevelY]; } nextTileX = Level.GRID_SIZE - 1; } else if (nextTileX >= Level.GRID_SIZE) { nextLevelX = levelX + 1; nextLevelY = levelY; if (nextLevelX < LevelManager.MAX_LEVELS) { nextLevel = RetroGame.getLevels()[nextLevelX, nextLevelY]; } nextTileX = 0; } else if (nextTileY < 0) { nextLevelX = levelX; nextLevelY = levelY - 1; if (nextLevelY >= 0) { nextLevel = RetroGame.getLevels()[nextLevelX, nextLevelY]; } nextTileY = Level.GRID_SIZE - 1; } else if (nextTileY >= Level.GRID_SIZE) { nextLevelX = levelX; nextLevelY = levelY + 1; if (nextLevelY < LevelManager.MAX_LEVELS) { nextLevel = RetroGame.getLevels()[nextLevelX, nextLevelY]; } nextTileY = 0; } else { nextLevel = level; } //collision with collectables if (Alive) { foreach (Level l in levelManager.CurrentLevels) { foreach (Collectable c in l.collectables) { if (c.ableToBeCollected && hitbox.intersects(c.hitbox)) { c.collectedBy(this); } } foreach (Prisoner p in l.prisoners) { if (p.ableToBeCollected && hitbox.intersects(p.hitbox)) { p.collectedBy(this); } } foreach (PowerupIcon p in l.powerups) { if (p.ableToBeCollected && hitbox.intersects(p.hitbox)) { p.collectedBy(this); } } } } //flashing float flashTotalDuration = individualFlashDuration * flashCount; if (flashTime < flashTotalDuration) { flashTime += seconds; float flashInterp = (flashTime % individualFlashDuration) / individualFlashDuration; float colorInterp = 1f - (Math.Abs(flashInterp - 0.5f) * 2); //map 0.0 - 0.5 to 0.0 - 1.0 and 0.5 - 1.0 to 1.0 - 0.0 maskingColor = Color.Lerp(color, flashColor, colorInterp); } else { maskingColor = color; } base.Update(gameTime); }
public static void Draw(SpriteBatch spriteBatch) { Vector2 screenSize = RetroGame.screenSize; int score = RetroGame.Score; int availableSand = RetroGame.AvailableSand; if (!(RetroGame.TopScreen is InventoryScreen)) { Inventory.DrawEquipped(spriteBatch); } float hudWidth = screenSize.X * HUD_WIDTH; float HUD_INITIAL_POSITION = screenSize.X * (1 - HUD_WIDTH) / 2; float xPos = HUD_INITIAL_POSITION; float yPos = 0; spriteBatch.Draw(RetroGame.PIXEL, new Rectangle((int)xPos, 0, (int)hudWidth, hudHeight), HUD_COLOR); // score float xPosScore = xPos + (SCORE_XPOS * hudWidth); float yPosScore = yPos; float scoreBorderWidthHeight = (float)Math.Ceiling(SCORE_BORDER_WIDTHHEIGHT * hudScale); for (int i = 0; i <= SCORE_DIGITS; i++) { spriteBatch.Draw(RetroGame.PIXEL, new Rectangle((int)(xPosScore + i * SCORE_CELL_RELATIVEWIDTH * screenSize.X), (int)(yPosScore), (int)scoreBorderWidthHeight, (int)(SCORE_CELL_RELATIVEHEIGHT * hudHeight + scoreBorderWidthHeight)), SCORE_BORDER_COLOR); } spriteBatch.Draw(RetroGame.PIXEL, new Rectangle((int)(xPosScore), (int)(yPosScore), (int)(SCORE_DIGITS * SCORE_CELL_RELATIVEWIDTH * screenSize.X + scoreBorderWidthHeight), (int)scoreBorderWidthHeight), SCORE_BORDER_COLOR); spriteBatch.Draw(RetroGame.PIXEL, new Rectangle((int)(xPosScore), (int)(yPosScore + SCORE_CELL_RELATIVEHEIGHT * hudHeight), (int)(SCORE_DIGITS * SCORE_CELL_RELATIVEWIDTH * screenSize.X + scoreBorderWidthHeight), (int)scoreBorderWidthHeight), SCORE_BORDER_COLOR); xPosScore += (SCORE_CELL_RELATIVEWIDTH * screenSize.X) / 2; yPosScore += (SCORE_CELL_RELATIVEHEIGHT * hudHeight) / 2; float scoreTextScale = SCORE_TEXT_BASE_SCALE * hudScale; for (int i = SCORE_DIGITS - 1; i >= 0; i--) { int dividedScore = score / (int)Math.Pow(10, i); int digit = dividedScore % 10; Color dcolor = (dividedScore == 0) ? SCORE_TEXT_COLOR_ZERO : SCORE_TEXT_COLORS[digit]; string dstring = "" + digit; Vector2 dimensions = RetroGame.FONT_PIXEL_HUGE.MeasureString(dstring); spriteBatch.DrawString(RetroGame.FONT_PIXEL_HUGE, "" + digit, new Vector2(xPosScore, yPosScore), dcolor, 0, dimensions / 2, scoreTextScale, SpriteEffects.None, 0); xPosScore += (SCORE_CELL_RELATIVEWIDTH * screenSize.X); } xPos = hudWidth * SAND_POSITION.X + HUD_INITIAL_POSITION; yPos = hudHeight * SAND_POSITION.Y; spriteBatch.Draw(TextureManager.Get("sandiconhud"), new Vector2(xPos, yPos), null, Color.White, 0, Vector2.Zero, HUD_ICON_SCALE * hudScale, SpriteEffects.None, 0); spriteBatch.DrawString(RetroGame.FONT_PIXEL_SMALL, RetroGame.AvailableSand.ToString("000"), new Vector2(xPos + (HUD_TEXT_OFFSET * hudScale), yPos), Color.White, 0, Vector2.Zero, HUD_TEXT_SCALE * hudScale, SpriteEffects.None, 0); xPos = hudWidth * BOMB_POSITION.X + HUD_INITIAL_POSITION; yPos = hudHeight * BOMB_POSITION.Y; spriteBatch.Draw(TextureManager.Get("bomb"), new Vector2(xPos, yPos), null, Color.White, 0, Vector2.Zero, HUD_ICON_SCALE * hudScale, SpriteEffects.None, 0); spriteBatch.DrawString(RetroGame.FONT_PIXEL_SMALL, RetroGame.AvailableBombs.ToString("000"), new Vector2(xPos + (HUD_TEXT_OFFSET * hudScale), yPos), Color.White, 0, Vector2.Zero, HUD_TEXT_SCALE * hudScale, SpriteEffects.None, 0); xPos = hudWidth * GEMS_POSITION.X + HUD_INITIAL_POSITION; yPos = hudHeight * GEMS_POSITION.Y; spriteBatch.Draw(TextureManager.Get("collectable3"), new Vector2(xPos, yPos), null, Color.White, 0, Vector2.Zero, HUD_ICON_SCALE * hudScale, SpriteEffects.None, 0); spriteBatch.DrawString(RetroGame.FONT_PIXEL_SMALL, RetroGame.AvailableGems.ToString("000"), new Vector2(xPos + (HUD_TEXT_OFFSET * hudScale), yPos), Color.White, 0, Vector2.Zero, HUD_TEXT_SCALE * hudScale, SpriteEffects.None, 0); xPos = hudWidth * PRIS_POSITION.X + HUD_INITIAL_POSITION; yPos = hudHeight * PRIS_POSITION.Y; spriteBatch.Draw(TextureManager.Get("prisoner1"), new Vector2(xPos, yPos), null, Color.White, 0, Vector2.Zero, HUD_ICON_SCALE * hudScale, SpriteEffects.None, 0); spriteBatch.DrawString(RetroGame.FONT_PIXEL_SMALL, RetroGame.TotalPrisoners.ToString("000"), new Vector2(xPos + (HUD_TEXT_OFFSET * hudScale), yPos), Color.White, 0, Vector2.Zero, HUD_TEXT_SCALE * hudScale, SpriteEffects.None, 0); //store xPos = hudWidth * STORE_POSITION.X + HUD_INITIAL_POSITION; yPos = hudHeight * STORE_POSITION.Y; spriteBatch.Draw(storeIconTarget, new Vector2(xPos, yPos), null, Color.White, 0, Vector2.Zero, STORE_ICON_SCALE * hudScale, SpriteEffects.None, 0); //cell names xPos = hudWidth * CELL_OFFSETX + HUD_INITIAL_POSITION; yPos = hudHeight * CELL_YPOS; string cellName = Level.GetCellName(RetroGame.getHeroes()[0].levelX, RetroGame.getHeroes()[0].levelY); Vector2 nameDims = RetroGame.FONT_PIXEL_SMALL.MeasureString(cellName); float nameRatio = nameDims.Y / nameDims.X; float cellBorderWidthWithX = nameDims.X * modifiedScale * 0.8f; float cellBorderHeightWithX = cellBorderWidthWithX * nameRatio; float cellBorderHeightWithY = nameDims.Y * modifiedScale * 0.8f; float cellBorderWidthWithY = cellBorderHeightWithY / nameRatio; Vector2 cellBorderScale = new Vector2(((cellBorderWidthWithX + cellBorderWidthWithY) / 2) / cellBorderTex.Width, ((cellBorderHeightWithX + cellBorderHeightWithY) / 2) / cellBorderTex.Width); Vector2 nameScale = new Vector2(((cellBorderWidthWithX + cellBorderWidthWithY) * 0.85f / 2) / nameDims.X, ((cellBorderHeightWithX + cellBorderHeightWithY) * 0.85f / 2) / nameDims.Y); spriteBatch.Draw(cellBorderTex, new Vector2(xPos, yPos), null, Color.White, 0, new Vector2(cellBorderTex.Width / 2f, cellBorderTex.Height / 2f), cellBorderScale, SpriteEffects.None, 0); spriteBatch.DrawString(RetroGame.FONT_PIXEL_SMALL, cellName, new Vector2(xPos, yPos), Color.White, 0, nameDims / 2, nameScale, SpriteEffects.None, 0); if (RetroGame.NUM_PLAYERS == 2) { xPos = hudWidth * (1 - CELL_OFFSETX) + HUD_INITIAL_POSITION; yPos = hudHeight * CELL_YPOS; cellName = Level.GetCellName(RetroGame.getHeroes()[1].levelX, RetroGame.getHeroes()[1].levelY); nameDims = RetroGame.FONT_PIXEL_SMALL.MeasureString(cellName); nameRatio = nameDims.Y / nameDims.X; cellBorderWidthWithX = nameDims.X * modifiedScale * 0.8f; cellBorderHeightWithX = cellBorderWidthWithX * nameRatio; cellBorderHeightWithY = nameDims.Y * modifiedScale * 0.8f; cellBorderWidthWithY = cellBorderHeightWithY / nameRatio; cellBorderScale = new Vector2(((cellBorderWidthWithX + cellBorderWidthWithY) / 2) / cellBorderTex.Width, ((cellBorderHeightWithX + cellBorderHeightWithY) / 2) / cellBorderTex.Width); nameScale = new Vector2(((cellBorderWidthWithX + cellBorderWidthWithY) * 0.85f / 2) / nameDims.X, ((cellBorderHeightWithX + cellBorderHeightWithY) * 0.85f / 2) / nameDims.Y); spriteBatch.Draw(cellBorderTex, new Vector2(xPos, yPos), null, Color.White, 0, new Vector2(cellBorderTex.Width / 2f, cellBorderTex.Height / 2f), cellBorderScale, SpriteEffects.None, 0); spriteBatch.DrawString(RetroGame.FONT_PIXEL_SMALL, cellName, new Vector2(xPos, yPos), Color.White, 0, nameDims / 2, nameScale, SpriteEffects.None, 0); } //radar Hero heroWithRadar = null; foreach (Hero hero in RetroGame.getHeroes()) { if (hero.HasPowerup("Radar")) { heroWithRadar = hero; } } if (heroWithRadar != null) { ((RadarPowerup)heroWithRadar.GetPowerup("Radar")).DrawOnHUD(spriteBatch, hudScale); } if (showExclamation && exclamationStrings != null && exclamationStrings.Length > 0) { float exclamationScale = (hudScale + 1.25f) / 2; float space = FONT_EXCLAMATION.MeasureString(" ").X; string fullString = ""; foreach (string s in exclamationStrings) { fullString += s + " "; } fullString = fullString.Trim(); Vector2 fullDimensions = FONT_EXCLAMATION.MeasureString(fullString); float initialPos = (screenSize.X - fullDimensions.X * exclamationScale) / 2; float offset = 0; for (int i = 0; i < exclamationStrings.Length; i++) { string s = exclamationStrings[i]; Color c = exclamationColors[i]; float stringWidth = FONT_EXCLAMATION.MeasureString(s).X; spriteBatch.DrawString(FONT_EXCLAMATION, s, new Vector2(initialPos + offset, (screenSize.Y * 0.8f - fullDimensions.Y * exclamationScale) / 2), c, 0, Vector2.Zero, exclamationScale, SpriteEffects.None, 0); offset += (stringWidth + space) * exclamationScale; } } }
public void UpdateEscape(GameTime gameTime) { float seconds = gameTime.getSeconds(); //remove entities foreach (Collectable c in collectablesToRemove) { if (levels != null) { Level l = levels[c.levelX, c.levelY]; if (l != null && l.collectables != null) { if (c is Prisoner) { l.removePrisoner((Prisoner)c); } else if (c is PowerupIcon) { l.removePowerup((PowerupIcon)c); } else { l.collectables.Remove(c); } } } } collectablesToRemove.Clear(); foreach (Enemy e in enemiesToRemove) { foreach (Level l in levels) { if (l != null) { l.enemies.Remove(e); } } } enemiesToRemove.Clear(); foreach (Hero hero in heroes) { hero.Update(gameTime); } foreach (Level l in CurrentLevels) { l.UpdateEscape(gameTime); } bool levelChanged = false; foreach (Hero hero in heroes) { levelChanged |= hero.levelChanged; } if (levelChanged) { createAndRemoveLevels(); if (RetroGame.State == GameState.Arena) { RetroGame.EnterEscapeMode(); } } float mult = 0f; float currentZoomSpeed = Camera.zoomSpeed; #if DEBUG if (heroes[0].isDown(Keys.E)) { mult = 2.7f; } else if (heroes[0].isDown(Keys.R)) { mult = -2.7f; } Camera.targetZoom += Camera.zoomSpeed * mult * seconds; #endif if (mult != 0f) { currentZoomSpeed = 5 * Camera.zoomSpeed; } if (Camera.targetZoom - Camera.zoom > seconds * currentZoomSpeed) { Camera.zoom += currentZoomSpeed * seconds; } else if (Camera.targetZoom - Camera.zoom < -seconds * currentZoomSpeed) { Camera.zoom -= currentZoomSpeed * seconds; } else { Camera.zoom = Camera.targetZoom; } Camera.Update(gameTime); }
public bool attemptScroll(Entity entity, Vector2 offset) { Vector2 topEdge = (entity.getTop() + offset); Vector2 bottomEdge = (entity.getBottom() + offset); Vector2 leftEdge = entity.getLeft() + offset; Vector2 rightEdge = entity.getRight() + offset; Vector2 leadEdge = Vector2.Zero; Direction dir = Direction.None; if (offset.X < 0 && offset.X != 0) { dir = Direction.Left; leadEdge = leftEdge; } else if (offset.X > 0 && offset.X != 0) { dir = Direction.Right; leadEdge = rightEdge; } else if (offset.Y < 0 && offset.Y != 0) { dir = Direction.Up; leadEdge = topEdge; } else if (offset.Y > 0 && offset.Y != 0) { dir = Direction.Down; leadEdge = bottomEdge; } int x = (int)leadEdge.X; int y = (int)leadEdge.Y; if (x <= 0 || y <= 0) { return(false); } int levelX = x / Level.TEX_SIZE; // get which level you are going to int levelY = y / Level.TEX_SIZE; if (levelX >= MAX_LEVELS || levelY >= MAX_LEVELS) { return(false); } Level level = RetroGame.getLevels()[levelX, levelY]; if (level == null) { return(false); } int tileX = (x % Level.TEX_SIZE) / Level.TILE_SIZE; // get which tile you are moving to int tileY = (y % Level.TEX_SIZE) / Level.TILE_SIZE; LevelContent.LevelTile tile = level.grid[tileX, tileY]; if (tile == LevelContent.LevelTile.Wall) { return(false); } else if (entity is Enemy && level.enemyGrid[tileX, tileY] != null && level.enemyGrid[tileX, tileY] != entity) { return(false); } return(true); }
public static void Initialize(bool resetScoresToDefault = false) { if (oldHighscoresSolo == null || resetScoresToDefault) { oldHighscoresSolo = new List <HeroHighscore>(5) { new HeroHighscore { id = 999, name = "JeffZero", color = Color.CornflowerBlue, score = 1000000 }, new HeroHighscore { id = 712, name = "RPGlord", color = Color.Chartreuse, score = 500000 }, new HeroHighscore { id = 21, name = "tyder21", color = Color.Purple, score = 250000 }, new HeroHighscore { id = 100, name = "BIGPUN", color = Color.Red, score = 100000 }, new HeroHighscore { id = 2, name = "ngirl", color = Color.Aquamarine, score = 50000 }, }; } if (oldHighscoresCoop == null || resetScoresToDefault) { oldHighscoresCoop = new List <HeroHighscoreCoop>(5) { new HeroHighscoreCoop { id1 = 1337, name1 = "Fool", color1 = Color.Firebrick, score = 1000000, id2 = 6969, name2 = "FAH", color2 = Color.Indigo }, new HeroHighscoreCoop { id1 = 2196, name1 = "Santa", color1 = Color.Coral, score = 500000, id2 = 0909, name2 = "Natwaf", color2 = Color.Crimson }, new HeroHighscoreCoop { id1 = 13, name1 = "XIII", color1 = Color.DeepPink, score = 250000, id2 = 964, name2 = "LotM", color2 = Color.SlateBlue }, new HeroHighscoreCoop { id1 = 8523, name1 = "Vlado", color1 = Color.Gold, score = 100000, id2 = 4444, name2 = "Cishir", color2 = Color.Purple }, new HeroHighscoreCoop { id1 = 1988, name1 = "Adam", color1 = Color.Gray, score = 50000, id2 = 101, name2 = "Koala", color2 = Color.Sienna }, }; } highscoresSolo = new List <HeroHighscore>(oldHighscoresSolo); highscoresCoop = new List <HeroHighscoreCoop>(oldHighscoresCoop); currentHighscorePosition = HIGHSCORE_COUNT; if (RetroGame.NUM_PLAYERS == 1) { currentSoloHighscore = new HeroHighscore(RetroGame.getHeroes()[0]); for (int i = 0; i < HIGHSCORE_COUNT; i++) //check for existing highscore for these players { if (currentSoloHighscore.id == highscoresSolo[i].id && currentSoloHighscore.name == highscoresSolo[i].name && currentSoloHighscore.color == highscoresSolo[i].color) { highscoresSolo[i] = currentSoloHighscore; currentHighscorePosition = i; break; } } } else if (RetroGame.NUM_PLAYERS == 2) { currentCoopHighscore = new HeroHighscoreCoop(RetroGame.getHeroes()[0], RetroGame.getHeroes()[1]); for (int i = 0; i < HIGHSCORE_COUNT; i++) //check for existing highscore for these players { if (currentCoopHighscore.id1 == highscoresCoop[i].id1 && currentCoopHighscore.name1 == highscoresCoop[i].name1 && currentCoopHighscore.color1 == highscoresCoop[i].color1 && currentCoopHighscore.id2 == highscoresCoop[i].id2 && currentCoopHighscore.name2 == highscoresCoop[i].name2 && currentCoopHighscore.color2 == highscoresCoop[i].color2) { highscoresCoop[i] = currentCoopHighscore; currentHighscorePosition = i; break; } } } }