2 using System.Collections.Generic;
3 using System.Diagnostics;
6 using FBLibrary.Core.BaseEntities;
7 using FBClient.Controls;
9 using FBClient.Core.Entities;
10 using FBClient.Entities;
11 using FBClient.Screens;
12 using FBClient.Screens.GameScreens;
13 using FBClient.Sprites;
14 using FBClient.TileEngine;
15 using FBClient.WorldEngine;
16 using Microsoft.Xna.Framework;
17 using Microsoft.Xna.Framework.Audio;
18 using Microsoft.Xna.Framework.Graphics;
20 namespace FBClient.Entities
31 private bool _cellTeleporting;
32 private float _invincibleBlinkFrequency;
33 private TimeSpan _invincibleBlinkTimer;
38 private SoundEffect _playerDeathSound;
42 #region Property Region
46 #region Constructor Region
62 private void Initiliaze()
66 _invincibleBlinkFrequency = Config.InvincibleBlinkFrequency;
67 _invincibleBlinkTimer = TimeSpan.FromSeconds(_invincibleBlinkFrequency);
70 #region XNA Method Region
74 const int animationFramesPerSecond = 10;
75 var animations =
new Dictionary<AnimationKey, Animation>();
77 var animation =
new Animation(4, 23, 23, 0, 0, animationFramesPerSecond);
78 animations.Add(AnimationKey.Down, animation);
80 animation =
new Animation(4, 23, 23, 0, 23, animationFramesPerSecond);
81 animations.Add(AnimationKey.Left, animation);
83 animation =
new Animation(4, 23, 23, 0, 46, animationFramesPerSecond);
84 animations.Add(AnimationKey.Right, animation);
86 animation =
new Animation(4, 23, 23, 0, 69, animationFramesPerSecond);
87 animations.Add(AnimationKey.Up, animation);
89 var spriteTexture = FinalBomber.Instance.Content.Load<Texture2D>(
"Graphics/Characters/player1");
92 Sprite.ChangeFramesPerSecond(animationFramesPerSecond);
94 var playerDeathTexture = FinalBomber.Instance.Content.Load<Texture2D>(
"Graphics/Characters/player1Death");
95 animation =
new Animation(8, 23, 23, 0, 0, 4);
96 _playerDeathAnimation =
new AnimatedSprite(playerDeathTexture, animation)
102 _playerDeathSound = FinalBomber.Instance.Content.Load<SoundEffect>(
"Audio/Sounds/playerDeath");
105 public virtual void Update(GameTime gameTime,
Map map,
int[,] hazardMap)
107 if (IsAlive && !InDestruction)
109 PreviousDirection = CurrentDirection;
111 Sprite.Update(gameTime);
113 #region Invincibility
115 if (!GameConfiguration.Invincible && IsInvincible)
117 if (InvincibleTimer >= TimeSpan.Zero)
119 if (_invincibleBlinkTimer >= TimeSpan.Zero)
120 _invincibleBlinkTimer -= gameTime.ElapsedGameTime;
122 _invincibleBlinkTimer = TimeSpan.FromSeconds(_invincibleBlinkFrequency);
130 Move(gameTime, map, hazardMap);
138 if (Config.PlayerCanPush)
142 Point direction = Point.Zero;
143 switch (CurrentDirection)
145 case LookDirection.Up:
146 direction =
new Point(CellPosition.X, CellPosition.Y - 1);
148 case LookDirection.Down:
149 direction =
new Point(CellPosition.X, CellPosition.Y + 1);
151 case LookDirection.Left:
152 direction =
new Point(CellPosition.X - 1, CellPosition.Y);
154 case LookDirection.Right:
155 direction =
new Point(CellPosition.X + 1, CellPosition.Y);
158 Bomb bomb = BombAt(direction);
160 bomb.ChangeDirection(CurrentDirection, Id);
187 else if (InDestruction)
189 _playerDeathAnimation.Update(gameTime);
193 #region Edge wall gameplay
256 public void Draw(GameTime gameTime)
258 var playerNamePosition =
new Vector2(
261 Position.Y + Engine.Origin.Y - 25 -
262 ControlManager.SpriteFont.MeasureString(Name).Y / 2);
264 if ((IsAlive && !InDestruction) || OnEdge)
268 if (_invincibleBlinkTimer > TimeSpan.FromSeconds(_invincibleBlinkFrequency * 0.5f))
270 Sprite.Draw(gameTime, FinalBomber.Instance.SpriteBatch, Position);
271 FinalBomber.Instance.SpriteBatch.DrawString(ControlManager.SpriteFont, Name,
278 Sprite.Draw(gameTime, FinalBomber.Instance.SpriteBatch, Position);
279 FinalBomber.Instance.SpriteBatch.DrawString(ControlManager.SpriteFont, Name, playerNamePosition,
285 _playerDeathAnimation.Draw(gameTime, FinalBomber.Instance.SpriteBatch, Position);
286 FinalBomber.Instance.SpriteBatch.DrawString(ControlManager.SpriteFont, Name, playerNamePosition,
293 #region Method Region
295 #region Private Method Region
297 private Bomb BombAt(Point cell)
299 if (cell.X >= 0 && cell.Y >= 0 &&
307 Bomb bomb = FinalBomber.Instance.GamePlayScreen.BombList.Find(b => b.CellPosition == cell);
313 private void Invincibility()
316 _invincibleBlinkFrequency = Config.InvincibleBlinkFrequency;
317 _invincibleBlinkTimer = TimeSpan.FromSeconds(_invincibleBlinkFrequency);
322 #region Protected Method Region
324 protected virtual void Move(GameTime gameTime,
Map map,
int[,] hazardMap)
327 ComputeWallCollision(map);
332 #region Update player's position
334 if (IsChangingCell())
336 if (map.
Board[PreviousCellPosition.X, PreviousCellPosition.Y] ==
this)
338 map.Board[PreviousCellPosition.X, PreviousCellPosition.Y] = null;
341 if (_cellTeleporting)
342 _cellTeleporting =
false;
346 if (map.
Board[CellPosition.X, CellPosition.Y] == null)
348 map.Board[CellPosition.X, CellPosition.Y] =
this;
357 var deltaTime = (float)TimeSpan.FromTicks(GameConfiguration.DeltaTime).TotalSeconds;
358 float speedValue = (
Speed * deltaTime);
364 #region Override Method Region
370 Sprite.IsAnimating =
false;
371 InDestruction =
true;
372 _playerDeathSound.Play();
373 _playerDeathAnimation.IsAnimating =
true;
379 _playerDeathAnimation.IsAnimating =
false;
380 InDestruction =
false;
385 if (Config.MapSize.X - CellPosition.X < Config.MapSize.X / 2)
387 Sprite.CurrentAnimation = AnimationKey.Left;
393 Sprite.CurrentAnimation = AnimationKey.Right;
394 Position =
new Vector2(0, Position.Y);
410 Sprite.IsAnimating =
true;
411 InDestruction =
false;
413 Sprite.CurrentAnimation = AnimationKey.Down;
414 _playerDeathAnimation.IsAnimating =
false;
421 PreviousDirection = CurrentDirection;
423 Debug.Print(
"New look direction: " + (
LookDirection)newLookDirection);
428 return TimeSpan.FromTicks(GameConfiguration.DeltaTime).Milliseconds;
437 foreach (
Player player
in this)
439 if (player.
Id == playerID)
void Draw(GameTime gameTime)
Player(int id, PlayerStats stats)
virtual void MoveFromEdgeWall()
virtual void Move(GameTime gameTime, Map map, int[,] hazardMap)
static SpriteFont SpriteFont
Player GetPlayerByID(int playerID)
virtual void Update(GameTime gameTime, Map map, int[,] hazardMap)
static FinalBomber Instance
virtual void ChangeLookDirection(byte newLookDirection)
override float GetMovementSpeed()
void Rebirth(Vector2 position)
void UpdatePlayerPosition(Map map)
readonly GamePlayScreen GamePlayScreen