Final-Bomber  0.1
Bomberman/Dynablaster remake in C# using XNA.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Pages
Player.cs
Go to the documentation of this file.
1 using FBLibrary.Core;
2 using FBLibrary.Core.BaseEntities;
3 using Microsoft.Xna.Framework;
4 using System;
5 
6 namespace FBServer.Core
7 {
8  public class Player : BasePlayer
9  {
10  private TimeSpan _destructionTimer;
11 
12  private readonly Timer _tmrSendPos = new Timer(true);
13 
14  public Player(int id)
15  : base(id)
16  {
17  _destructionTimer = DestructionTime;
18  }
19 
20  public Player(int id, PlayerStats stats)
21  : base(id)
22  {
23  _destructionTimer = DestructionTime;
24  Stats = stats;
25  }
26 
27  public void SetMovement(LookDirection direction)
28  {
29  CurrentDirection = direction;
30  if (PreviousDirection == LookDirection.Idle && direction != LookDirection.Idle)
31  {
32  PreviousDirection = direction;
33  SendPosition();
34  }
35  }
36 
37 
38  public void MovePlayer(BaseMap map)
39  {
40  if (IsAlive)
41  {
42  IsMoving = true;
43  switch (CurrentDirection)
44  {
45  case LookDirection.Down:
46  Position += new Vector2(0, GetMovementSpeed());
47  break;
48  case LookDirection.Up:
49  Position += new Vector2(0, -GetMovementSpeed());
50  break;
51  case LookDirection.Left:
52  Position += new Vector2(-GetMovementSpeed(), 0);
53  break;
54  case LookDirection.Right:
55  Position += new Vector2(GetMovementSpeed(), 0);
56  break;
57  default:
58  IsMoving = false;
59  break;
60  }
61 
62  // If the player is moving
63  if (IsMoving)
64  {
65  ComputeWallCollision(map);
66  }
67 
68  if (CurrentDirection != PreviousDirection)
69  {
70  SendPosition();
71  }
72  else
73  {
74  if (_tmrSendPos.Each(ServerSettings.SendPlayerPositionTime))
75  SendPosition();
76  }
77 
78  if (InDestruction)
79  {
80  _destructionTimer -= TimeSpan.FromMilliseconds(GameSettings.Speed);
81 
82  if (_destructionTimer <= TimeSpan.Zero)
83  {
84  Remove();
85  }
86  }
87 
88  // Call Update method of DynamicEntity class
89  base.Update();
90 
91  PreviousDirection = CurrentDirection;
92  }
93  }
94 
95  private void SendPosition()
96  {
97  GameSettings.GameServer.SendPlayerPosition(this, false);
98  }
99 
100  protected override float GetMovementSpeed()
101  {
102  float rtn = (Speed * GameSettings.Speed) / 1000f;
103  return rtn;
104  }
105 
106  protected override int GetTime()
107  {
108  return GameSettings.Speed;
109  }
110 
111  public override void Destroy()
112  {
113  InDestruction = true;
114  }
115 
116  public override void Remove()
117  {
118  IsAlive = false;
119  }
120  }
121 }
override int GetTime()
Definition: Player.cs:106
override float GetMovementSpeed()
Definition: Player.cs:100
Player(int id, PlayerStats stats)
Definition: Player.cs:20
override void Remove()
Definition: Player.cs:116
Player(int id)
Definition: Player.cs:14
void MovePlayer(BaseMap map)
Definition: Player.cs:38
void SetMovement(LookDirection direction)
Definition: Player.cs:27
override void Destroy()
Definition: Player.cs:111