// draw method public void Draw(SpriteBatch spriteBatch, Character ch) { if (ch.Player == 1) { spriteBatch.Draw(healthBarSkin, new Rectangle((int)((1 - (ch.Health / ch.MaxHealth)) * HEALTHBAR_WIDTH), HEALTHBAR_Y, (int)((ch.Health / ch.MaxHealth) * HEALTHBAR_WIDTH + 5/* buffer*/), HEALTHBAR_HEIGHT), Color.White); } if (ch.Player == 2) { spriteBatch.Draw(healthBarSkin, new Rectangle(HEALTHBAR2_X, HEALTHBAR_Y, (int)((ch.Health / ch.MaxHealth) * HEALTHBAR_WIDTH), HEALTHBAR_HEIGHT), Color.White); } }
//checks to see if a character occupies the same space as projectile //collision detection public bool isColliding(Character cha) { if(isActive == true) { if (this.xPos == cha.XPos && this.yPos==cha.YPos) { isActive = false; return true; } else { return false; } } else { return false; } }
// constructor public HealthBar(Character ch, Texture2D skin) { healthBarSkin = skin; }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); // TODO: Add your update logic here kState = Keyboard.GetState(); if (gameState == GameState.IN_GAME) // gameState has to be 'active' for commands to register { switch (selector1.PlayerChar) // p1 { case CharacterType.IGNIS: // Ignis //Image char1Proj1.ProjSkin = ignisProj; // set later to ignis projectile //External Tool Values char1Proj1.Damage = ignisProjDmg; char1Proj1.FramesPerBlock = ignisFPB; break; case CharacterType.HANZO: // Hanzo //Image char1Proj1.ProjSkin = hanzoProj; // set later to hanzo projectile //External Tool Values char1Proj1.Damage = hanzoProjDmg; char1Proj1.FramesPerBlock = hanzoFPB; break; case CharacterType.STEVE: // Steve //Image char1Proj1.ProjSkin = steveProj; // set later to steve projectile //External Tool Values char1Proj1.Damage = steveProjDmg; char1Proj1.FramesPerBlock = steveFPB; break; } switch (selector2.PlayerChar) // p2 { case CharacterType.IGNIS: // Ignis //Image char2Proj1.ProjSkin = ignisProj; // set later to ignis projectile //External Tool Values char2Proj1.Damage = ignisProjDmg; char2Proj1.FramesPerBlock = ignisFPB;; break; case CharacterType.HANZO: // Hanzo //Image char2Proj1.ProjSkin = hanzoProj; // set later to hanzo projectile //External Tool Values char2Proj1.Damage = hanzoProjDmg; char2Proj1.FramesPerBlock = hanzoFPB; break; case CharacterType.STEVE: // Steve //Image char2Proj1.ProjSkin = steveProj; // set later to steve projectile //External Tool Values char2Proj1.Damage = steveProjDmg; char2Proj1.FramesPerBlock = steveFPB; break; } char1.Input(kState); char2.Input(kState); if (char1Proj1.isColliding(char2) == true) { Console.WriteLine(char1Proj1.Damage + " " + char2.Health); char2.takeDamage(char1Proj1.Damage); char2.Dazed = false; } if (char2Proj1.isColliding(char1) == true) { Console.WriteLine(char2Proj1.Damage + " " + char1.Health); char1.takeDamage(char2Proj1.Damage); char1.Dazed = false; } //Character Projectiles //Ignis //Flame's Wake if (igFireBall1.isColliding(char2) == true) { Console.WriteLine(igFireBall1.Damage + " " + char2.Health); char2.takeDamage(igFireBall1.Damage); char2.Dazed = false; } if (igFireBall2.isColliding(char1) == true) { Console.WriteLine(igFireBall2.Damage + " " + char1.Health); char1.takeDamage(igFireBall2.Damage); char1.Dazed = false; } //Stalking Flare if (igStalk1.isColliding(char2) == true) { Console.WriteLine(igStalk1.Damage + " " + char2.Health); char2.takeDamage(igStalk1.Damage); char2.Dazed = false; } if (igStalk2.isColliding(char1) == true) { Console.WriteLine(igStalk2.Damage + " " + char1.Health); char1.takeDamage(igStalk2.Damage); char1.Dazed = false; } //Explosive Blaze if (igBlaze1.isColliding(char2) == true) { Console.WriteLine(igBlaze1.Damage + " " + char2.Health); char2.takeDamage(igBlaze1.Damage); if (igBlaze1.YPos == igFireBall1.YPos || igBlaze1.YPos == igStalk1.YPos) { char2.Dazed = true; } } if (igBlaze2.isColliding(char1) == true) { Console.WriteLine(igBlaze2.Damage + " " + char1.Health); char1.takeDamage(igBlaze2.Damage); if (igBlaze2.YPos == igFireBall2.YPos || igBlaze2.YPos == igStalk2.YPos) { char1.Dazed = true; } } //Hanzo //Seeking Kunai if (hzSeeking1.isColliding(char2) == true) { Console.WriteLine(hzSeeking1.Damage + " " + char2.Health); char2.takeDamage(hzSeeking1.Damage); char2.Dazed = false; char1.CanSwing = true; } if (hzSeeking2.isColliding(char1) == true) { Console.WriteLine(hzSeeking2.Damage + " " + char1.Health); char1.takeDamage(hzSeeking2.Damage); char1.Dazed = false; char2.CanSwing = true; } //Sundering Strike if (hzSunder1.isColliding(char2) == true) { Console.WriteLine(hzSunder1.Damage + " " + char2.Health); if (char1.YPos == char2.YPos && char1.XPos == (char2.XPos - 1)) { char2.takeDamage(35); char2.Dazed = false; char1.CanSwing = false; } } if (hzSunder2.isColliding(char1) == true) { Console.WriteLine(hzSunder2.Damage + " " + char1.Health); if (char1.YPos == char2.YPos && char2.XPos == (char1.XPos + 1)) { char1.takeDamage(35); char1.Dazed = false; char2.CanSwing = false; } } //Death Sentence if (hzDeath1.isColliding(char2) == true) { Console.WriteLine(hzDeath1.Damage + " " + char2.Health); char2.takeDamage(hzDeath1.Damage); char2.Dazed = true; char2.XPos = 4; char1.CanSwing = true; } if (hzDeath2.isColliding(char1) == true) { Console.WriteLine(hzDeath2.Damage + " " + char1.Health); char1.takeDamage(hzDeath2.Damage); char1.Dazed = true; char1.XPos = 3; char2.CanSwing = true; } //Steve //Voltaic Travesty if (stTrav1.isColliding(char2) == true) { Console.WriteLine(stTrav1.Damage + " " + char2.Health); char2.takeDamage(stTrav1.Damage); char2.Dazed = false; } if (stTrav2.isColliding(char1) == true) { Console.WriteLine(stTrav2.Damage + " " + char1.Health); char1.takeDamage(stTrav2.Damage); char1.Dazed = false; } //Dolt Bolt if (stDolt1.isColliding(char2) == true) { Console.WriteLine(stDolt1.Damage + " " + char2.Health); char2.takeDamage(stDolt1.Damage); char2.Dazed = false; } if (stDolt2.isColliding(char1) == true) { Console.WriteLine(stDolt2.Damage + " " + char1.Health); char1.takeDamage(stDolt2.Damage); char1.Dazed = false; } } if (gameState == GameState.MAIN_MENU) { if (kState.IsKeyDown(Keys.Enter)) // sets the gameState to character select { gameState = GameState.SELECT_SCREEN; } } if (gameState == GameState.SELECT_SCREEN) { // character select functionality selector1.CharacterSelect(kState); selector2.CharacterSelect(kState); if (kState.IsKeyDown(Keys.Space)) // sets the gameState to active { gameState = GameState.IN_GAME; // Player 1 character load if (selector1.PlayerChar == CharacterType.IGNIS) { char1 = new Ignis(0, 0, ignisHealth, 1, ignisSprite, char1Proj1, igFireBall1, igStalk1, igBlaze1); } else if (selector1.PlayerChar == CharacterType.HANZO) { char1 = new Hanzo(0, 0, hanzoHealth, 1, hanzoSprite, char1Proj1, hzSeeking1, hzSunder1, hzDeath1); } else if (selector1.PlayerChar == CharacterType.STEVE) { char1 = new Steve(0, 0, steveHealth, 1, steveSprite, char1Proj1, stTrav1, stDolt1); } // Player 2 character load if (selector2.PlayerChar == CharacterType.IGNIS) { char2 = new Ignis(7, 3, ignisHealth, 2, ignisSprite, char2Proj1, igFireBall2, igStalk2, igBlaze2); } else if (selector2.PlayerChar == CharacterType.HANZO) { char2 = new Hanzo(7, 3, hanzoHealth, 2, hanzoSprite, char2Proj1, hzSeeking2, hzSunder2, hzDeath2); } else if (selector2.PlayerChar == CharacterType.STEVE) { char2 = new Steve(7, 3, steveHealth, 2, steveSprite, char2Proj1, stTrav2, stDolt2); } } } // pause feature if (gameState == GameState.IN_GAME && kState.IsKeyDown(Keys.Tab) && canToggle == true) // if active and player presses tab, pause { canToggle = false; gameState = GameState.PAUSE_SCREEN; } if (gameState == GameState.PAUSE_SCREEN && kState.IsKeyDown(Keys.Tab) && canToggle == true) // if paused and player presses tab, unpause { canToggle = false; gameState = GameState.IN_GAME; } if (gameState == GameState.IN_GAME || gameState == GameState.PAUSE_SCREEN) { if (kState.IsKeyUp(Keys.Tab)) { canToggle = true; } } // win state if (gameState == GameState.IN_GAME && char1.Health <= 0) { gameState = GameState.WIN_SCREEN; } else if (gameState == GameState.IN_GAME && char2.Health <= 0) { gameState = GameState.WIN_SCREEN; } // reset function! if (gameState == GameState.WIN_SCREEN && kState.IsKeyDown(Keys.Space)) { gameState = GameState.MAIN_MENU; char1.Health = 1; char2.Health = 1; } base.Update(gameTime); }