//Drawing Life and Coin status internal void Draw(float a_elapsedTime, SpriteBatch a_spriteBatch) { Vector2 pos = m_camera.VisualizeCordinates(10 + m_camera.GetScreenRectangle.X, 5); m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, pos, Model.State.ID.STATIC_ONE, AnimationSystem.Texture.EXTRA_LIFE); m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, pos + new Vector2(2, 40), Model.State.ID.STATIC_TWO, AnimationSystem.Texture.COIN); a_spriteBatch.DrawString(m_font, m_gameModel.Player.Life.ToString(), m_camera.VisualizeCordinates(55 + m_camera.GetScreenRectangle.X, 11), Color.YellowGreen); a_spriteBatch.DrawString(m_font, m_gameModel.Player.Coins.ToString(), m_camera.VisualizeCordinates(55 + m_camera.GetScreenRectangle.X, 48), Color.LightGoldenrodYellow); }
internal void DrawPlatforms(SpriteBatch a_spriteBatch, Model.TMXLevel a_level) { foreach (Model.MovingPlatform platform in a_level.MovingPlatforms.Where(x => x.GetPlatformArea.Intersects(m_camera.GetScreenRectangle))) { Vector2 position = m_camera.VisualizeCordinates(platform.GetPlatformArea.X, platform.GetPlatformArea.Y); a_spriteBatch.Draw(m_platform, position, Color.White); } }
//Metod för utritning av spelare private void DrawPlayer(float a_elapsedTime) { if (m_player.IsAlive()) { DrawWeapon(a_elapsedTime, m_player.UnitState, m_player.WeaponState, m_player); } else { m_player.UnitState = Model.Unit.IS_DEAD; } //Ritar spelare Vector2 playerPosition = m_camera.VisualizeCordinates(m_player.ThisUnit.Bounds.X, m_player.ThisUnit.Bounds.Y); m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, playerPosition, m_player.UnitState, AnimationSystem.PLAYER); //Börjat leka med armor. if (m_player.HasHelm) { DrawArmor(a_elapsedTime, m_player, m_player.UnitState, AnimationSystem.ARMOR_HEAD); } }
/// <summary> /// Method for drawing the player /// </summary> /// <param name="elapsedTime">Elapsed time in milleseconds</param> private void DrawPlayer(float elapsedTime) { if (_player.IsAlive()) { DrawWeapon(elapsedTime, _player.UnitState, _player.WeaponState, _player); } else { _player.UnitState = Model.State.IS_DEAD; } //Drawing player Vector2 playerPosition = _camera.VisualizeCordinates(_player.ThisUnit.Bounds.X, _player.ThisUnit.Bounds.Y); _animationSystem.UpdateAndDraw(elapsedTime, Color.White, playerPosition, _player.UnitState, AnimationSystem.Texture.PLAYER); //Armor if (_player.HasHelm) { DrawArmor(elapsedTime, _player, _player.UnitState, AnimationSystem.Texture.ARMOR_HEAD); } }
//Draw method internal void Draw(float a_elapsedTime, SpriteBatch m_spriteBatch) { #region Enemies foreach (Model.Enemy enemy in m_gameModel.Enemies) { //Visualizing coordinates Vector2 enemyPosition = m_camera.VisualizeCordinates(enemy.Obj.Bounds.X, enemy.Obj.Bounds.Y); if (enemy.IsAlive) { //Crawler if (enemy.EnemyType == Model.Enemy.Type.Crawler) { //Adjusting position enemyPosition = enemyPosition - new Vector2(9, 6); if (m_gameModel.TMXLevel.TriggerOneIsActive && enemy.UnitState == Model.State.ID.MOVING_RIGHT) { enemy.UnitState = Model.State.ID.FACING_RIGHT; } else if (m_gameModel.TMXLevel.TriggerOneIsActive && enemy.UnitState == Model.State.ID.MOVING_LEFT) { enemy.UnitState = Model.State.ID.FACING_LEFT; } m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, enemyPosition, enemy.UnitState, AnimationSystem.Texture.CRAWLER); } //Shooter else if (enemy.EnemyType == Model.Enemy.Type.Shooter) { m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, enemyPosition, enemy.UnitState, AnimationSystem.Texture.SHOOTER); } //Jumper else if (enemy.EnemyType == Model.Enemy.Type.Jumper) { enemyPosition = enemyPosition - new Vector2(12, 0); if (m_gameModel.TMXLevel.TriggerOneIsActive && enemy.UnitState == Model.State.ID.MOVING_LEFT) { m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, enemyPosition, Model.State.ID.FACING_LEFT, AnimationSystem.Texture.JUMPER); } else if (m_gameModel.TMXLevel.TriggerOneIsActive) { m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, enemyPosition, Model.State.ID.FACING_RIGHT, AnimationSystem.Texture.JUMPER); } else if (enemy.IsJumping && enemy.UnitState == Model.State.ID.MOVING_LEFT) { m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, enemyPosition, Model.State.ID.JUMPING_LEFT, AnimationSystem.Texture.JUMPER); } else if (enemy.IsJumping) { m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, enemyPosition, Model.State.ID.JUMPING_RIGHT, AnimationSystem.Texture.JUMPER); } else { m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, enemyPosition, enemy.UnitState, AnimationSystem.Texture.JUMPER); } } } else { //Drawing dead enemy animations AnimationSystem.Texture texture; if (enemy.UnitState == Model.State.ID.MOVING_RIGHT || enemy.UnitState == Model.State.ID.JUMPING_RIGHT || enemy.UnitState == Model.State.ID.FACING_RIGHT) { enemy.UnitState = Model.State.ID.IS_DEAD_RIGHT; } if (enemy.UnitState == Model.State.ID.MOVING_LEFT || enemy.UnitState == Model.State.ID.JUMPING_LEFT || enemy.UnitState == Model.State.ID.FACING_LEFT) { enemy.UnitState = Model.State.ID.IS_DEAD_LEFT; } if (enemy.EnemyType == Model.Enemy.Type.Crawler) { texture = AnimationSystem.Texture.CRAWLER; } else if (enemy.EnemyType == Model.Enemy.Type.Jumper) { texture = AnimationSystem.Texture.JUMPER; } else { texture = AnimationSystem.Texture.SHOOTER; } //Getting a decreasing float number in order to fade the animation float rbg = enemy.Visibility; m_animationSystem.UpdateAndDraw(a_elapsedTime, new Color(rbg, rbg, rbg, rbg), enemyPosition, enemy.UnitState, texture); } } //Drawing enemy projectiles int frameY = 0; foreach (Model.Projectile projectile in m_gameModel.Projectiles) { if (projectile.DirectionLeft) { frameY = 1; } else { frameY = 0; } if (m_camera.GetScreenRectangle.Contains(projectile.Rec)) { m_animationSystem.DrawMultibleAnimations(Color.White, m_camera.VisualizeCordinates(projectile.Rec.X, projectile.Rec.Y), frameY, AnimationSystem.Texture.SHOOT); } else { projectile.Active = false; } } if (!m_gameModel.TMXLevel.TriggerOneIsActive) { m_animationSystem.UpdateMultibleAnimations(a_elapsedTime, AnimationSystem.Texture.SHOOT, frameY); } #endregion #region Player //Visualizing player position Vector2 playerPosition = m_camera.VisualizeCordinates(m_gameModel.Player.Obj.Bounds.X - 22, m_gameModel.Player.Obj.Bounds.Y); //Drawing smoke @ player if powerup one is active if (m_gameModel.Player.PowerUpOneIsActive) { if (m_smokeSystem.SmokeWasReset) { m_smokeSystem.UpdateAndDraw(a_elapsedTime, playerPosition + new Vector2(40, 50), m_spriteBatch); } else { m_smokeSystem.LoadNewSmoke(); m_smokeSystem.SmokeWasReset = true; } } else { m_smokeSystem.SmokeWasReset = false; } //Getting a decreasing float number in order to fade the animation when the player gets hit float c = m_gameModel.Player.Visibility; m_animationSystem.UpdateAndDraw(a_elapsedTime, new Color(c, c, c, c), playerPosition, m_gameModel.Player.UnitState, AnimationSystem.Texture.AVATAR); #endregion }
//Drawing items and triggers internal void Draw(float a_elapsedTime, SpriteBatch a_spriteBatch) { #region Collectable Items & Triggers //Seperate updating calls for items m_animationSystem.UpdateMultibleAnimations(a_elapsedTime, AnimationSystem.Texture.COIN, 0); m_animationSystem.UpdateMultibleAnimations(a_elapsedTime, AnimationSystem.Texture.POWER_UP_ONE, 0); m_animationSystem.UpdateMultibleAnimations(a_elapsedTime, AnimationSystem.Texture.EXTRA_LIFE, 0); foreach (Vector4 item in m_level.GetItemsInRegion(m_camera.GetScreenRectangle)) { //Getting the items/triggers as a Vector4: position x, position y, visibility, type Vector2 pos = m_camera.VisualizeCordinates((int)item.X, (int)item.Y); float isVisible = item.W; float type = item.Z; //Coins if (isVisible == 1 && type == (int)Model.TMXLevel.ItemType.Coin) { m_animationSystem.DrawMultibleAnimations(Color.White, pos, 0, AnimationSystem.Texture.COIN); } //Power up one if (isVisible == 1 && type == (int)Model.TMXLevel.ItemType.PowerUpOne && !m_player.PowerUpOneIsActive) { pos = pos - new Vector2(16, 16); m_animationSystem.DrawMultibleAnimations(Color.White, pos, 0, AnimationSystem.Texture.POWER_UP_ONE); } //Extra life if (isVisible == 1 && type == (int)Model.TMXLevel.ItemType.ExtraLife) { pos = pos - new Vector2(4, 5); m_animationSystem.DrawMultibleAnimations(Color.White, pos, 0, AnimationSystem.Texture.EXTRA_LIFE); } //Trigger one if (isVisible == 1 && type == (int)Model.TMXLevel.ItemType.TriggerOne) { if (m_level.TriggerOneIsActive) { pos = pos - new Vector2(7, 20); m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, pos, Model.State.ID.STATIC_ONE, AnimationSystem.Texture.TRIGGER_ONE); } else { pos = pos - new Vector2(18, 20); m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, pos, Model.State.ID.STATIC_TWO, AnimationSystem.Texture.TRIGGER_ONE); } } //Triger two if (isVisible == 1 && type == (int)Model.TMXLevel.ItemType.TriggerTwo) { if (m_level.TriggerTwoIsActive) { pos = pos - new Vector2(7, 20); m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, pos, Model.State.ID.STATIC_ONE, AnimationSystem.Texture.TRIGGER_TWO); } else { pos = pos - new Vector2(18, 20); m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, pos, Model.State.ID.STATIC_TWO, AnimationSystem.Texture.TRIGGER_TWO); } } } #endregion #region MovementAids foreach (Vector4 item in m_level.GetMovmentAidsInRegion(m_camera.GetScreenRectangle)) { //Getting the MovementAid object as a Vector4: position x, position y, visibility, type Vector2 pos = m_camera.VisualizeCordinates((int)item.X - 10, (int)item.Y - 10); float isVisible = item.W; float type = item.Z; //Check if the player hits a trampoline if (m_player.SpeedY == 10) { m_trampolineWatch.Start(); } //Differentiate animation when triggered if (type == (int)Model.TMXLevel.MovementAidType.Trampoline && m_trampolineWatch.IsRunning && m_trampolineWatch.ElapsedMilliseconds < 1000) { m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, pos, Model.State.ID.STATIC_TWO, AnimationSystem.Texture.TRAMPOLINE); } else if (type == (int)Model.TMXLevel.MovementAidType.Trampoline) { m_trampolineWatch.Stop(); m_trampolineWatch.Reset(); m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, pos, Model.State.ID.STATIC_ONE, AnimationSystem.Texture.TRAMPOLINE); } } #endregion }