-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add restarting mechanism with scenes (scuffed)
- Loading branch information
1 parent
aedad9c
commit 2084005
Showing
7 changed files
with
153 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.Xna.Framework.Content; | ||
using Microsoft.Xna.Framework.Graphics; | ||
|
||
namespace Core; | ||
|
||
public abstract class Scene : IDisposable, IInitialize, ILoadContent, IUpdate, IDraw | ||
{ | ||
private bool disposed = false; | ||
internal readonly ObjectRegistry objectRegistry; | ||
|
||
public Scene() | ||
{ | ||
objectRegistry = new(); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public IEnumerable<T> GetObjectsOfType<T>() where T : class | ||
{ | ||
return objectRegistry.GetObjectsOfType<T>(); | ||
} | ||
|
||
public void DrawObjects(SpriteBatch spriteBatch) | ||
{ | ||
Draw(spriteBatch); | ||
foreach (IDraw draw in GetObjectsOfType<IDraw>()) | ||
draw.Draw(spriteBatch); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// ignore extra dispose calls; we've already disposed. | ||
if (disposed) | ||
return; | ||
|
||
GC.SuppressFinalize(this); | ||
|
||
// dispose of the object registry | ||
objectRegistry.Dispose(); | ||
|
||
disposed = true; | ||
OnDispose(); | ||
} | ||
|
||
public virtual void OnDispose() { } | ||
|
||
public abstract void Draw(SpriteBatch spriteBatch); | ||
public abstract void Update(); | ||
public abstract void LoadContent(ContentManager content); | ||
public abstract void Initialize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Core; | ||
using Microsoft.Xna.Framework.Content; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using SpaceShooter2.Src.Data; | ||
|
||
namespace SpaceShooter2.Src.Scenes; | ||
|
||
internal class GameScene : Scene | ||
{ | ||
private readonly GlobalState glob; | ||
|
||
public GameScene(GlobalState glob) | ||
{ | ||
this.glob = glob; | ||
} | ||
|
||
public override void Initialize() | ||
{ | ||
_ = new Spawner(glob); | ||
_ = new UI(glob); | ||
} | ||
|
||
public override void LoadContent(ContentManager content) | ||
{ | ||
glob.player = new Player(glob); | ||
|
||
} | ||
public override void Update() { } | ||
public override void Draw(SpriteBatch spriteBatch) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters