-
-
Save voidproc/133f015c10124a9f6e85372833788215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <Siv3D.hpp> // OpenSiv3D v0.1.5 | |
void Main() | |
{ | |
Graphics::SetBackground(Color{ 255, 237, 216 }); | |
const Texture textureFire(Emoji(L"🔥"), TextureDesc::Mipped); | |
const Texture textureCol(Emoji(L"💥"), TextureDesc::Mipped); | |
// 敵や障害物などのレーザーがあたるもの | |
Array<Circle> enemies{ Circle{50}, Circle{40}, Circle{70} }; | |
while (System::Update()) | |
{ | |
// 敵を動かす/描画 | |
const auto frame = System::FrameCount(); | |
for (int i : step(enemies.size())) | |
{ | |
enemies[i].setPos(Window::Center().x + (120 + i * 40) * sin(frame * (0.03 + i * 0.01) + i * Math::TwoPi / 3), 100); | |
enemies[i].draw(Color{ 255, 193, 118 }); | |
} | |
// マウス位置の上方にレーザーが伸びる | |
// いま nearest まで伸びてる | |
const auto cursorPos = Cursor::PosF(); | |
Vec2 nearest = cursorPos + Vec2{ 0, -1000 }; | |
for (const auto& enemy : enemies) | |
{ | |
if (cursorPos.intersects(enemy)) | |
{ | |
// レーザー発射点がめりこんでいれば、レーザーは伸びない | |
nearest = cursorPos; | |
} | |
else | |
{ | |
// めりこんでいないので、マウス位置に一番近い衝突点までレーザーが伸びる | |
Line{ cursorPos, nearest }.intersectsAt(enemy).value_or(Array<Vec2>{}).each([&](const auto& pos) { | |
if (cursorPos.distanceFrom(pos) < cursorPos.distanceFrom(nearest)) { | |
nearest = pos; | |
}; | |
}); | |
} | |
} | |
Line{ cursorPos, nearest }.draw(16 + 4 * sin(frame * 10), Palette::Darkorange); //レーザー本体 | |
textureFire.resize(70 + 8 * sin(frame * 5)).rotate(20_deg * sin(frame * 0.1)).drawAt(cursorPos); //発射点 | |
textureCol.resize(100 + 30 * sin(frame * 0.5)).drawAt(nearest); //照射先 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment