Skip to content

Commit

Permalink
horde_shooting_v_1_0
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivAlley committed Nov 5, 2023
1 parent df93738 commit cf824b6
Show file tree
Hide file tree
Showing 31 changed files with 1,884 additions and 95 deletions.
Binary file added WindowsDesktop/App/raw_resource/attack_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/firerate_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/focus_crystal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/fullfine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/health_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/long_shot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/luck_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/plate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/regen_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/rockstanding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/speed_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/vamp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/void_shield.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WindowsDesktop/App/raw_resource/wire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
147 changes: 52 additions & 95 deletions WindowsDesktop/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,105 +1,62 @@
# include <Siv3D.hpp> // Siv3D v0.6.12
#include <Siv3D/Windows/Windows.hpp>
#include "Siv3D.hpp"
#include "Src/Game.h"
#include "Src/GVars.h"

void Main()
{
// 背景の色を設定する | Set the background color
Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });

// 画像ファイルからテクスチャを作成する | Create a texture from an image file
const Texture texture{ U"example/windmill.png" };

// 絵文字からテクスチャを作成する | Create a texture from an emoji
const Texture emoji{ U"🦖"_emoji };

// 太文字のフォントを作成する | Create a bold font with MSDF method
const Font font{ FontMethod::MSDF, 48, Typeface::Bold };

// テキストに含まれる絵文字のためのフォントを作成し、font に追加する | Create a font for emojis in text and add it to font as a fallback
const Font emojiFont{ 48, Typeface::ColorEmoji };
font.addFallback(emojiFont);

// ボタンを押した回数 | Number of button presses
int32 count = 0;

// チェックボックスの状態 | Checkbox state
bool checked = false;
#include "Src/Player.h"
#include "Src/Title.h"

// プレイヤーの移動スピード | Player's movement speed
double speed = 200.0;

// プレイヤーの X 座標 | Player's X position
double playerPosX = 400;

// プレイヤーが右を向いているか | Whether player is facing right
bool isPlayerFacingRight = true;
void RegisterResource();

void Main()
{
System::SetTerminationTriggers(UserAction::CloseButtonClicked);
Cursor::RequestStyle(CursorStyle::Hidden);
while (ShowCursor(FALSE) >= 0)
Window::Resize(Global::windowSize);
Window::Resize({ 1920,1080 });
const ColorF backgroundColor = ColorF{ 0.4, 0.6, 0.8 }.removeSRGBCurve();
RegisterResource();
const MSRenderTexture renderTexture{ Scene::Size(), TextureFormat::R8G8B8A8_Unorm_SRGB, HasDepth::Yes };

FontAsset::Register(U"TitleFont", 60, Typeface::Heavy);
FontAsset::Register(U"UIFont", 30, Typeface::Regular);
FontAsset::Register(U"damageFont", 20, Typeface::Light);
App manager;
manager.add<Title>(U"Title");
manager.add<Game>(U"Game");
while (System::Update())
{
// テクスチャを描く | Draw the texture
texture.draw(20, 20);

// テキストを描く | Draw text
font(U"Hello, Siv3D!🎮").draw(64, Vec2{ 20, 340 }, ColorF{ 0.2, 0.4, 0.8 });

// 指定した範囲内にテキストを描く | Draw text within a specified area
font(U"Siv3D (シブスリーディー) は、ゲームやアプリを楽しく簡単な C++ コードで開発できるフレームワークです。")
.draw(18, Rect{ 20, 430, 480, 200 }, Palette::Black);

// 長方形を描く | Draw a rectangle
Rect{ 540, 20, 80, 80 }.draw();

// 角丸長方形を描く | Draw a rounded rectangle
RoundRect{ 680, 20, 80, 200, 20 }.draw(ColorF{ 0.0, 0.4, 0.6 });

// 円を描く | Draw a circle
Circle{ 580, 180, 40 }.draw(Palette::Seagreen);

// 矢印を描く | Draw an arrow
Line{ 540, 330, 760, 260 }.drawArrow(8, SizeF{ 20, 20 }, ColorF{ 0.4 });

// 半透明の円を描く | Draw a semi-transparent circle
Circle{ Cursor::Pos(), 40 }.draw(ColorF{ 1.0, 0.0, 0.0, 0.5 });

// ボタン | Button
if (SimpleGUI::Button(U"count: {}"_fmt(count), Vec2{ 520, 370 }, 120, (checked == false)))
if (not manager.update())
{
// カウントを増やす | Increase the count
++count;
break;
}

// チェックボックス | Checkbox
SimpleGUI::CheckBox(checked, U"Lock \U000F033E", Vec2{ 660, 370 }, 120);

// スライダー | Slider
SimpleGUI::Slider(U"speed: {:.1f}"_fmt(speed), speed, 100, 400, Vec2{ 520, 420 }, 140, 120);

// 左キーが押されていたら | If left key is pressed
if (KeyLeft.pressed())
{
// プレイヤーが左に移動する | Player moves left
playerPosX = Max((playerPosX - speed * Scene::DeltaTime()), 60.0);
isPlayerFacingRight = false;
}

// 右キーが押されていたら | If right key is pressed
if (KeyRight.pressed())
{
// プレイヤーが右に移動する | Player moves right
playerPosX = Min((playerPosX + speed * Scene::DeltaTime()), 740.0);
isPlayerFacingRight = true;
}

// プレイヤーを描く | Draw the player
emoji.scaled(0.75).mirrored(isPlayerFacingRight).drawAt(playerPosX, 540);
}
}

