Created
April 26, 2016 14:23
-
-
Save plasma-effect/b2f76697a36936888721fe2e95d783de to your computer and use it in GitHub Desktop.
新入生に見せるため突貫で作った弾避けゲー
This file contains hidden or 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
#include<Siv3D.hpp> | |
#include<chrono> | |
namespace sch = std::chrono; | |
void Main() | |
{ | |
s3d::Window::Resize(360, 480); | |
std::pair<s3d::Circle, bool> enemy[25 * 8]{}; | |
constexpr int s = 4; | |
s3d::Circle player(180, 240, s); | |
std::mt19937 random{ std::random_device()() }; | |
std::uniform_int_distribution<int> uni(0, 360); | |
auto start = sch::system_clock::now(); | |
s3d::Optional<sch::time_point<sch::system_clock>> end; | |
std::pair<s3d::Key, s3d::Point> keys[4] = | |
{ | |
std::make_pair(s3d::Input::KeyUp,s3d::Point(0,-1)), | |
std::make_pair(s3d::Input::KeyDown,s3d::Point(0,1)), | |
std::make_pair(s3d::Input::KeyRight,s3d::Point(1,0)), | |
std::make_pair(s3d::Input::KeyLeft,s3d::Point(-1,0)) | |
}; | |
int n{}; | |
s3d::Font const font(32); | |
while (s3d::System::Update()) | |
{ | |
for (auto& p : enemy) | |
{ | |
if (p.second) | |
p.first.draw(s3d::Palette::Red); | |
} | |
if (end) | |
{ | |
font(L"ゲームオーバー:\n", sch::duration_cast<sch::milliseconds>(*end - start)).draw(); | |
continue; | |
} | |
++n; | |
if (n % 20 == 0) | |
{ | |
for (int i{};i < 8;++i) | |
{ | |
for (auto& a : enemy) | |
{ | |
if (!a.second) | |
{ | |
a.first.center = s3d::Vec2(uni(random), -s); | |
a.first.setSize(s); | |
a.second = true; | |
break; | |
} | |
} | |
} | |
} | |
if (std::any_of(std::begin(enemy), std::end(enemy), | |
[&](auto const& p) | |
{ | |
return p.second&& p.first.intersects(player); | |
})) | |
end = sch::system_clock::now(); | |
for (auto& p : enemy) | |
{ | |
if (p.second) | |
{ | |
p.first.y += 1; | |
if (p.first.y > 480 + s) | |
{ | |
p.second = false; | |
} | |
} | |
} | |
for (auto const& p : keys) | |
{ | |
if (p.first.pressed) | |
{ | |
player.center += p.second; | |
} | |
} | |
player.draw(s3d::Palette::White); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment