Last active
August 29, 2015 14:07
Revisions
-
chobby revised this gist
Oct 4, 2014 . 1 changed file with 1 addition and 0 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ //May2014 # include <Siv3D.hpp> void Main() -
chobby created this gist
Oct 4, 2014 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,139 @@ # include <Siv3D.hpp> void Main() { Window::Resize(854, 480); Rect window(Window::Size()); //任意の画像を用意してください Texture openingTexture(L"data/opening.png"); Texture mainTexture(L"data/main.png"); Texture gameOverTexture(L"data/gameOver.png"); Texture gameClearTexture(L"data/gameClear.png"); Font font(30); String highScoresString; int nowScore = 0; std::array<int, 5> highScores; highScores.fill(0); auto setScore = [&](int score) { auto it = std::min_element(highScores.begin(), highScores.end()); if (score > *it) { *it = score; } std::sort(highScores.begin(), highScores.end(), std::greater<int>()); highScoresString.clear(); for (const auto& score : highScores) { highScoresString += Format(score, L"\n"); } }; auto init = [&]() { nowScore = 0; }; enum class GameState { Opening, Main, GameOver, GameClear, Result }; GameState gameState = GameState::Opening; auto opening = [&]() { if (Input::AnyKeyClicked()) { init(); gameState = GameState::Main; } window(openingTexture).draw(); }; auto gameMain = [&]() { if (Input::KeyZ.clicked) { gameState = GameState::GameClear; } if (Input::KeyX.clicked) { gameState = GameState::GameOver; } if (Input::KeySpace.clicked) { ++nowScore; } window(mainTexture).draw(); font(nowScore).draw(); }; auto gameOver = [&]() { if (Input::AnyKeyClicked()) { gameState = GameState::Opening; } window(gameOverTexture).draw(); }; auto gameClear = [&]() { if (Input::AnyKeyClicked()) { setScore(nowScore); gameState = GameState::Result; } window(gameClearTexture).draw(); }; auto result = [&]() { if (Input::AnyKeyClicked()) { gameState = GameState::Opening; } font(highScoresString).drawCenter(Window::Center()); }; std::vector<std::function<void()>> sequences = { opening, gameMain, gameOver, gameClear, result }; while (System::Update()) { sequences[static_cast<int>(gameState)](); } }