diff --git a/src/battle_game/core/CMakeLists.txt b/src/battle_game/core/CMakeLists.txt index 31e58c94..c07aa2c1 100644 --- a/src/battle_game/core/CMakeLists.txt +++ b/src/battle_game/core/CMakeLists.txt @@ -3,7 +3,8 @@ list(APPEND LIBRARY_LIST ${lib_name}) add_library(${lib_name}) file(GLOB_RECURSE source_files *.cpp *.h) -target_sources(${lib_name} PRIVATE ${source_files}) +target_sources(${lib_name} PRIVATE ${source_files} "units/strange_tank.cpp" "units/strange_tank.h" "bullets/pea.h") + target_link_libraries(${lib_name} PRIVATE grassland) target_include_directories(${lib_name} PRIVATE ${BATTLE_GAME_EXTERNAL_INCLUDE_DIRS} ${BATTLE_GAME_INCLUDE_DIR}) diff --git a/src/battle_game/core/bullets/bullets.h b/src/battle_game/core/bullets/bullets.h index d1447761..bafd13f9 100644 --- a/src/battle_game/core/bullets/bullets.h +++ b/src/battle_game/core/bullets/bullets.h @@ -13,3 +13,5 @@ #include "battle_game/core/bullets/udongein_directional_bullet.h" #include "battle_game/core/bullets/warning_line.h" #include "battle_game/core/bullets/water_drop.h" +#include "battle_game/core/bullets/joker.h" +#include "battle_game/core/bullets/pea.h" diff --git a/src/battle_game/core/bullets/cannon_ball.cpp b/src/battle_game/core/bullets/cannon_ball.cpp index 445d3929..16b6d64f 100644 --- a/src/battle_game/core/bullets/cannon_ball.cpp +++ b/src/battle_game/core/bullets/cannon_ball.cpp @@ -28,6 +28,7 @@ void CannonBall::Update() { bool should_die = false; if (game_core_->IsBlockedByObstacles(position_)) { should_die = true; + } auto &units = game_core_->GetUnits(); @@ -37,6 +38,7 @@ void CannonBall::Update() { } if (unit.second->IsHit(position_)) { game_core_->PushEventDealDamage(unit.first, id_, damage_scale_ * 10.0f); + should_die = true; } } diff --git a/src/battle_game/core/bullets/joker.cpp b/src/battle_game/core/bullets/joker.cpp new file mode 100644 index 00000000..29e3efb2 --- /dev/null +++ b/src/battle_game/core/bullets/joker.cpp @@ -0,0 +1,57 @@ +#include "battle_game/core/bullets/cannon_ball.h" +#include "battle_game/core/game_core.h" +#include "battle_game/core/particles/particles.h" + +namespace battle_game::bullet { +Joker::Joker(GameCore *core, + uint32_t id, + uint32_t unit_id, + uint32_t player_id, + glm::vec2 position, + float rotation, + float damage_scale, + glm::vec2 velocity) + : Bullet(core, id, unit_id, player_id, position, rotation, damage_scale), + velocity_(velocity) { +} + +void Joker::Render() { + SetTransformation(position_, rotation_, glm::vec2{0.1f}); + SetColor(game_core_->GetPlayerColor(player_id_)); + SetTexture("../../textures/particle3.png"); + DrawModel(0); +} + +void Joker::Update() { + float x = game_core_->RandomFloat(); + position_ += velocity_ * kSecondPerTick * x * 2.0f; + bool should_die = false; + if (game_core_->IsBlockedByObstacles(position_)) { + should_die = true; + } + + auto &units = game_core_->GetUnits(); + for (auto &unit : units) { + if (unit.first == unit_id_) { + continue; + } + if (unit.second->IsHit(position_)) { + game_core_->PushEventDealDamage( + unit.first, id_, damage_scale_ * (game_core_->RandomFloat()) * 25.0f); + should_die = true; + } + } + + if (should_die) { + game_core_->PushEventRemoveBullet(id_); + } +} + +Joker::~Joker() { + for (int i = 0; i < 5; i++) { + game_core_->PushEventGenerateParticle( + position_, rotation_, game_core_->RandomInCircle() * 2.0f, 0.2f, + glm::vec4{0.0f, 0.0f, 0.0f, 1.0f}, 3.0f); + } +} +} // namespace battle_game::bullet \ No newline at end of file diff --git a/src/battle_game/core/bullets/joker.h b/src/battle_game/core/bullets/joker.h new file mode 100644 index 00000000..c77804c0 --- /dev/null +++ b/src/battle_game/core/bullets/joker.h @@ -0,0 +1,22 @@ +#pragma once +#include "battle_game/core/bullet.h" + +namespace battle_game::bullet { +class Joker : public Bullet { + public: + Joker(GameCore *core, + uint32_t id, + uint32_t unit_id, + uint32_t player_id, + glm::vec2 position, + float rotation, + float damage_scale, + glm::vec2 velocity); + ~Joker() override; + void Render() override; + void Update() override; + + private: + glm::vec2 velocity_{}; +}; +} // namespace battle_game::bullet \ No newline at end of file diff --git a/src/battle_game/core/bullets/pea.cpp b/src/battle_game/core/bullets/pea.cpp new file mode 100644 index 00000000..ee1c6fb4 --- /dev/null +++ b/src/battle_game/core/bullets/pea.cpp @@ -0,0 +1,59 @@ +#include "battle_game/core/bullets/pea.h" + +#include "battle_game/core/game_core.h" +#include "battle_game/core/particles/particles.h" + +namespace battle_game::bullet { +Pea::Pea(GameCore *core, + uint32_t id, + uint32_t unit_id, + uint32_t player_id, + glm::vec2 position, + float rotation, + float damage_scale, + glm::vec2 velocity) + : Bullet(core, id, unit_id, player_id, position, rotation, damage_scale), + velocity_(velocity) { +} + +void Pea::Render() { + SetTransformation(position_, rotation_, glm::vec2{0.1f}); + SetColor(game_core_->GetPlayerColor(player_id_)); + SetTexture("../../textures/coin.png"); + DrawModel(0); +} + +void Pea::Update() { + position_ += velocity_ * kSecondPerTick; + bool should_die = false; + if (game_core_->IsBlockedByObstacles(position_)) { + game_core_->PushEventDealDamage(unit_id_, id_, damage_scale_ * 10.0f); + should_die = true; + + } + + auto &units = game_core_->GetUnits(); + for (auto &unit : units) { + if (unit.first == unit_id_) { + continue; + } + if (unit.second->IsHit(position_)) { + game_core_->PushEventDealDamage(unit.first, id_, damage_scale_ * 10.0f); + game_core_->PushEventDealDamage(unit_id_, id_, -damage_scale_ * 10.0f); + should_die = true; + } + } + + if (should_die) { + game_core_->PushEventRemoveBullet(id_); + } +} + +Pea::~Pea() { + for (int i = 0; i < 5; i++) { + game_core_->PushEventGenerateParticle( + position_, rotation_, game_core_->RandomInCircle() * 2.0f, 0.2f, + glm::vec4{0.0f, 0.0f, 0.0f, 1.0f}, 3.0f); + } +} +} // namespace battle_game::bullet diff --git a/src/battle_game/core/bullets/pea.h b/src/battle_game/core/bullets/pea.h new file mode 100644 index 00000000..e5d20204 --- /dev/null +++ b/src/battle_game/core/bullets/pea.h @@ -0,0 +1,22 @@ +#pragma once +#include "battle_game/core/bullet.h" + +namespace battle_game::bullet { +class Pea : public Bullet { + public: + Pea(GameCore *core, + uint32_t id, + uint32_t unit_id, + uint32_t player_id, + glm::vec2 position, + float rotation, + float damage_scale, + glm::vec2 velocity); + ~Pea() override; + void Render() override; + void Update() override; + + private: + glm::vec2 velocity_{}; +}; +} // namespace battle_game::bullet \ No newline at end of file diff --git a/src/battle_game/core/game_core.cpp b/src/battle_game/core/game_core.cpp index f8845ba7..9d73c8fc 100644 --- a/src/battle_game/core/game_core.cpp +++ b/src/battle_game/core/game_core.cpp @@ -226,7 +226,9 @@ void GameCore::PushEventDealDamage(uint32_t dst_unit_id, PushEventKillUnit(dst_unit_id, src_unit_id); } } + }); + } void GameCore::PushEventRemoveObstacle(uint32_t obstacle_id) { @@ -242,7 +244,9 @@ void GameCore::PushEventRemoveBullet(uint32_t bullet_id) { if (bullets_.count(bullet_id)) { bullets_.erase(bullet_id); } + }); + } void GameCore::PushEventRemoveParticle(uint32_t particle_id) { diff --git a/src/battle_game/core/selectable_units.cpp b/src/battle_game/core/selectable_units.cpp index fa7b1d01..890deefb 100644 --- a/src/battle_game/core/selectable_units.cpp +++ b/src/battle_game/core/selectable_units.cpp @@ -31,6 +31,7 @@ void GameCore::GeneratePrimaryUnitList() { * */ ADD_SELECTABLE_UNIT(unit::InfernoTank); ADD_SELECTABLE_UNIT(unit::Tank); + ADD_SELECTABLE_UNIT(unit::JokerTank); ADD_SELECTABLE_UNIT(unit::DoubleScatterTank); ADD_SELECTABLE_UNIT(unit::ThreeBodyMan); ADD_SELECTABLE_UNIT(unit::LMTank); @@ -51,6 +52,11 @@ void GameCore::GeneratePrimaryUnitList() { ADD_SELECTABLE_UNIT(unit::CritTank); ADD_SELECTABLE_UNIT(unit::Railgun); ADD_SELECTABLE_UNIT(unit::Udongein); + ADD_SELECTABLE_UNIT(unit::LMTank); + ADD_SELECTABLE_UNIT(unit::StrangeTank); + + + unit.reset(); } diff --git a/src/battle_game/core/units/joker_tank.cpp b/src/battle_game/core/units/joker_tank.cpp new file mode 100644 index 00000000..53e01eb9 --- /dev/null +++ b/src/battle_game/core/units/joker_tank.cpp @@ -0,0 +1,173 @@ +#include "battle_game/core/bullets/bullets.h" +#include "battle_game/core/game_core.h" +#include "battle_game/graphics/graphics.h" +#include "joker_tank.h" + +namespace battle_game::unit { + +namespace { +uint32_t tank_body_model_index = 0xffffffffu; +uint32_t tank_turret_model_index = 0xffffffffu; +} // namespace + +JokerTank::JokerTank(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(); + { + /* JokerTank 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}); + } + + { + /* JokerTank 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 JokerTank::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 JokerTank::Update() { + TankMove(3.0f, glm::radians(180.0f)); + TurretRotate(); + Fire(); + +} + +void JokerTank::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() * 2 * game_core_->RandomFloat(); + 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() * + 2 * game_core_->RandomFloat(); + game_core_->PushEventRotateUnit(id_, rotation_ + rotation_offset); + } +} + +void JokerTank::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 JokerTank::Fire() { + if (fire_count_down_ == 0) { + 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 * 1.5 * + game_core_->RandomFloat(); // Fire interval 1 second. + } + } + } + if (fire_count_down_) { + fire_count_down_--; + } +} + +bool JokerTank::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 *JokerTank::UnitName() const { + return "Joker Tank"; +} + +const char *JokerTank::Author() const { + return "Joker zhs"; +} +} // namespace battle_game::unit \ No newline at end of file diff --git a/src/battle_game/core/units/joker_tank.h b/src/battle_game/core/units/joker_tank.h new file mode 100644 index 00000000..f90815d0 --- /dev/null +++ b/src/battle_game/core/units/joker_tank.h @@ -0,0 +1,27 @@ +#pragma once +#include "battle_game/core/unit.h" + +namespace battle_game::unit { +class JokerTank : public Unit { + public: + JokerTank(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 \ No newline at end of file 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..70150f58 --- /dev/null +++ b/src/battle_game/core/units/strange_tank.cpp @@ -0,0 +1,165 @@ +#include "strange_tank.h" #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 + +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(); + { + /* 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 StrangeTank::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 StrangeTank::Update() { + TankMove(3.0f, glm::radians(180.0f)); + TurretRotate(); + Fire(); +} + +void StrangeTank::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 StrangeTank::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 StrangeTank::Fire() { + if (fire_count_down_ == 0) { + 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. + } + } + } + if (fire_count_down_) { + fire_count_down_--; + } +} + +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 *StrangeTank::UnitName() const { + return "Strange Tank"; +} +const char *StrangeTank::Author() const { + return "Joker zhs"; +} +} // namespace battle_game::unit \ No newline at end of file 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..cab2e3ae --- /dev/null +++ b/src/battle_game/core/units/strange_tank.h @@ -0,0 +1,24 @@ +#pragma once +#include "battle_game/core/unit.h" + +namespace battle_game::unit { +class StrangeTank : public Unit { + public: + 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; + + 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 \ No newline at end of file diff --git a/src/battle_game/core/units/tiny_tank.cpp b/src/battle_game/core/units/tiny_tank.cpp index 99b61f59..6f156964 100644 --- a/src/battle_game/core/units/tiny_tank.cpp +++ b/src/battle_game/core/units/tiny_tank.cpp @@ -83,6 +83,7 @@ void Tank::Update() { TankMove(3.0f, glm::radians(180.0f)); TurretRotate(); Fire(); + } void Tank::TankMove(float move_speed, float rotate_angular_speed) { diff --git a/src/battle_game/core/units/tiny_tank.h b/src/battle_game/core/units/tiny_tank.h index 507c8044..482e8ab6 100644 --- a/src/battle_game/core/units/tiny_tank.h +++ b/src/battle_game/core/units/tiny_tank.h @@ -13,6 +13,7 @@ class Tank : public Unit { 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; diff --git a/src/battle_game/core/units/units.h b/src/battle_game/core/units/units.h index ebaa91e6..01a04b52 100644 --- a/src/battle_game/core/units/units.h +++ b/src/battle_game/core/units/units.h @@ -3,8 +3,10 @@ #include "battle_game/core/units/Whaooooo_tank.h" #include "battle_game/core/units/crit_tank.h" #include "battle_game/core/units/dark_fury.h" +#include "battle_game/core/units/strange_tank.h" #include "battle_game/core/units/double_scatter_tank.h" #include "battle_game/core/units/inferno_tank.h" +#include "battle_game/core/units/joker_tank.h" #include "battle_game/core/units/lm_tank.h" #include "battle_game/core/units/mine_sample_tank.h" #include "battle_game/core/units/missile_tank.h" @@ -23,3 +25,7 @@ #include "battle_game/core/units/triple_shot_tank.h" #include "battle_game/core/units/udongein.h" #include "battle_game/core/units/zibeng_dog.h" + + + +