Skip to content

Instantly share code, notes, and snippets.

@seibe
Last active January 19, 2020 07:08
Show Gist options
  • Save seibe/bfdc38cb7e02b14c6acc1b292e74e546 to your computer and use it in GitHub Desktop.
Save seibe/bfdc38cb7e02b14c6acc1b292e74e546 to your computer and use it in GitHub Desktop.
GameCanvasでマルチシーンのサンプルコード
using GameCanvas;
/// <summary>
/// ブート画面
/// </summary>
public sealed class Boot : IScene
{
private float mEnterTime;
public Boot()
{
// empty
}
public void Enter(in Proxy gc, in object param)
{
mEnterTime = gc.TimeSinceStartup;
gc.ClearScreen();
gc.DrawImage(0, 250, 502);
}
public object Leave(in Proxy gc)
{
return null;
}
public bool Update(in Proxy gc, out EScene next)
{
if (gc.TimeSinceStartup - mEnterTime > 1.5f)
{
next = EScene.Top;
return true;
}
next = EScene.Boot;
return false;
}
}
/// <summary>
/// シーン列挙体
/// </summary>
public enum EScene
{
Boot,
Top,
InGame,
Result,
Option
}
private Dictionary<EScene, IScene> mSceneDict;
private IScene mScene;
public override void InitGame()
{
// ゲームの設定
gc.SetResolution(900, 1600);
// シーンの生成
mSceneDict = new Dictionary<EScene, IScene>();
mSceneDict.Add(EScene.Boot, new Boot());
mSceneDict.Add(EScene.Top, new Top());
mSceneDict.Add(EScene.InGame, new InGame());
mSceneDict.Add(EScene.Result, new Result());
mSceneDict.Add(EScene.Option, new Option());
mScene = mSceneDict[EScene.Boot];
mScene.Enter(gc, null);
}
public override void DrawGame()
{
if (mScene.Update(gc, out EScene next))
{
var param = mScene.Leave(gc);
mScene = mSceneDict[next];
mScene.Enter(gc, param);
}
}
using GameCanvas;
/// <summary>
/// シーンインターフェース
/// </summary>
public interface IScene
{
void Enter(in Proxy gc, in object param);
object Leave(in Proxy gc);
bool Update(in Proxy gc, out EScene next);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment