Final-Bomber  0.1
Bomberman/Dynablaster remake in C# using XNA.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Pages
PowerUp.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using FBLibrary.Core;
3 using FBLibrary.Core.BaseEntities;
4 using FBClient.Entities;
5 using FBClient.Screens;
6 using FBClient.Screens.GameScreens;
7 using FBClient.Sprites;
8 using Microsoft.Xna.Framework;
9 using Microsoft.Xna.Framework.Audio;
10 using Microsoft.Xna.Framework.Graphics;
11 
12 namespace FBClient.Core.Entities
13 {
14 
15 
16  public class PowerUp : BasePowerUp
17  {
18  #region Field Region
19 
20  // Graphics
21  private AnimatedSprite _itemDestroyAnimation;
22  public AnimatedSprite Sprite { get; protected set; }
23 
24  // Sounds
25  private SoundEffect _powerUpPickUpSound;
26 
27  #endregion
28 
29  #region Constructor Region
30 
31  public PowerUp(Point cellPosition)
32  : base(cellPosition)
33  {
34  Initialize();
35  }
36 
37  public PowerUp(Point cellPosition, PowerUpType type) : base(cellPosition)
38  {
39  Type = type;
40  Initialize();
41  }
42 
43  #endregion
44 
45  private void Initialize()
46  {
47  var animations = new Dictionary<AnimationKey, Animation>();
48  var animation = new Animation(2, 32, 32, 0, Config.ItemTypeIndex[Type] * 32, 5);
49 
50  var spriteTexture = FinalBomber.Instance.Content.Load<Texture2D>("Graphics/Characters/item");
51  Sprite = new AnimatedSprite(spriteTexture, animation) { IsAnimating = true };
52 
53  var itemDestroyTexture = FinalBomber.Instance.Content.Load<Texture2D>("Graphics/Characters/itemDestroy");
54  animation = new Animation(7, 31, 28, 0, 0, 8);
55  _itemDestroyAnimation = new AnimatedSprite(itemDestroyTexture, animation)
56  {
57  IsAnimating = false
58  };
59 
60  // Sounds
61  _powerUpPickUpSound = FinalBomber.Instance.Content.Load<SoundEffect>("Audio/Sounds/item");
62  }
63 
64  #region XNA Method Region
65 
66  public void Update(GameTime gameTime)
67  {
68  Sprite.Update(gameTime);
69 
70  if (InDestruction)
71  {
72  _itemDestroyAnimation.Update(gameTime);
73  }
74 
75  base.Update();
76  }
77 
78  public void Draw(GameTime gameTime)
79  {
80  Sprite.Draw(gameTime, FinalBomber.Instance.SpriteBatch, Position);
81 
82  if (_itemDestroyAnimation.IsAnimating)
83  _itemDestroyAnimation.Draw(gameTime, FinalBomber.Instance.SpriteBatch, Position);
84  }
85 
86  #endregion
87 
88  #region Method Region
89 
90  public override void PickUp()
91  {
92  _powerUpPickUpSound.Play();
93 
94  base.PickUp();
95  }
96 
97  public override void Destroy()
98  {
99  if (!_itemDestroyAnimation.IsAnimating)
100  {
101  InDestruction = true;
102  _itemDestroyAnimation.IsAnimating = true;
103  }
104  }
105 
106  public override void Remove()
107  {
108  IsAlive = false;
109  }
110 
111  #endregion
112  }
113 }
override void PickUp()
Definition: PowerUp.cs:90
override void Destroy()
Definition: PowerUp.cs:97
PowerUp(Point cellPosition, PowerUpType type)
Definition: PowerUp.cs:37
void Draw(GameTime gameTime)
Definition: PowerUp.cs:78
override void Remove()
Definition: PowerUp.cs:106
void Update(GameTime gameTime)
Definition: PowerUp.cs:66
PowerUp(Point cellPosition)
Definition: PowerUp.cs:31