Final-Bomber  0.1
Bomberman/Dynablaster remake in C# using XNA.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Pages
Teleporter.cs
Go to the documentation of this file.
1 using FBLibrary.Core;
2 using FBClient.Screens;
3 using FBClient.Screens.GameScreens;
4 using FBClient.Sprites;
5 using FBClient.WorldEngine;
6 using Microsoft.Xna.Framework;
7 using Microsoft.Xna.Framework.Graphics;
8 
9 namespace FBClient.Core.Entities
10 {
11  public class Teleporter : BaseEntity
12  {
13  #region Field Region
14 
15  private bool _isAlive;
16  public AnimatedSprite Sprite { get; protected set; }
17 
18  #endregion
19 
20  #region Property Region
21 
22  public bool IsAlive
23  {
24  get { return _isAlive; }
25  }
26 
27  #endregion
28 
29  #region Constructor Region
30 
31  public Teleporter(Point cellPosition)
32  : base(cellPosition)
33  {
34  var spriteTexture = FinalBomber.Instance.Content.Load<Texture2D>("Graphics/Characters/teleporter");
35  var animation = new Animation(2, 32, 32, 0, 0, 2);
36  Sprite = new AnimatedSprite(spriteTexture, animation) { IsAnimating = true };
37 
38  _isAlive = true;
39  }
40 
41  #endregion
42 
43  #region XNA Method Region
44 
45  public void Update(GameTime gameTime)
46  {
47  Sprite.Update(gameTime);
48  }
49 
50  public void Draw(GameTime gameTime)
51  {
52  Sprite.Draw(gameTime, FinalBomber.Instance.SpriteBatch, Position);
53  }
54 
55  #endregion
56 
57  #region Public Method Region
58 
59  public void ChangeEntityPosition(DynamicEntity entity, Map map)
60  {
61  bool allTeleporterCellTaken = true;
62 
63  foreach (Teleporter t in map.TeleporterList)
64  {
65  Point position = t.CellPosition;
66  if (position != CellPosition && map.Board[position.X, position.Y] is Teleporter)
67  allTeleporterCellTaken = false;
68  }
69 
70  if (!allTeleporterCellTaken)
71  {
72  Point position = CellPosition;
73  while (position == CellPosition)
74  {
75  position = FinalBomber.Instance.GamePlayScreen.TeleporterList[
76  GamePlayScreen.Random.Next(FinalBomber.Instance.GamePlayScreen.TeleporterList.Count)].
77  CellPosition;
78  }
79 
80  var bomb = entity as Bomb;
81  if (bomb != null)
82  {
83  bomb.ChangeSpeed(bomb.Speed + Config.BombSpeedIncrementeur);
84  bomb.ResetTimer();
85  bomb.ChangePosition(position);
86  }
87  else
88  entity.ChangePosition(position);
89  }
90  }
91 
92  #endregion
93 
94  #region Override Method Region
95 
96  public override void Destroy()
97  {
98  }
99 
100  public override void Remove()
101  {
102  _isAlive = false;
103  }
104 
105  #endregion
106  }
107 }
void ChangeEntityPosition(DynamicEntity entity, Map map)
Definition: Teleporter.cs:59
void Draw(GameTime gameTime)
Definition: Teleporter.cs:50
Teleporter(Point cellPosition)
Definition: Teleporter.cs:31
void Update(GameTime gameTime)
Definition: Teleporter.cs:45