-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameObjectManager.cs
166 lines (152 loc) · 5.94 KB
/
GameObjectManager.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
162
163
164
165
166
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Mario.Interfaces.GameObjects;
using Mario.Factory;
using Mario.CameraClasses;
using Mario.GameObjects.Block;
using Game1;
using Mario.Collision.CollisionManager;
using System.Diagnostics;
using Mario.EnemyClasses;
using Mario.EnemyStates.GoombaStates;
using Mario.HeadUpDesign;
using Mario.XMLRead;
using Mario.Display;
using Mario.Sprite;
using Microsoft.Xna.Framework.Media;
using Mario.Sound;
using Mario.Collections;
using System.Collections;
using Mario.ItemClasses;
using Mario.GameObjects;
namespace Mario
{
public class GameObjectManager
{
private static GameObjectManager instance = new GameObjectManager();
public static GameObjectManager Instance { get => instance; set => instance = value; }
private static IList<IController> ControllerList { get; set; }
private readonly GameObjectList gameObjectList;
public GameObjectList GameObjectList { get => gameObjectList; }
public IMario Mario { get { return (IMario)GameObjectList.Peek(typeof(IMario)); } set { GameObjectList.SetSingleton(typeof(IMario), value); } }
public ICamera CameraMario { get; set; }
public ICameraController CameraController { get; set; }
public IList<Rectangle> FloorBoxPositions { get; }
public GameTime CurrentGameTime { get; set; }
private HeadsUpDisplayBoard headUpDisplayBoard;
private IDisplay lifeDisplay;
private IDisplay gameOverDisplay;
public IList<ITextSprite> UITextSprites { get; }
public IList<ITextSprite> UIScoreSprite { get; }
public bool LifeDisplayTrigger { get; set; }
public float EndOfLevelXPosition { get; set; }
private int count = 0;
private GameObjectManager()
{
LifeDisplayTrigger = true;
gameObjectList = new GameObjectList();
ControllerList = new List<IController>
{
new Keyboards()
};
FloorBoxPositions = new List<Rectangle>();
UITextSprites = new List<ITextSprite>();
UIScoreSprite = new List<ITextSprite>();
}
public void SetInitialValuesCamera()
{
CameraMario = new Camera();
CameraController = new CameraController(CameraMario);
}
public void LoadContent()
{
ItemFactory.Instance.LoadContent(Game1.Instance.Content);
EnemyFactory.Instance.LoadContent(Game1.Instance.Content);
BackgroundFactory.Instance.LoadContent(Game1.Instance.Content);
ProjectileFactory.Instance.LoadContent(Game1.Instance.Content);
MarioFactory.Instance.LoadContent(Game1.Instance.Content);
TextSpriteFactory.Instance.LoadAllTextures(Game1.Instance.Content);
BlockFactory.Instance.LoadContent(Game1.Instance.Content);
gameObjectList.Initial();
LevelLoader.Instance.LoadFile("XMLFile2.xml");
foreach (IController controller in ControllerList)
{
controller.Initialize((IMario)GameObjectList.Peek(typeof(IMario)));
}
if (LifeCounter.Instance.Life == LifeUtil.minLife)
gameOverDisplay = new GameOverDisplay();
lifeDisplay = new LifeDisplay();
headUpDisplayBoard = new HeadsUpDisplayBoard();
Timer.StopTimer();
count = 0;
}
public void Update()
{
foreach (IController controller in ControllerList)
{
controller.Update();
}
if (!Game1.Instance.IsPause)
{
IEnumerator gameObjEnumerator = GameObjectList.GetEnumerator();
while (gameObjEnumerator.MoveNext())
{
if (!CameraMario.IsOffSideOfScreen(((IGameObject)gameObjEnumerator.Current).Box))
{
((IGameObject)gameObjEnumerator.Current).Update();
}
}
if (CameraMario.IsOffTopOrBottomOfScreen(Mario.Box))
{
Mario.BeDead();
LifeCounter.Instance.DecreaseLife();
SetInitialValuesCamera();
LoadContent();
Timer.ResetTimer();
SoundManager.StopSong();
}
CollisionDetector.Instance.Update();
CameraController.Update();
}
if (LifeCounter.Instance.LifeRemains() > LifeUtil.minLife)
{
lifeDisplay.Update();
if (count == 100) {
SoundManager.Instance.PlayBGM(SoundString.marioBGM);
Timer.StartTimer();
}
}
else if (LifeCounter.Instance.LifeRemains() == LifeUtil.minLife)
{
gameOverDisplay.Update();
}
headUpDisplayBoard.Update();
FloatingScoreBar.Update();
FloatingTimeBar.Update();
ScoringSystem.Instance.SetMarioEnemyHitThisIterationToFalse();
count++;
}
public void Draw(SpriteBatch spriteBatch)
{
IEnumerator gameObjEnumerator = GameObjectList.GetEnumerator();
while (gameObjEnumerator.MoveNext())
{
((IGameObject)gameObjEnumerator.Current).Draw(spriteBatch);
}
if (LifeCounter.Instance.LifeRemains() > LifeUtil.minLife)
{
lifeDisplay.Draw(spriteBatch);
}
else if (LifeCounter.Instance.LifeRemains() == LifeUtil.minLife)
{
gameOverDisplay.Draw(spriteBatch);
}
headUpDisplayBoard.Draw(spriteBatch);
FloatingScoreBar.Draw(spriteBatch);
FloatingTimeBar.Draw(spriteBatch);
}
}
}