|
|
@ -1,4 +1,5 @@ |
|
|
|
using Microsoft.Xna.Framework; |
|
|
|
using Microsoft.Xna.Framework.Audio; |
|
|
|
using Microsoft.Xna.Framework.Graphics; |
|
|
|
using System; |
|
|
|
|
|
|
@ -6,8 +7,6 @@ namespace SemiColinGames { |
|
|
|
class Scene : IDisposable { |
|
|
|
const float DESIRED_ASPECT_RATIO = 1920.0f / 1080.0f; |
|
|
|
|
|
|
|
public bool Enabled = false; |
|
|
|
|
|
|
|
Color backgroundColor = Color.CornflowerBlue; |
|
|
|
|
|
|
|
readonly GraphicsDevice graphics; |
|
|
@ -16,6 +15,12 @@ namespace SemiColinGames { |
|
|
|
readonly RenderTarget2D sceneTarget; |
|
|
|
readonly BasicEffect basicEffect; |
|
|
|
readonly SpriteBatch spriteBatch; |
|
|
|
readonly SoundEffectInstance music; |
|
|
|
|
|
|
|
// Draw() needs to be called without IsRunningSlowly this many times before we actually
|
|
|
|
// attempt to draw the scene. This is a workaround for the fact that otherwise the first few
|
|
|
|
// frames can be really slow to draw.
|
|
|
|
int framesToSuppress = 2; |
|
|
|
|
|
|
|
public Scene(GraphicsDevice graphics, Camera camera) { |
|
|
|
this.graphics = graphics; |
|
|
@ -32,6 +37,10 @@ namespace SemiColinGames { |
|
|
|
}; |
|
|
|
|
|
|
|
spriteBatch = new SpriteBatch(graphics); |
|
|
|
|
|
|
|
music = SoundEffects.IntroMusic.CreateInstance(); |
|
|
|
music.IsLooped = true; |
|
|
|
music.Volume = 0.1f; |
|
|
|
} |
|
|
|
|
|
|
|
~Scene() { |
|
|
@ -39,16 +48,22 @@ namespace SemiColinGames { |
|
|
|
} |
|
|
|
|
|
|
|
public void Dispose() { |
|
|
|
music.Stop(); |
|
|
|
music.Dispose(); |
|
|
|
sceneTarget.Dispose(); |
|
|
|
basicEffect.Dispose(); |
|
|
|
spriteBatch.Dispose(); |
|
|
|
GC.SuppressFinalize(this); |
|
|
|
} |
|
|
|
|
|
|
|
public void Draw(World world, Player player, LinesOfSight linesOfSight, bool paused) { |
|
|
|
public void Draw( |
|
|
|
bool isRunningSlowly, World world, Player player, LinesOfSight linesOfSight, bool paused) { |
|
|
|
graphics.SetRenderTarget(null); |
|
|
|
graphics.Clear(backgroundColor); |
|
|
|
if (!Enabled) { |
|
|
|
|
|
|
|
// Enable the scene after we've gotten enough non-slow frames.
|
|
|
|
if (framesToSuppress > 0 && !isRunningSlowly) { |
|
|
|
framesToSuppress--; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -110,6 +125,9 @@ namespace SemiColinGames { |
|
|
|
string text = "Paused"; |
|
|
|
Vector2 position = Textures.BannerFont.CenteredOn(text, camera.HalfSize); |
|
|
|
Text.DrawOutlined(spriteBatch, Textures.BannerFont, text, position, Color.White); |
|
|
|
music.Pause(); |
|
|
|
} else { |
|
|
|
music.Play(); |
|
|
|
} |
|
|
|
spriteBatch.End(); |
|
|
|
|
|
|
|