Final-Bomber  0.1
Bomberman/Dynablaster remake in C# using XNA.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Pages
Arrow.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using FBLibrary.Core;
3 using FBClient.Sprites;
4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Graphics;
6 
7 namespace FBClient.Core.Entities
8 {
9  public class Arrow : DynamicEntity
10  {
11  #region Field Region
12 
13  private readonly LookDirection _lookDirection;
14  private bool _isAlive;
15  public AnimatedSprite Sprite { get; protected set; }
16 
17  #endregion
18 
19  #region Property Region
20 
21  #endregion
22 
23  #region Constructor Region
24 
25  public Arrow(Point position, LookDirection initialLookDirection)
26  {
27  _isAlive = true;
28  _lookDirection = initialLookDirection;
29  }
30 
31  #endregion
32 
33  #region XNA Method Region
34 
35  public void LoadContent()
36  {
37  const int animationFramesPerSecond = 10;
38  var animations = new Dictionary<AnimationKey, Animation>();
39 
40  var animation = new Animation(1, 32, 32, 0, 0, animationFramesPerSecond);
41  animations.Add(AnimationKey.Down, animation);
42 
43  animation = new Animation(1, 32, 32, 0, 32, animationFramesPerSecond);
44  animations.Add(AnimationKey.Left, animation);
45 
46  animation = new Animation(1, 32, 32, 0, 64, animationFramesPerSecond);
47  animations.Add(AnimationKey.Right, animation);
48 
49  animation = new Animation(1, 32, 32, 0, 96, animationFramesPerSecond);
50  animations.Add(AnimationKey.Up, animation);
51 
52  var spriteTexture = FinalBomber.Instance.Content.Load<Texture2D>("Graphics/Characters/arrow");
53 
54  Sprite = new AnimatedSprite(spriteTexture, animations)
55  {
56  IsAnimating = true,
57  CurrentAnimation = LookDirectionToAnimationKey(_lookDirection)
58  };
59  }
60 
61  public void Update(GameTime gameTime)
62  {
63  Sprite.Update(gameTime);
64  }
65 
66  public void Draw(GameTime gameTime)
67  {
68  Sprite.Draw(gameTime, FinalBomber.Instance.SpriteBatch, Position);
69  }
70 
71  #endregion
72 
73  #region Private Method Region
74 
75  private AnimationKey LookDirectionToAnimationKey(LookDirection lookDirection)
76  {
77  var animationKey = AnimationKey.Up;
78  switch (lookDirection)
79  {
80  case LookDirection.Up:
81  animationKey = AnimationKey.Up;
82  break;
83  case LookDirection.Down:
84  animationKey = AnimationKey.Down;
85  break;
86  case LookDirection.Right:
87  animationKey = AnimationKey.Right;
88  break;
89  case LookDirection.Left:
90  animationKey = AnimationKey.Left;
91  break;
92  }
93  return animationKey;
94  }
95 
96  #endregion
97 
98  #region Public Method Region
99 
100  public void ChangeDirection(Bomb bomb)
101  {
102  Point nextPosition = bomb.CellPosition;
103  switch (_lookDirection)
104  {
105  case LookDirection.Up:
106  nextPosition.Y--;
107  break;
108  case LookDirection.Down:
109  nextPosition.Y++;
110  break;
111  case LookDirection.Left:
112  nextPosition.X--;
113  break;
114  case LookDirection.Right:
115  nextPosition.X++;
116  break;
117  }
118 
119  if (
120  !FinalBomber.Instance.GamePlayScreen.World.Levels[FinalBomber.Instance.GamePlayScreen.World.CurrentLevel
121  ].
122  CollisionLayer[nextPosition.X, nextPosition.Y])
123  {
124  bomb.ChangeDirection(_lookDirection, -1);
125  //bomb.ChangeSpeed(bomb.Speed + Config.BombSpeedIncrementeur);
126  bomb.ResetTimer();
127  }
128  }
129 
130  #endregion
131 
132  #region Override Method Region
133 
134  public override void Destroy()
135  {
136  }
137 
138  public override void Remove()
139  {
140  _isAlive = false;
141  }
142 
143  #endregion
144  }
145 }
void Update(GameTime gameTime)
Definition: Arrow.cs:61
override void Remove()
Definition: Arrow.cs:138
Arrow(Point position, LookDirection initialLookDirection)
Definition: Arrow.cs:25
void ChangeDirection(Bomb bomb)
Definition: Arrow.cs:100
override void Destroy()
Definition: Arrow.cs:134
static FinalBomber Instance
Definition: FinalBomber.cs:17
void Draw(GameTime gameTime)
Definition: Arrow.cs:66
readonly GamePlayScreen GamePlayScreen
Definition: FinalBomber.cs:66