Skip to content

Instantly share code, notes, and snippets.

@Reputeless
Created November 2, 2023 15:16
Show Gist options
  • Save Reputeless/b91fe47d3ee9a50fd2798206682ab1be to your computer and use it in GitHub Desktop.
Save Reputeless/b91fe47d3ee9a50fd2798206682ab1be to your computer and use it in GitHub Desktop.
# include <Siv3D.hpp>
class Bullet
{
public:
Bullet() = default;
Bullet(const Vec2& startPos, const double angle)
: m_startPos{ startPos }
, m_angle{ angle } {}
void update(double deltaTime = Scene::DeltaTime())
{
m_time += deltaTime;
}
void draw() const
{
m_startPos.asCircle(5).drawFrame(1);
Line{ m_startPos, Arg::angle = m_angle, 800 }.draw(1);
Circle{ getPos(), 10 }.draw();
}
Vec2 getPos() const
{
const Vec2 move = Vec2{ (Periodic::Triangle1_1(1.0s, (0.25 + m_time)) * 60), (-200 * m_time) }.rotate(m_angle);
return (m_startPos + move);
}
double getTime() const
{
return m_time;
}
private:
Vec2 m_startPos{ 0, 0 };
double m_time = 0.0;
double m_angle = 0_deg;
};
void Main()
{
Array<Bullet> bullets;
int32 count = 0;
while (System::Update())
{
if (MouseL.down())
{
bullets.push_back(Bullet{ Cursor::PosF(), ((count % 12) * 30_deg) });
++count;
}
for (auto& bullet : bullets)
{
bullet.update();
}
bullets.remove_if([](const Bullet& bullet) { return (5.0 < bullet.getTime()); });
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