<Siv3D.hpp> void Main() { Size brickSize{ 40, 20 }; double speed = 480.0; Vec2 ballVelocity{ 0, -speed }; Circle ball{ 400, 400, 8 }; Array<Rect> bricks; for (auto p : step(Size{ (Scene::Width() / brickSize.x), 5 })) bricks << Rect{ (p.x * brickSize.x), (60 + p.y * brickSize.y), brickSize }; while (System::Update()) { Rect paddle{ Arg::center(Cursor::Pos().x, 500), 60, 10 }; ball.moveBy(ballVelocity * Scene::DeltaTime()); for (auto it = bricks.begin(); it != bricks.end(); ++it) if (it->intersects(ball)) { (it->bottom().intersects(ball) || it->top().intersects(ball) ? ballVelocity.y : ballVelocity.x) *= -1; bricks.erase(it); break; } if (ball.y < 0 && ballVelocity.y < 0) ballVelocity.y *= -1; if ((ball.x < 0 && ballVelocity.x < 0) || (Scene::Width() < ball.x && 0 < ballVelocity.x)) ballVelocity.x *= -1; if (0 < ballVelocity.y && paddle.intersects(ball)) ballVelocity = Vec2{ (ball.x - paddle.center().x) * 10, -ballVelocity.y }.setLength(speed); for (const auto& brick : bricks) brick.stretched(-1).draw(HSV{ brick.y - 40 }); ball.draw(); paddle.draw(); } } C++ で自力で作ると 500 行ぐらいかかる Siv3D は 27 行