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 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 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 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; } } } }
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; } } }