From b091cb7910fa82e9fb00abdb163d277ba574f804 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 9 Jan 2025 14:54:51 +0100 Subject: make format --- game/enemy/BattleScript.cpp | 4 ++-- game/enemy/EnemyBulletSubScene.cpp | 2 +- game/enemy/EnemyScript.cpp | 28 ++++++++++++---------------- game/enemy/EnemyScript.h | 1 + game/enemy/EnemySubScene.cpp | 4 ++-- 5 files changed, 18 insertions(+), 21 deletions(-) (limited to 'game/enemy') diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp index 2d1e143..cfffcb3 100644 --- a/game/enemy/BattleScript.cpp +++ b/game/enemy/BattleScript.cpp @@ -40,10 +40,10 @@ void BattleScript::spawn_enemies(int amount) { RefVector enemy_scripts = this->get_components_by_tag("enemy"); std::uniform_real_distribution dist(70, 150); - + for (int i = 0; i < amount; i++) { BehaviorScript & script = enemy_scripts[i]; - if(script.active == true) continue; + if (script.active == true) continue; script.active = true; this->queue_event( SpawnEnemyEvent { diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index eb43f0a..c0e94e0 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -29,7 +29,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { .body_type = Rigidbody::BodyType::KINEMATIC, .linear_velocity = vec2 {-400, 0}, .kinematic_collision = false, - .collision_layers = {COLL_LAY_BOT_TOP,COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, + .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, .collision_layer = COLL_LAY_BULLET }); bullet_body.active = false; diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 2382847..8804f50 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -2,18 +2,17 @@ #include "../Config.h" #include "../Random.h" #include "EnemyConfig.h" +#include "api/Color.h" +#include "api/Sprite.h" #include #include #include #include #include #include -#include #include +#include #include -#include "../Random.h" -#include "api/Color.h" -#include "api/Sprite.h" #include using namespace crepe; using namespace std; @@ -43,11 +42,10 @@ void EnemyScript::fixed_update(duration_t dt) { float direction_to_player_y = player_transform.position.y - transform.position.y; float distance_to_player_y = std::abs(direction_to_player_y); - float adjustment_speed = speed * (distance_to_player_y / MAX_DISTANCE); adjustment_speed = std::clamp(adjustment_speed, MIN_SPEED, MAX_SPEED); - Rigidbody& player_body = this->get_components_by_tag("player").front(); + Rigidbody & player_body = this->get_components_by_tag("player").front(); // move path nodes for (vec2 & path_node : ai_component.path) { path_node.y += (direction_to_player_y > 0 ? 1 : -1) * adjustment_speed * dt.count(); @@ -63,7 +61,7 @@ void EnemyScript::fixed_update(duration_t dt) { } std::chrono::duration elapsed_hit = now - last_hit; //hit blink timer - if(elapsed_hit > blink_time){ + if (elapsed_hit > blink_time) { set_hit_blink(false); } } @@ -92,10 +90,10 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { return false; } -void EnemyScript::set_hit_blink(bool status){ +void EnemyScript::set_hit_blink(bool status) { RefVector sprites = this->get_components(); - for(Sprite& sprite : sprites){ - if(status){ + for (Sprite & sprite : sprites) { + if (status) { sprite.data.color = Color::RED; continue; } @@ -109,13 +107,12 @@ bool EnemyScript::on_collide(const CollisionEvent & e) { last_hit = std::chrono::steady_clock::now(); //Sprite& sprite; set_hit_blink(true); - } - if(health <= 0){ + if (health <= 0) { this->despawn_enemy(); } //body_animator.play(); - + return false; } @@ -153,9 +150,8 @@ void EnemyScript::shoot(const vec2 & location) { } } -void EnemyScript::create_tank(){ +void EnemyScript::create_tank() { RefVector sprites = this->get_components(); - Sprite& tank_body = sprites[2]; + Sprite & tank_body = sprites[2]; tank_body.active = true; - } diff --git a/game/enemy/EnemyScript.h b/game/enemy/EnemyScript.h index 24799a5..2bd9742 100644 --- a/game/enemy/EnemyScript.h +++ b/game/enemy/EnemyScript.h @@ -20,6 +20,7 @@ public: void create_tank(); void create_soldier(); void set_hit_blink(bool status); + private: std::random_device rd; std::default_random_engine engine; diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index edc537f..fe9fd63 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -74,7 +74,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { .looping = true, } ); - // tanky body + // tanky body Asset tank_body_asset {"asset/workers/workerFatBody.png"}; enemy.add_component(vec2(50, 50)); Sprite & tank_body_sprite = enemy.add_component( @@ -121,7 +121,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { } ); //gun - Asset enemy_pistol_asset{"asset/workers/gun.png"}; + Asset enemy_pistol_asset {"asset/workers/gun.png"}; Sprite & enemy_pistol_sprite = enemy.add_component( enemy_pistol_asset, Sprite::Data { -- cgit v1.2.3