//
// - Debug ビルド: プログラムの最適化を減らす代わりに、エラーやクラッシュ時に詳細な情報を得られます。
//
// - Release ビルド: 最大限の最適化でビルドします。
//
// - [デバッグ] メニュー → [デバッグの開始] でプログラムを実行すると、[出力] ウィンドウに詳細なログが表示され、エラーの原因を探せます。
//
// - Visual Studio を更新した直後は、プログラムのリビルド([ビルド]メニュー → [ソリューションのリビルド])が必要な場合があります。
//
void RegisterResource()
{
Array<bool> b;
b << TextureAsset::Register(U"attack_up", U"raw_resource/attack_up.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"firerate_up", U"raw_resource/firerate_up.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"focus_crystal", U"raw_resource/focus_crystal.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"fullfine", U"raw_resource/fullfine.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"health_up", U"raw_resource/health_up.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"long_shot", U"raw_resource/long_shot.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"luck_up", U"raw_resource/luck_up.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"lucky_multi_up", U"raw_resource/lucky_multi_up.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"plate", U"raw_resource/plate.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"precision_multi_up", U"raw_resource/precision_multi_up.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"regen_up", U"raw_resource/regen_up.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"rockstanding", U"raw_resource/rockstanding.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"speed_up", U"raw_resource/speed_up.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"vamp", U"raw_resource/vamp.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"void_shield", U"raw_resource/void_shield.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"wire", U"raw_resource/wire.png", TextureDesc::MippedSRGB);
b << TextureAsset::Register(U"title", U"raw_resource/title.png", TextureDesc::MippedSRGB);
b << AudioAsset::Register(U"player_fire", Resource(U"embed_rc/player_fire.mp3"));
b << AudioAsset::Register(U"player_hit_marker", Resource(U"embed_rc/hit_marker.mp3"));
b << AudioAsset::Register(U"player_damaged", Resource(U"embed_rc/player_damaged.mp3"));
auto result = b.all();
assert(result);
}
226 changes: 226 additions & 0 deletions WindowsDesktop/Src/Enemy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
#include "Enemy.h"

#include "Player.h"
#include "GVars.h"
#include "Item.h"

EnemyBase::EnemyBase()
:m_pos{ Vec3{ RandomClosed(-45, 45), 5, 100 } }
, m_health{ 100 * Global::escalation }
, m_maxHealth{ 100 * Global::escalation }
{
m_normalCollision <<
OrientedBox{ m_pos, Vec3{ 2,3,2 }};
m_criticalCollision <<
OrientedBox{ m_pos + m_headMargin, Vec3{ 1,1,1 } };
}

void EnemyBase::MoveStraight()
{
Vec3 vecToPlayer = Player::GetInstance().GetPos() - m_pos;
if (vecToPlayer.lengthSq() > 2.0 * 2.0)
{
vecToPlayer.normalize();
Vec3 moveVec = vecToPlayer * m_speed * Global::deltaTime;
m_pos += moveVec;
}
else
{
Attack();
}
}

void EnemyBase::Attack()
{
if (m_attackTimer.ms() > 1500)
{
Player::GetInstance().ApplyDamaged(m_atk);
m_attackTimer.restart();

Vec3 vecToPlayer = Player::GetInstance().GetPos() - m_pos;
vecToPlayer.normalize();

Vec3 impulseKnockBackVec = -vecToPlayer * 5.0;
m_pos += impulseKnockBackVec;
}
}

void EnemyBase::ApplyDamage(int damage)
{
if (Player::GetInstance().GetRecordDPSTimer().ms() > 1000)
{
Player::GetInstance().GetRecordDPSTimer().restart();
if (Global::accumlatedDamage > Global::maxDPS)
{
Global::maxDPS = Global::accumlatedDamage;
}
Global::accumlatedDamage = 0;
}
Global::accumlatedDamage += damage;
m_health -= damage;
if (m_health <= 0)
{
m_state = State::Dead;
if (RandomBool(Global::CalcDropRate(Player::GetInstance().GetItemCount())))
{
Global::RouletteDropItem(m_pos);
}
}
}

void EnemyBase::Update()
{
for (auto& box : m_normalCollision)
{
box.setPos(m_pos);
}
for (auto& box : m_criticalCollision)
{
box.setPos(m_pos + m_headMargin);
}

Ray ray{ m_pos,Vec3{0,-1,0} };

if (!ray.intersects(Global::gameFloor))
{
m_pos.y -= 30 * Global::deltaTime;
}
if (m_pos.y < -300)
{
m_state = State::Dead;
}
}

void EnemyBase::Draw()
{
for (const auto& box : m_normalCollision)
{
box.drawFrame(m_color);
}
for (const auto& box : m_criticalCollision)
{
box.draw(Linear::Palette::Red);
}
}

void StraightMoveEnemy::Update()
{
EnemyBase::Update();
MoveStraight();
}

void StraightMoveEnemy::Attack()
{
EnemyBase::Attack();
}

void SlitheringEnemy::Update()
{
EnemyBase::Update();

Vec3 vecToPlayer = Player::GetInstance().GetPos() - m_pos;
if (vecToPlayer.lengthSq() > 2.0 * 2.0)
{
vecToPlayer.normalize();

static double timeFactor = 0.0;
timeFactor += Global::deltaTime;

double slitherOffset = amplitude * sin(frequency * timeFactor);

Vec3 lateralDir = vecToPlayer.cross(Vec3{ 0, 1, 0 });
lateralDir.normalize();

Vec3 movement = (vecToPlayer * m_speed + lateralDir * slitherOffset) * Global::deltaTime;
m_pos += movement;
}
else
{
Attack();
}
}

void SlitheringEnemy::Attack()
{
EnemyBase::Attack();
}

void DistanceAttackEnemy::Update()
{
EnemyBase::Update();
auto dist = Player::GetInstance().GetPos() - m_pos;
double distance = dist.length();
if (distance > 50.0)
{
MoveStraight();
}
else
{
if (m_attackTimer.ms() > 5000)
{
launchProjectile();
m_attackTimer.restart();
}
}
}

void DistanceAttackEnemy::launchProjectile()
{
temp_enemies.push_back(std::make_unique<FlyingObject>(
m_pos
));
}

void FlyingObject::Update()
{
EnemyBase::Update();

std::call_once(m_flag, [&]()
{
Vec3 vecToPlayer = Player::GetInstance().GetPos() - m_pos;
m_targetVec = vecToPlayer.normalized();
});
Vec3 moveVec = m_targetVec * m_speed * Global::deltaTime;
m_pos += moveVec;

Vec3 vec = Player::GetInstance().GetPos() - m_pos;
if (vec.lengthSq() < 2.0 * 2.0)
{
Attack();
}

}

void FlyingObject::Attack()
{
Player::GetInstance().ApplyDamaged(m_atk);
m_state = State::Dead;
}

void ChargingEnemy::Update()
{
EnemyBase::Update();
std::call_once(m_flag, [&]()
{
Vec3 vecToPlayer = Player::GetInstance().GetPos() - m_pos;
m_targetVec = vecToPlayer.normalized();
});
Vec3 moveVec = m_targetVec * m_speed * Global::deltaTime;
m_pos += moveVec;

Vec3 vec = Player::GetInstance().GetPos() - m_pos;
if (vec.lengthSq() < 2.0 * 2.0)
{
Attack();
}
}

void ChargingEnemy::Attack()
{
if (m_attackTimer.ms() > 2000)
{
Player::GetInstance().ApplyDamaged(m_atk);
m_attackTimer.restart();
}
}

Loading

0 comments on commit cf824b6

Please sign in to comment.