Skip to content

Instantly share code, notes, and snippets.

@Reputeless
Last active October 21, 2023 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reputeless/9fdae7c44013e25f290b255dcc8701e7 to your computer and use it in GitHub Desktop.
Save Reputeless/9fdae7c44013e25f290b255dcc8701e7 to your computer and use it in GitHub Desktop.

プロジェクトの構造

ProjectDirectory/
│
├── Main.cpp
├── Common.hpp
├── Title.hpp
├── Title.cpp
├── Game.hpp
└── Game.cpp
# pragma once
# include <Siv3D.hpp>
using App = SceneManager<String>;
# include "Game.hpp"
Game::Game(const InitData& init)
: IScene{ init }
{
}
void Game::update()
{
if (MouseL.down())
{
changeScene(U"Title");
}
}
void Game::draw() const
{
Scene::SetBackground(ColorF{ 0.3, 0.4, 0.5 });
}
# pragma once
# include "Common.hpp"
// ゲームシーン
class Game : public App::Scene
{
public:
Game(const InitData& init);
void update() override;
void draw() const override;
};
# include <Siv3D.hpp> // Siv3D v0.6.12
# include "Common.hpp"
# include "Title.hpp"
# include "Game.hpp"
void Main()
{
Window::Resize(1280, 720);
Window::SetTitle(U"Siv3D Game v1.0");
Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });
FontAsset::Register(U"Bold", FontMethod::MSDF, 48, Typeface::Bold);
App manager;
manager.add<Title>(U"Title");
manager.add<Game>(U"Game");
while (System::Update())
{
if (not manager.update())
{
break;
}
}
}
# include "Title.hpp"
Title::Title(const InitData& init)
: IScene{ init }
{
}
void Title::update()
{
if (m_startButton.leftClicked())
{
changeScene(U"Game");
}
if (m_quitButton.leftClicked())
{
System::Exit();
}
}
void Title::draw() const
{
Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });
const Font& font = FontAsset(U"Bold");
font(U"Siv3D Game").drawAt(120, Vec2{ 640, 200 }, ColorF{ 0.96 });
m_startButton.draw(ColorF{ 0.96 });
font(U"Start").drawAt(m_startButton.center(), ColorF{ 0.2 });
if (m_startButton.mouseOver())
{
m_startButton.drawFrame(2, 0, ColorF{ 0.2 });
Cursor::RequestStyle(CursorStyle::Hand);
}
m_quitButton.draw(ColorF{ 0.96 });
font(U"Quit").drawAt(m_quitButton.center(), ColorF{ 0.2 });
if (m_quitButton.mouseOver())
{
m_quitButton.drawFrame(2, 0, ColorF{ 0.2 });
Cursor::RequestStyle(CursorStyle::Hand);
}
}
# pragma once
# include "Common.hpp"
// タイトルシーン
class Title : public App::Scene
{
public:
Title(const InitData& init);
void update() override;
void draw() const override;
private:
Rect m_startButton{ Arg::center(640, 480), 400, 80 };
Rect m_quitButton{ Arg::center(640, 580), 400, 80 };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment