diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-10 11:10:05 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-10 11:10:05 +0100 |
commit | a9c6e86e4d95f4f4986be9016779dcc26a925862 (patch) | |
tree | 27fb51d2b1ab0d260cfc6b9ebed4c7fceedcee34 /game | |
parent | 1de7cd3a1265edd2c247f5f847a5665bafd78faa (diff) |
animation working + removed bullet colliding with dead enemies
Diffstat (limited to 'game')
-rw-r--r-- | game/enemy/EnemyBulletSubScene.cpp | 2 | ||||
-rw-r--r-- | game/enemy/EnemyScript.cpp | 12 | ||||
-rw-r--r-- | game/enemy/EnemySubScene.cpp | 6 | ||||
-rw-r--r-- | game/player/PlayerScript.cpp | 2 |
4 files changed, 13 insertions, 9 deletions
diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index 1406660..bc31ba8 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -30,7 +30,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) { .body_type = Rigidbody::BodyType::KINEMATIC, .linear_velocity = vec2 {-300, 0}, .kinematic_collision = false, - .collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_MISSILE, COLL_LAY_ZAPPER}, + .collision_layers = {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 e3c8e9f..22431fd 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -82,6 +82,7 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { this->speed = e.speed; this->alive = true; this->spawned = true; + this->health = 2; RefVector<Animator> animators = this->get_components<Animator>(); for (Animator & anim : animators) { anim.active = false; @@ -99,7 +100,9 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) { Transform & transform = this->get_component<Transform>(); Camera & camera = this->get_components_by_name<Camera>("camera").front(); Transform & cam_transform = this->get_components_by_name<Transform>("camera").front(); - + Rigidbody& rb = this->get_component<Rigidbody>(); + rb.data.collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_PLAYER_BULLET}; + rb.data.collision_layer = COLL_LAY_ENEMY; vec2 half_screen = camera.viewport_size / 2; float x_value = cam_transform.position.x + half_screen.x - 40 * (1 + e.column); uniform_real_distribution<float> dist( @@ -132,7 +135,6 @@ void EnemyScript::set_hit_blink(bool status) { bool EnemyScript::on_collide(const CollisionEvent & e) { if (!this->alive) return false; if (e.info.other.metadata.tag == "player_bullet") { - cout << "health: " << health << endl; this->health--; last_hit = std::chrono::steady_clock::now(); //Sprite& sprite; @@ -160,8 +162,10 @@ void EnemyScript::death() { sprite.data.position_offset.x = 15; } rb.data.linear_velocity_coefficient = {0.5, 1}; - //rb.add_force_linear(vec2{0,20}); - rb.data.gravity_scale = 20; + rb.data.collision_layers = {COLL_LAY_BOT_TOP}; + rb.data.collision_layer = 0; + + rb.data.gravity_scale = 1; tr.rotation = 90; AI & ai = this->get_component<AI>(); ai.active = false; diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index ed3e555..d1117d8 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -33,7 +33,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { }); // normal body Asset enemy_body_asset {"asset/workers/worker2Body.png"}; - enemy.add_component<BoxCollider>(vec2(50, 50)); + enemy.add_component<BoxCollider>(vec2(40, 60)); Sprite & enemy_body_sprite = enemy.add_component<Sprite>( enemy_body_asset, Sprite::Data { @@ -53,7 +53,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { } ); body_animator.pause(); - enemy.add_component<BoxCollider>(vec2(40, 60), vec2(-20, 0)); + Asset enemy_head_asset {"asset/workers/worker2Head.png"}; Sprite & enemy_head_sprite = enemy.add_component<Sprite>( enemy_head_asset, @@ -74,7 +74,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) { ); //jetpack - enemy.add_component<CircleCollider>(25, vec2(0, -20)); + //enemy.add_component<CircleCollider>(25, vec2(0, -20)); Asset enemy_jetpack_asset {"asset/barry/jetpackDefault.png"}; Sprite & enemy_jetpack_sprite = enemy.add_component<Sprite>( enemy_jetpack_asset, diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index c3843ca..0fadade 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -159,7 +159,7 @@ void PlayerScript::fixed_update(crepe::duration_t dt) { if (current_jetpack_sound > 7) { current_jetpack_sound = 0; } - } else if (transform.position.y == 195) { + } else if (transform.position.y == 200) { Rigidbody & rb = this->body; if (prev_anim != 0 && rb.data.linear_velocity.x != 0) { for (Animator & anim : animators) { |