/
GameEntities.cs
executable file
·161 lines (132 loc) · 4.25 KB
/
GameEntities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using LunchHourGames.Players;
using LunchHourGames.Obstacles;
namespace LunchHourGames.Combat
{
public class GameEntities
{
private List<GameEntity> gameEntities = new List<GameEntity>();
private List<Player> players = new List<Player>();
private List<Obstacle> obstacles = new List<Obstacle>();
public void addPlayer(Player player)
{
players.Add(player);
gameEntities.Add(player);
}
public void removePlayer(Player player)
{
players.Remove(player);
gameEntities.Remove(player);
}
public List<Player> MyPlayers
{
get { return this.players; }
}
public void addObstacle(Obstacle obstacle)
{
obstacles.Add(obstacle);
gameEntities.Add(obstacle);
}
public void removeObstacle(Obstacle obstacle)
{
obstacles.Remove(obstacle);
gameEntities.Remove(obstacle);
}
public List<Obstacle> MyObstacles
{
get { return this.obstacles; }
}
public void Add(GameEntity gameEntity)
{
gameEntities.Add(gameEntity);
if (gameEntity.MyEntityType == GameEntity.EntityType.Player)
addPlayer((Player)gameEntity);
else if (gameEntity.MyEntityType == GameEntity.EntityType.Obstacle)
addObstacle((Obstacle)gameEntity);
}
public void Remove(GameEntity gameEntity)
{
if (gameEntity.MyEntityType == GameEntity.EntityType.Player)
removePlayer((Player)gameEntity);
else if (gameEntity.MyEntityType == GameEntity.EntityType.Obstacle)
removeObstacle((Obstacle)gameEntity);
}
public List<GameEntity> MyGameEntities
{
get { return this.gameEntities; }
}
public void clearAll()
{
players.Clear();
obstacles.Clear();
}
public void setGraphicsMatrices(Matrix view, Matrix projection, Matrix world)
{
foreach (GameEntity gameEntity in gameEntities)
{
gameEntity.setGraphicsMatrices(view, projection, world);
}
}
public Player moveToHumanControlledPlayer()
{
foreach (Player player in MyPlayers)
{
if (player.MyType == Player.Type.Human)
return player;
}
return null;
}
public List<Player> getPlayer(Player.Type type)
{
List<Player> typesOfPlayers = new List<Player>();
foreach (Player player in MyPlayers)
{
if (player.MyType == type)
typesOfPlayers.Add(player);
}
return typesOfPlayers;
}
public Player getPlayer(int id)
{
foreach (Player player in MyPlayers)
{
if (player.ID == id)
return player;
}
return null;
}
public Player findPlayerAtPoint(Point point)
{
foreach (Player player in MyPlayers)
{
Rectangle playerRect = player.getCurrentRectangle();
if (playerRect.Contains(point))
return player;
}
return null;
}
public GameEntity findGameEntityAtPoint(Point point)
{
foreach (GameEntity gameEntity in MyGameEntities)
{
Rectangle extents = gameEntity.getExtents();
if (extents.Contains(point))
return gameEntity;
}
return null;
}
public bool areAnyPlayersMoving()
{
foreach (Player player in MyPlayers)
{
if (player.IsMoving)
return true;
}
return false;
}
}
}