シューティングゲーム
https://gyazo.com/4b09836278385497984b8a887301c9ba
(※)ウィンドウの大きさを640*480にしています。
code:cpp
# include <Siv3D.hpp>
void Main()
{
Window::Resize(640, 480);
int32 level = 0;
Graphics::SetBackground(ColorF(0.8, 1.0, 0.8));
const Texture textureA(Emoji(U"🛩"), TextureDesc::Mipped);
const Texture textureB(Emoji(U"👾"), TextureDesc::Mipped);
Stopwatch time1(true);
Stopwatch time2(true);
Array<Vec2> bullets, enemies;
Vec2 playerPos = Window::Center();
while (System::Update())
{
const double speed = System::DeltaTime() * 100;
playerPos.moveBy(Vec2(KeyRight.pressed() - KeyLeft.pressed(), KeyDown.pressed() - KeyUp.pressed())
.setLength(6 * speed))
.clamp(Window::ClientRect());
if (time1 >= 250ms - 1ms * Min(level, 180)) {
enemies.emplace_back(680, Random(40, 440));
++level;
time1.restart();
}
if (KeyZ.pressed() && time2 >= 40ms) {
bullets.push_back(playerPos);
time2.restart();
}
bullets.each(=(Vec2& bullet) { bullet.x += 9.0 * speed; }); enemies.each(=(Vec2& enemy) { enemy.x -= 3.0 * speed; }); bullets.remove_if([](const Vec2& b) { return b.x > 664.5; });
enemies.remove_if(&(const Vec2& e) {
for (auto it = bullets.begin(); it != bullets.end(); ++it)
{
if (it->distanceFrom(e) < 35.0)
{
bullets.erase(it);
return true;
}
}
return e.x < -35.0;
});
bullets.each([](const Vec2& b) { Circle(b, 4).draw(Palette::Orange); });
textureA.resized(150).drawAt(playerPos);
enemies.each(&(const Vec2& e) { textureB.resized(70).drawAt(e); }); }
}