Skip to content

Instantly share code, notes, and snippets.

@Reputeless
Forked from yashihei/main.cpp
Last active August 29, 2015 14:21
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/7181ef8927439da946a7 to your computer and use it in GitHub Desktop.
Save Reputeless/7181ef8927439da946a7 to your computer and use it in GitHub Desktop.
#include <Siv3D.hpp>
#include <deque>
class Bullet
{
public:
Bullet(Vec2 pos, Vec2 vec, Color color)
: pos(pos), vec(vec), color(color) {}
void move()
{
pos += vec;
enabled = Window::ClientRect().intersects(pos);
}
void draw() const
{
Circle(pos, 5.0).draw(color);
}
bool isEnabled() const
{
return enabled;
}
private:
Vec2 pos, vec;
Color color;
bool enabled = true;
};
void Main()
{
std::deque<Bullet> bullets;
Vec2 pos(320, 240);
double sp = 2.0;
double turnAngle = 3.0;
int interval = 3;
int sep = 5;
double hue = 0.0;
GUI gui(GUIStyle::Default);
gui.addln(GUIText::Create(L"bulletSpeed"));
gui.addln(L"speed", GUISlider::Create(1.0, 10.0, sp, 200));
gui.addln(GUIText::Create(L"turnSpeed"));
gui.addln(L"turnAngle", GUISlider::Create(-5.0, 5.0, turnAngle, 200));
gui.addln(GUIText::Create(L"interval"));
gui.addln(L"interval", GUISlider::Create(1.0, 10.0, 3.0, 200));
gui.addln(GUIText::Create(L"separate"));
gui.addln(L"separate", GUISlider::Create(3.0, 10.0, 5.0, 200));
gui.addln(GUIText::Create(L"color"));
gui.addln(L"color", GUISlider::Create(0.0, 360.0, hue, 200));
Println(L"Spaceキーで各パラメーターを設定、右クリックで発射地点変更");
while (System::Update())
{
const int cnt = System::FrameCount();
if (cnt == 600)
ClearPrint();
sp = gui.slider(L"speed").value;
turnAngle = gui.slider(L"turnAngle").value;
interval = gui.slider(L"interval").valueInt;
sep = gui.slider(L"separate").valueInt;
hue = gui.slider(L"color").value;
if (Input::KeySpace.clicked)
gui.show(!gui.style.visible);
if (Input::KeyC.clicked)
bullets.clear();
if (Input::MouseR.pressed)
pos = Mouse::Pos();
const double rad = Radians(cnt * turnAngle);
if (cnt % interval == 0)
{
for (int i = 0; i < sep; ++i)
{
const double tRad = rad + (TwoPi / sep) * i;
bullets.emplace_back(pos, Circular(sp, tRad), HSV(hue, 0.7, 1.0));
}
}
for (auto& bullet : bullets)
bullet.move();
Erase_if(bullets, [](const Bullet& bullet) { return !bullet.isEnabled(); });
for (const auto& bullet : bullets)
bullet.draw();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment