Skip to content

Instantly share code, notes, and snippets.

@yashihei
Last active August 29, 2015 14:21
Show Gist options
  • Save yashihei/aad13278d4a1ae8d8800 to your computer and use it in GitHub Desktop.
Save yashihei/aad13278d4a1ae8d8800 to your computer and use it in GitHub Desktop.
danmaku_generator
#include <Siv3D.hpp>
#include <deque>
using namespace std;
class Bullet {
public:
Bullet(Vec2 pos, Vec2 vec, Color color): pos(pos), vec(vec), color(color) {}
void move() {
pos += vec;
if (pos.x < 0.0 || pos.x > Window::Width() || pos.y < 0.0 || pos.y > Window::Height()) {
enabled = false;
}
}
void draw() {
Circle(pos, 5.0).draw(color);
}
bool isEnabled() { return enabled; }
private:
Vec2 pos, vec;
Color color;
bool enabled = true;
};
void Main()
{
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, 20.0, 5.0, 200));
gui.addln(GUIText::Create(L"color"));
gui.addln(L"color", GUISlider::Create(0.0, 360.0, hue, 200));
gui.addln(L"blend", GUICheckBox::Create({ L"addBlend" }));
while (System::Update()) {
const int cnt = System::FrameCount();
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 (gui.checkBox(L"blend").checked(0)) {
Graphics2D::SetBlendState(BlendState::Additive);
} else {
Graphics2D::SetBlendState(BlendState::Default);
}
if (Input::KeySpace.clicked) gui.show(!gui.style.visible);
if (Input::KeyC.clicked) bullets.clear();
if (Input::MouseR.pressed) pos = Mouse::Pos();
double rad = Radians(cnt * turnAngle);
if (cnt % interval == 0) {
for (int i = 0; i < sep ; i++) {
Vec2 vec = Circular(sp, rad + (TwoPi / sep) * i);
bullets.emplace_back(pos, vec, HSV(hue, 0.7, 1.0));
}
}
for (auto& bullet : bullets) {
bullet.move();
}
Erase_if(bullets, [](Bullet bullet) { return !bullet.isEnabled(); });
for (auto& bullet : bullets) {
bullet.draw();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment