Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/battle_game/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
2 changes: 2 additions & 0 deletions src/battle_game/core/bullets/bullets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions src/battle_game/core/bullets/cannon_ball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void CannonBall::Update() {
bool should_die = false;
if (game_core_->IsBlockedByObstacles(position_)) {
should_die = true;

}

auto &units = game_core_->GetUnits();
Expand All @@ -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;
}
}
Expand Down
57 changes: 57 additions & 0 deletions src/battle_game/core/bullets/joker.cpp
Original file line number Diff line number Diff line change
@@ -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<particle::Smoke>(
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
22 changes: 22 additions & 0 deletions src/battle_game/core/bullets/joker.h
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions src/battle_game/core/bullets/pea.cpp
Original file line number Diff line number Diff line change
@@ -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<particle::Smoke>(
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
22 changes: 22 additions & 0 deletions src/battle_game/core/bullets/pea.h
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions src/battle_game/core/game_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/battle_game/core/selectable_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down
Loading