diff options
-rw-r--r-- | game/enemy/BattleScript.cpp | 4 | ||||
-rw-r--r-- | game/enemy/EnemyBulletSubScene.cpp | 2 | ||||
-rw-r--r-- | game/enemy/EnemyScript.cpp | 28 | ||||
-rw-r--r-- | game/enemy/EnemyScript.h | 1 | ||||
-rw-r--r-- | game/enemy/EnemySubScene.cpp | 4 | ||||
-rw-r--r-- | game/main.cpp | 2 | ||||
-rw-r--r-- | game/scheduler/ObjectsScheduler.cpp | 20 |
7 files changed, 29 insertions, 32 deletions
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<BehaviorScript> enemy_scripts = this->get_components_by_tag<BehaviorScript>("enemy"); std::uniform_real_distribution<float> 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>( 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 <crepe/api/AI.h> #include <crepe/api/Animator.h> #include <crepe/api/AudioSource.h> #include <crepe/api/BoxCollider.h> #include <crepe/api/ParticleEmitter.h> #include <crepe/api/Rigidbody.h> -#include <crepe/api/Transform.h> #include <crepe/api/Sprite.h> +#include <crepe/api/Transform.h> #include <crepe/types.h> -#include "../Random.h" -#include "api/Color.h" -#include "api/Sprite.h" #include <random> 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<Rigidbody>("player").front(); + Rigidbody & player_body = this->get_components_by_tag<Rigidbody>("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<float> 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<Sprite> sprites = this->get_components<Sprite>(); - 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<Sprite> sprites = this->get_components<Sprite>(); - 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<BoxCollider>(vec2(50, 50)); Sprite & tank_body_sprite = enemy.add_component<Sprite>( @@ -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<Sprite>( enemy_pistol_asset, Sprite::Data { diff --git a/game/main.cpp b/game/main.cpp index a34121e..751cbe5 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -17,7 +17,7 @@ int main() { Config::get_instance() = ENGINE_CONFIG; Engine gameloop; - + gameloop.add_scene<MainMenuScene>(); gameloop.add_scene<ShopMenuScene>(); gameloop.add_scene<GameScene>(); diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp index a802806..8415ef8 100644 --- a/game/scheduler/ObjectsScheduler.cpp +++ b/game/scheduler/ObjectsScheduler.cpp @@ -4,8 +4,8 @@ #include "../Config.h" #include "../Random.h" -#include "../missile/SpawnEvent.h" #include "../enemy/EnemyScript.h" +#include "../missile/SpawnEvent.h" #include "api/Rigidbody.h" #include "api/Transform.h" #include "enemy/BattleScript.h" @@ -16,23 +16,23 @@ void ObjectsScheduler::preset_0() { trigger_event<MissileSpawnEvent>(MissileSpawnEvent {}); trigger_event<MissileSpawnEvent>(MissileSpawnEvent {}); this->trigger_event<BattleStartEvent>(BattleStartEvent { - .num_enemies = Random::i(3,1), + .num_enemies = Random::i(3, 1), .battle = false, }); } -void ObjectsScheduler::preset_1() { - trigger_event<MissileSpawnEvent>(MissileSpawnEvent {}); +void ObjectsScheduler::preset_1() { + trigger_event<MissileSpawnEvent>(MissileSpawnEvent {}); this->trigger_event<BattleStartEvent>(BattleStartEvent { - .num_enemies = Random::i(4,1), + .num_enemies = Random::i(4, 1), .battle = false, - }); + }); } -void ObjectsScheduler::preset_2() { +void ObjectsScheduler::preset_2() { trigger_event<CreateZapperEvent>(CreateZapperEvent {}); this->trigger_event<BattleStartEvent>(BattleStartEvent { - .num_enemies = Random::i(2,1), + .num_enemies = Random::i(2, 1), .battle = false, - }); + }); } void ObjectsScheduler::preset_3() { trigger_event<CreateZapperEvent>(CreateZapperEvent {}); } void ObjectsScheduler::preset_4() {} @@ -42,7 +42,7 @@ void ObjectsScheduler::boss_fight_1() { this->trigger_event<BattleStartEvent>(BattleStartEvent { .num_enemies = 7, .battle = true, - }); + }); RefVector<Rigidbody> rb_back_forest = this->get_components_by_tag<Rigidbody>("forest_background"); |