From d44cd15379c8c9222857fddfcb2cbb2649fe9f3c Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Fri, 13 Jan 2023 21:17:47 +0800 Subject: [PATCH 01/14] Create clang-format.yml --- .github/workflows/clang-format.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index b58554a6..aa28939d 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -3,6 +3,7 @@ name: "[PR] Clang-format" on: pull_request: types: [opened, synchronize, reopened] + paths: - 'src/**' - '.github/workflows/clang-format.yml' From 8b85bf72df22bc57ed700fc3e9c4dafd3bd4afee Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:34:02 +0800 Subject: [PATCH 02/14] Update player.cpp --- src/battle_game/core/player.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/battle_game/core/player.cpp b/src/battle_game/core/player.cpp index 9ee1934e..a9fa6ed2 100644 --- a/src/battle_game/core/player.cpp +++ b/src/battle_game/core/player.cpp @@ -1,5 +1,4 @@ #include "battle_game/core/player.h" - #include "battle_game/core/game_core.h" namespace battle_game { @@ -19,4 +18,4 @@ void Player::Update() { } } } -} // namespace battle_game \ No newline at end of file +} // namespace battle_game From 02fe7897ba1806689326c28931e44b182d4eb70d Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:43:02 +0800 Subject: [PATCH 03/14] Update input_data.cpp --- src/battle_game/core/input_data.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/battle_game/core/input_data.cpp b/src/battle_game/core/input_data.cpp index 55a799d7..91df6b00 100644 --- a/src/battle_game/core/input_data.cpp +++ b/src/battle_game/core/input_data.cpp @@ -1,3 +1,2 @@ #include "battle_game/core/input_data.h" - namespace battle_game {} From 6718459419d2bffec9f38a156f252b6555650cbb Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Mon, 27 Feb 2023 21:19:04 +0800 Subject: [PATCH 04/14] Update clang-format.yml --- .github/workflows/clang-format.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index aa28939d..82d0be2e 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -1,5 +1,6 @@ name: "[PR] Clang-format" - + + on: pull_request: types: [opened, synchronize, reopened] From ff24cf3f766c216dcbe883db5b502314f39591ae Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Mon, 27 Feb 2023 21:35:49 +0800 Subject: [PATCH 05/14] Create strange_tank.cpp --- src/battle_game/core/units/strange_tank.cpp | 165 ++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 src/battle_game/core/units/strange_tank.cpp diff --git a/src/battle_game/core/units/strange_tank.cpp b/src/battle_game/core/units/strange_tank.cpp new file mode 100644 index 00000000..5d390025 --- /dev/null +++ b/src/battle_game/core/units/strange_tank.cpp @@ -0,0 +1,165 @@ +#include "tiny_tank.h" + +#include "battle_game/core/bullets/bullets.h" +#include "battle_game/core/game_core.h" +#include "battle_game/graphics/graphics.h" + +namespace battle_game::unit { + +namespace { +uint32_t tank_body_model_index = 0xffffffffu; +uint32_t tank_turret_model_index = 0xffffffffu; +} // namespace + +Tank::Tank(GameCore *game_core, uint32_t id, uint32_t player_id) + : Unit(game_core, id, player_id) { + if (!~tank_body_model_index) { + auto mgr = AssetsManager::GetInstance(); + { + /* Tank Body */ + tank_body_model_index = mgr->RegisterModel( + { + {{-0.8f, 0.8f}, {0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{-0.8f, -1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{0.8f, 0.8f}, {0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{0.8f, -1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + // distinguish front and back + {{0.6f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + {{-0.6f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, + }, + {0, 1, 2, 1, 2, 3, 0, 2, 5, 2, 4, 5}); + } + + { + /* Tank Turret */ + std::vector turret_vertices; + std::vector turret_indices; + const int precision = 60; + const float inv_precision = 1.0f / float(precision); + for (int i = 0; i < precision; i++) { + auto theta = (float(i) + 0.5f) * inv_precision; + theta *= glm::pi() * 2.0f; + auto sin_theta = std::sin(theta); + auto cos_theta = std::cos(theta); + turret_vertices.push_back({{sin_theta * 0.5f, cos_theta * 0.5f}, + {0.0f, 0.0f}, + {0.7f, 0.7f, 0.7f, 1.0f}}); + turret_indices.push_back(i); + turret_indices.push_back((i + 1) % precision); + turret_indices.push_back(precision); + } + turret_vertices.push_back( + {{0.0f, 0.0f}, {0.0f, 0.0f}, {0.7f, 0.7f, 0.7f, 1.0f}}); + turret_vertices.push_back( + {{-0.1f, 0.0f}, {0.0f, 0.0f}, {0.7f, 0.7f, 0.7f, 1.0f}}); + turret_vertices.push_back( + {{0.1f, 0.0f}, {0.0f, 0.0f}, {0.7f, 0.7f, 0.7f, 1.0f}}); + turret_vertices.push_back( + {{-0.1f, 1.2f}, {0.0f, 0.0f}, {0.7f, 0.7f, 0.7f, 1.0f}}); + turret_vertices.push_back( + {{0.1f, 1.2f}, {0.0f, 0.0f}, {0.7f, 0.7f, 0.7f, 1.0f}}); + turret_indices.push_back(precision + 1 + 0); + turret_indices.push_back(precision + 1 + 1); + turret_indices.push_back(precision + 1 + 2); + turret_indices.push_back(precision + 1 + 1); + turret_indices.push_back(precision + 1 + 2); + turret_indices.push_back(precision + 1 + 3); + tank_turret_model_index = + mgr->RegisterModel(turret_vertices, turret_indices); + } + } +} + +void Tank::Render() { + battle_game::SetTransformation(position_, rotation_); + battle_game::SetTexture(0); + battle_game::SetColor(game_core_->GetPlayerColor(player_id_)); + battle_game::DrawModel(tank_body_model_index); + battle_game::SetRotation(turret_rotation_); + battle_game::DrawModel(tank_turret_model_index); +} + +void Tank::Update() { + TankMove(3.0f, glm::radians(180.0f)); + TurretRotate(); + Fire(); +} + +void Tank::TankMove(float move_speed, float rotate_angular_speed) { + auto player = game_core_->GetPlayer(player_id_); + if (player) { + auto &input_data = player->GetInputData(); + glm::vec2 offset{0.0f}; + if (input_data.key_down[GLFW_KEY_W]) { + offset.y += 1.0f; + } + if (input_data.key_down[GLFW_KEY_S]) { + offset.y -= 1.0f; + } + float speed = move_speed * GetSpeedScale(); + offset *= kSecondPerTick * speed; + auto new_position = + position_ + glm::vec2{glm::rotate(glm::mat4{1.0f}, rotation_, + glm::vec3{0.0f, 0.0f, 1.0f}) * + glm::vec4{offset, 0.0f, 0.0f}}; + if (!game_core_->IsBlockedByObstacles(new_position)) { + game_core_->PushEventMoveUnit(id_, new_position); + } + float rotation_offset = 0.0f; + if (input_data.key_down[GLFW_KEY_A]) { + rotation_offset += 1.0f; + } + if (input_data.key_down[GLFW_KEY_D]) { + rotation_offset -= 1.0f; + } + rotation_offset *= kSecondPerTick * rotate_angular_speed * GetSpeedScale(); + game_core_->PushEventRotateUnit(id_, rotation_ + rotation_offset); + } +} + +void Tank::TurretRotate() { + auto player = game_core_->GetPlayer(player_id_); + if (player) { + auto &input_data = player->GetInputData(); + auto diff = input_data.mouse_cursor_position - position_; + if (glm::length(diff) < 1e-4) { + turret_rotation_ = rotation_; + } else { + turret_rotation_ = std::atan2(diff.y, diff.x) - glm::radians(90.0f); + } + } +} + +void Tank::Fire() { + if (fire_count_down_) { + fire_count_down_--; + } else { + auto player = game_core_->GetPlayer(player_id_); + if (player) { + auto &input_data = player->GetInputData(); + if (input_data.mouse_button_down[GLFW_MOUSE_BUTTON_LEFT]) { + auto velocity = Rotate(glm::vec2{0.0f, 20.0f}, turret_rotation_); + GenerateBullet( + position_ + Rotate({0.0f, 1.2f}, turret_rotation_), + turret_rotation_, GetDamageScale(), velocity); + fire_count_down_ = kTickPerSecond; // Fire interval 1 second. + } + } + } +} + +bool Tank::IsHit(glm::vec2 position) const { + position = WorldToLocal(position); + return position.x > -0.8f && position.x < 0.8f && position.y > -1.0f && + position.y < 1.0f && position.x + position.y < 1.6f && + position.y - position.x < 1.6f; +} + +const char *Tank::UnitName() const { + return "Tiny Tank"; +} + +const char *Tank::Author() const { + return "LazyJazz"; +} +} // namespace battle_game::unit From cb5b1ca029824c9f22de17b241aaeef78208e462 Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Mon, 27 Feb 2023 21:39:03 +0800 Subject: [PATCH 06/14] Create strange_tank.h --- src/battle_game/core/units/strange_tank.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/battle_game/core/units/strange_tank.h diff --git a/src/battle_game/core/units/strange_tank.h b/src/battle_game/core/units/strange_tank.h new file mode 100644 index 00000000..7727dce9 --- /dev/null +++ b/src/battle_game/core/units/strange_tank.h @@ -0,0 +1,23 @@ +#pragma once +#include "battle_game/core/unit.h" + +namespace battle_game::unit { +class Tank : public Unit { + public: + Tank(GameCore *game_core, uint32_t id, uint32_t player_id); + void Render() override; + void Update() override; + [[nodiscard]] bool IsHit(glm::vec2 position) const override; + + protected: + void TankMove(float move_speed, float rotate_angular_speed); + void TurretRotate(); + void Fire(); + [[nodiscard]] const char *UnitName() const override; + [[nodiscard]] const char *Author() const override; + + float turret_rotation_{0.0f}; + uint32_t fire_count_down_{0}; + uint32_t mine_count_down_{0}; +}; +} // namespace battle_game::unit From 49f80d1f20d6cf5698eb449ee03fe4ec90e6264c Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Mon, 27 Feb 2023 21:42:01 +0800 Subject: [PATCH 07/14] Update strange_tank.cpp --- src/battle_game/core/units/strange_tank.cpp | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/battle_game/core/units/strange_tank.cpp b/src/battle_game/core/units/strange_tank.cpp index 5d390025..c12266e1 100644 --- a/src/battle_game/core/units/strange_tank.cpp +++ b/src/battle_game/core/units/strange_tank.cpp @@ -1,4 +1,4 @@ -#include "tiny_tank.h" +#include "strange_tank.h" #include "battle_game/core/bullets/bullets.h" #include "battle_game/core/game_core.h" @@ -11,7 +11,7 @@ uint32_t tank_body_model_index = 0xffffffffu; uint32_t tank_turret_model_index = 0xffffffffu; } // namespace -Tank::Tank(GameCore *game_core, uint32_t id, uint32_t player_id) +Strangetank::Strangetank(GameCore *game_core, uint32_t id, uint32_t player_id) : Unit(game_core, id, player_id) { if (!~tank_body_model_index) { auto mgr = AssetsManager::GetInstance(); @@ -70,7 +70,7 @@ Tank::Tank(GameCore *game_core, uint32_t id, uint32_t player_id) } } -void Tank::Render() { +void Strangetank::Render() { battle_game::SetTransformation(position_, rotation_); battle_game::SetTexture(0); battle_game::SetColor(game_core_->GetPlayerColor(player_id_)); @@ -79,13 +79,13 @@ void Tank::Render() { battle_game::DrawModel(tank_turret_model_index); } -void Tank::Update() { +void Strangetank::Update() { TankMove(3.0f, glm::radians(180.0f)); TurretRotate(); Fire(); } -void Tank::TankMove(float move_speed, float rotate_angular_speed) { +void Strangetank::TankMove(float move_speed, float rotate_angular_speed) { auto player = game_core_->GetPlayer(player_id_); if (player) { auto &input_data = player->GetInputData(); @@ -117,7 +117,7 @@ void Tank::TankMove(float move_speed, float rotate_angular_speed) { } } -void Tank::TurretRotate() { +void Strangetank::TurretRotate() { auto player = game_core_->GetPlayer(player_id_); if (player) { auto &input_data = player->GetInputData(); @@ -130,7 +130,7 @@ void Tank::TurretRotate() { } } -void Tank::Fire() { +void Strangetank::Fire() { if (fire_count_down_) { fire_count_down_--; } else { @@ -148,18 +148,18 @@ void Tank::Fire() { } } -bool Tank::IsHit(glm::vec2 position) const { +bool Strangetank::IsHit(glm::vec2 position) const { position = WorldToLocal(position); return position.x > -0.8f && position.x < 0.8f && position.y > -1.0f && position.y < 1.0f && position.x + position.y < 1.6f && position.y - position.x < 1.6f; } -const char *Tank::UnitName() const { - return "Tiny Tank"; +const char *Strangetank::UnitName() const { + return "Strangetank"; } -const char *Tank::Author() const { - return "LazyJazz"; +const char *Strangetank::Author() const { + return "wzjwzjwzj"; } } // namespace battle_game::unit From 31fbb58c6b41dd574c7b9736d0d2042c1ac49edc Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Mon, 27 Feb 2023 21:43:53 +0800 Subject: [PATCH 08/14] Update tiny_tank.h --- src/battle_game/core/units/tiny_tank.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battle_game/core/units/tiny_tank.h b/src/battle_game/core/units/tiny_tank.h index 507c8044..b366d6f2 100644 --- a/src/battle_game/core/units/tiny_tank.h +++ b/src/battle_game/core/units/tiny_tank.h @@ -2,9 +2,9 @@ #include "battle_game/core/unit.h" namespace battle_game::unit { -class Tank : public Unit { +class Strangetank : public Unit { public: - Tank(GameCore *game_core, uint32_t id, uint32_t player_id); + Strangetank(GameCore *game_core, uint32_t id, uint32_t player_id); void Render() override; void Update() override; [[nodiscard]] bool IsHit(glm::vec2 position) const override; From 239130cc128925fba193861ea4dae96a5834c4f0 Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Mon, 27 Feb 2023 21:45:24 +0800 Subject: [PATCH 09/14] Update units.h --- src/battle_game/core/units/units.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/battle_game/core/units/units.h b/src/battle_game/core/units/units.h index 0afabc61..2706927f 100644 --- a/src/battle_game/core/units/units.h +++ b/src/battle_game/core/units/units.h @@ -16,3 +16,4 @@ #include "battle_game/core/units/tiny_tank.h" #include "battle_game/core/units/triple_shot_tank.h" #include "battle_game/core/units/zibeng_dog.h" +#include "battle_game/core/units/strange_tank.h" From 7bd3a6fceb01a34b6c9a2f79c9b9f58ff61b5254 Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Mon, 27 Feb 2023 21:46:53 +0800 Subject: [PATCH 10/14] Update selectable_units.cpp --- src/battle_game/core/selectable_units.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/battle_game/core/selectable_units.cpp b/src/battle_game/core/selectable_units.cpp index 64c64c47..08f8c4e3 100644 --- a/src/battle_game/core/selectable_units.cpp +++ b/src/battle_game/core/selectable_units.cpp @@ -45,6 +45,7 @@ void GameCore::GeneratePrimaryUnitList() { ADD_SELECTABLE_UNIT(unit::ZibengDog); ADD_SELECTABLE_UNIT(unit::RageTank); ADD_SELECTABLE_UNIT(unit::SmokeBombTank); + ADD_SELECTABLE_UNIT(unit::Strangetank); unit.reset(); } From 37492920a64fd87c2e070e50af8820a7bef6c03f Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:43:45 +0800 Subject: [PATCH 11/14] Update tiny_tank.h --- src/battle_game/core/units/tiny_tank.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battle_game/core/units/tiny_tank.h b/src/battle_game/core/units/tiny_tank.h index b366d6f2..507c8044 100644 --- a/src/battle_game/core/units/tiny_tank.h +++ b/src/battle_game/core/units/tiny_tank.h @@ -2,9 +2,9 @@ #include "battle_game/core/unit.h" namespace battle_game::unit { -class Strangetank : public Unit { +class Tank : public Unit { public: - Strangetank(GameCore *game_core, uint32_t id, uint32_t player_id); + Tank(GameCore *game_core, uint32_t id, uint32_t player_id); void Render() override; void Update() override; [[nodiscard]] bool IsHit(glm::vec2 position) const override; From e279e001deb937cdbf74c472f2bd5f6ce58c4286 Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:45:06 +0800 Subject: [PATCH 12/14] Update strange_tank.h --- src/battle_game/core/units/strange_tank.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battle_game/core/units/strange_tank.h b/src/battle_game/core/units/strange_tank.h index 7727dce9..6d9e0c0a 100644 --- a/src/battle_game/core/units/strange_tank.h +++ b/src/battle_game/core/units/strange_tank.h @@ -2,9 +2,9 @@ #include "battle_game/core/unit.h" namespace battle_game::unit { -class Tank : public Unit { +class Strangetank : public Unit { public: - Tank(GameCore *game_core, uint32_t id, uint32_t player_id); + Strangetank(GameCore *game_core, uint32_t id, uint32_t player_id); void Render() override; void Update() override; [[nodiscard]] bool IsHit(glm::vec2 position) const override; From bd9e61f9a775b37fb22e4ca8c25b69f243a6d85c Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:46:50 +0800 Subject: [PATCH 13/14] Update strange_tank.cpp --- src/battle_game/core/units/strange_tank.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_game/core/units/strange_tank.cpp b/src/battle_game/core/units/strange_tank.cpp index c12266e1..18d6adde 100644 --- a/src/battle_game/core/units/strange_tank.cpp +++ b/src/battle_game/core/units/strange_tank.cpp @@ -1,4 +1,4 @@ -#include "strange_tank.h" +#include "src/battle_game/core/units/strange_tank.h" #include "battle_game/core/bullets/bullets.h" #include "battle_game/core/game_core.h" From 90922b6597ae05bbc32de43373b6c2f15848f463 Mon Sep 17 00:00:00 2001 From: wzjwzjwzjwzjwzj <113701018+wzjwzjwzjwzjwzj@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:47:52 +0800 Subject: [PATCH 14/14] Update strange_tank.cpp --- src/battle_game/core/units/strange_tank.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_game/core/units/strange_tank.cpp b/src/battle_game/core/units/strange_tank.cpp index 18d6adde..4b2ad956 100644 --- a/src/battle_game/core/units/strange_tank.cpp +++ b/src/battle_game/core/units/strange_tank.cpp @@ -1,4 +1,4 @@ -#include "src/battle_game/core/units/strange_tank.h" +#include "battle_game/core/units/strange_tank.h" #include "battle_game/core/bullets/bullets.h" #include "battle_game/core/game_core.h"