Added simple pause mechanism.
This commit is contained in:
parent
00b2670cfc
commit
c01f5d511d
@ -51,13 +51,16 @@ namespace SkinnerBox.States
|
|||||||
private List<DownloadEntity> activeDownloads = new List<DownloadEntity>();
|
private List<DownloadEntity> activeDownloads = new List<DownloadEntity>();
|
||||||
private DownloadSpawnInfo downloadSpawnInfo;
|
private DownloadSpawnInfo downloadSpawnInfo;
|
||||||
private const float downloadSafeMargin = 1.5f;
|
private const float downloadSafeMargin = 1.5f;
|
||||||
#endregion
|
|
||||||
|
|
||||||
//DDOS entities.
|
//DDOS entities.
|
||||||
private ObjectPool<DDOSEntity> ddosPool;
|
private ObjectPool<DDOSEntity> ddosPool;
|
||||||
private List<DDOSEntity> activeDDOS = new List<DDOSEntity>();
|
private List<DDOSEntity> activeDDOS = new List<DDOSEntity>();
|
||||||
private DDOSSPawnInfo dDOSSpawnInfo;
|
private DDOSSPawnInfo dDOSSpawnInfo;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region PauseManagement
|
||||||
|
bool paused = false;
|
||||||
|
#endregion
|
||||||
#region PlayerStats
|
#region PlayerStats
|
||||||
private int speedBoost = 0;
|
private int speedBoost = 0;
|
||||||
private int bandwithBoost = 0;
|
private int bandwithBoost = 0;
|
||||||
@ -113,6 +116,8 @@ namespace SkinnerBox.States
|
|||||||
|
|
||||||
this.font.PixelHeight = 32;
|
this.font.PixelHeight = 32;
|
||||||
font.PrepareCharacterGroup("Score:0123456789Uptim.%".ToCharArray());
|
font.PrepareCharacterGroup("Score:0123456789Uptim.%".ToCharArray());
|
||||||
|
this.font.PixelHeight = 64;
|
||||||
|
font.PrepareCharacterGroup("Paused...".ToCharArray());
|
||||||
|
|
||||||
activePackets.Clear();
|
activePackets.Clear();
|
||||||
activeWarnings.Clear();
|
activeWarnings.Clear();
|
||||||
@ -162,11 +167,21 @@ namespace SkinnerBox.States
|
|||||||
CalculateScaleFactors(vw, vh);
|
CalculateScaleFactors(vw, vh);
|
||||||
|
|
||||||
WindowContextsManager.CurrentWindowContext.resizeEvent += WindowResize;
|
WindowContextsManager.CurrentWindowContext.resizeEvent += WindowResize;
|
||||||
|
WindowContextsManager.CurrentWindowContext.focusGainedEvent += Focused;
|
||||||
|
WindowContextsManager.CurrentWindowContext.focusLostEvent += UnFocused;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render(double delta)
|
public void Render(double delta)
|
||||||
{
|
{
|
||||||
renderer.Begin(Matrix4x4.Identity, delta);
|
renderer.Begin(Matrix4x4.Identity, delta);
|
||||||
|
#region PauseHandling
|
||||||
|
if (paused) {
|
||||||
|
font.PixelHeight = 64;
|
||||||
|
font.WriteLine(renderer, Game.WIDTH_UNITS / 2f - 1f, Game.HEIGHT_UNITS / 2f, "Paused.", Color.Purple);
|
||||||
|
renderer.End();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
#region WarningRender
|
#region WarningRender
|
||||||
foreach (WarningEntity warn in activeWarnings)
|
foreach (WarningEntity warn in activeWarnings)
|
||||||
{
|
{
|
||||||
@ -193,6 +208,7 @@ namespace SkinnerBox.States
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#region StatusRender
|
#region StatusRender
|
||||||
|
font.PixelHeight = 32;
|
||||||
for (int i = 0; i < bandwithBoost + speedBoost; i++)
|
for (int i = 0; i < bandwithBoost + speedBoost; i++)
|
||||||
{
|
{
|
||||||
if (i < bandwithBoost) {
|
if (i < bandwithBoost) {
|
||||||
@ -218,6 +234,10 @@ namespace SkinnerBox.States
|
|||||||
|
|
||||||
public void Update(double timeStep)
|
public void Update(double timeStep)
|
||||||
{
|
{
|
||||||
|
if (paused) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
timeElapsed.Value = (float)timeStep + timeElapsed.DesignatedValue;
|
timeElapsed.Value = (float)timeStep + timeElapsed.DesignatedValue;
|
||||||
score += (float) timeStep * 0.5f;
|
score += (float) timeStep * 0.5f;
|
||||||
#region ServerUpdate
|
#region ServerUpdate
|
||||||
@ -483,5 +503,13 @@ namespace SkinnerBox.States
|
|||||||
this.cursorWidthScale = Game.WIDTH_UNITS * (1f / width);
|
this.cursorWidthScale = Game.WIDTH_UNITS * (1f / width);
|
||||||
this.cursorHeightScale = Game.HEIGHT_UNITS * (1f / height);
|
this.cursorHeightScale = Game.HEIGHT_UNITS * (1f / height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Focused() {
|
||||||
|
this.paused = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnFocused() {
|
||||||
|
this.paused = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,7 +24,8 @@ namespace SkinnerBox.States
|
|||||||
MeshBatchRenderer renderer;
|
MeshBatchRenderer renderer;
|
||||||
BitmapFont titleFont, boldFont;
|
BitmapFont titleFont, boldFont;
|
||||||
RectangleMesh serverUnit;
|
RectangleMesh serverUnit;
|
||||||
|
private BitmapFont genericFont;
|
||||||
|
|
||||||
public bool Activate()
|
public bool Activate()
|
||||||
{
|
{
|
||||||
Keyboard.keyboardUpdateEvent += KeyInput;
|
Keyboard.keyboardUpdateEvent += KeyInput;
|
||||||
@ -45,6 +46,9 @@ namespace SkinnerBox.States
|
|||||||
|
|
||||||
public void Deinitialize()
|
public void Deinitialize()
|
||||||
{
|
{
|
||||||
|
titleFont.Dispose();
|
||||||
|
boldFont.Dispose();
|
||||||
|
genericFont.Dispose();
|
||||||
this.renderer.Dispose();
|
this.renderer.Dispose();
|
||||||
this.assets.UnloadAll();
|
this.assets.UnloadAll();
|
||||||
}
|
}
|
||||||
@ -71,7 +75,7 @@ namespace SkinnerBox.States
|
|||||||
this.titleFont = new BitmapFont("resources/BigShouldersDisplay-Regular.ttf", textureSizes: 512);
|
this.titleFont = new BitmapFont("resources/BigShouldersDisplay-Regular.ttf", textureSizes: 512);
|
||||||
this.titleFont.PixelsPerUnitHeight = 80;
|
this.titleFont.PixelsPerUnitHeight = 80;
|
||||||
this.titleFont.PixelsPerUnitWidth = 80;
|
this.titleFont.PixelsPerUnitWidth = 80;
|
||||||
BitmapFont genericFont = new BitmapFont("resources/BigShouldersDisplay-Light.ttf");
|
genericFont = new BitmapFont("resources/BigShouldersDisplay-Light.ttf");
|
||||||
genericFont.PixelsPerUnitHeight = 80;
|
genericFont.PixelsPerUnitHeight = 80;
|
||||||
genericFont.PixelsPerUnitWidth = 80;
|
genericFont.PixelsPerUnitWidth = 80;
|
||||||
//Add additional states
|
//Add additional states
|
||||||
|
@ -97,7 +97,7 @@ namespace SkinnerBox.States
|
|||||||
|
|
||||||
public void Deinitialize()
|
public void Deinitialize()
|
||||||
{
|
{
|
||||||
|
font.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getName()
|
public string getName()
|
||||||
|
Loading…
Reference in New Issue
Block a user