aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 14:50:04 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 14:50:04 +0100
commit0de6692dcb029540f4502c5a2f1a0c6634f7b61f (patch)
tree001f373de315b651704b8b264e20314bc878e288
parenta4b9e948ac0acd14d82e009a75e1fccdddeeab9b (diff)
start of extra features and restored player functions
-rw-r--r--game/enemy/EnemyBulletSubScene.cpp2
-rw-r--r--game/enemy/EnemyScript.cpp10
-rw-r--r--game/enemy/EnemySubScene.cpp9
-rw-r--r--game/player/PlayerBulletSubScene.cpp6
-rw-r--r--game/player/PlayerSubScene.cpp6
-rw-r--r--game/workers/CollisionScript.cpp2
6 files changed, 22 insertions, 13 deletions
diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp
index edd8f0c..5c31f1d 100644
--- a/game/enemy/EnemyBulletSubScene.cpp
+++ b/game/enemy/EnemyBulletSubScene.cpp
@@ -30,7 +30,7 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) {
.linear_velocity = vec2 {-250, 0},
.kinematic_collision = false,
- .collision_layers = {COLL_LAY_MISSILE},
+ .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 6558af5..8e475a8 100644
--- a/game/enemy/EnemyScript.cpp
+++ b/game/enemy/EnemyScript.cpp
@@ -8,6 +8,8 @@
#include <crepe/api/ParticleEmitter.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Transform.h>
+#include <crepe/api/AudioSource.h>
+#include <crepe/api/Animator.h>
#include <crepe/types.h>
#include <random>
using namespace crepe;
@@ -82,8 +84,12 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) {
bool EnemyScript::on_collide(const CollisionEvent & e) {
if (e.info.other.metadata.tag == "player_bullet") {
- this->despawn_enemy();
+ //this->despawn_enemy();
+
}
+ Animator& body_animator = this->get_components<Animator>().front();
+ body_animator.data.col = 2;
+ //body_animator.play();
BehaviorScript & enemy_script = this->get_component<BehaviorScript>();
enemy_script.active = false;
return false;
@@ -110,6 +116,8 @@ void EnemyScript::shoot(const vec2 & location, float angle) {
= this->get_components_by_id<BoxCollider>(bullet_pos.game_object_id).front();
bullet_collider.active = true;
bullet_body.active = true;
+ AudioSource& audio = this->get_component<AudioSource>();
+ audio.play();
return;
}
}
diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp
index 7d3e784..8316db9 100644
--- a/game/enemy/EnemySubScene.cpp
+++ b/game/enemy/EnemySubScene.cpp
@@ -8,6 +8,7 @@
#include <crepe/api/GameObject.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Scene.h>
+#include <crepe/api/AudioSource.h>
#include <crepe/api/Sprite.h>
#include "../Config.h"
@@ -45,9 +46,8 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) {
enemy_body_sprite, ivec2(32, 32), uvec2(4, 8),
Animator::Data {
.fps = 5,
- .col = 3,
- .row = 1,
-
+ .col = 1,
+ .row = 0,
.looping = false,
}
);
@@ -91,7 +91,8 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) {
.looping = true,
}
);
-
+ enemy.add_component<AudioSource>(Asset("asset/sfx/bike_gun_2.ogg")).volume
+ = 0.1;
AI & ai_component = enemy.add_component<AI>(3000);
ai_component.path_follow_on();
BehaviorScript & enemy_script
diff --git a/game/player/PlayerBulletSubScene.cpp b/game/player/PlayerBulletSubScene.cpp
index 62bcf3e..2d237de 100644
--- a/game/player/PlayerBulletSubScene.cpp
+++ b/game/player/PlayerBulletSubScene.cpp
@@ -24,10 +24,10 @@ int PlayerBulletSubScene::create(Scene & scn, int counter) {
Rigidbody & player_bullet_body = player_bullet.add_component<Rigidbody>(Rigidbody::Data {
.gravity_scale = 0,
.body_type = Rigidbody::BodyType::KINEMATIC,
- .linear_velocity = vec2 {300, 0},
- .angular_velocity = 150,
+ .linear_velocity = vec2 {400, 0},
+ .angular_velocity = 10,
.kinematic_collision = false,
- .collision_layers = {COLL_LAY_ENEMY},
+ .collision_layers = {COLL_LAY_ENEMY,COLL_LAY_ZAPPER},
.collision_layer = COLL_LAY_PLAYER_BULLET,
diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp
index cf11162..c4d689a 100644
--- a/game/player/PlayerSubScene.cpp
+++ b/game/player/PlayerSubScene.cpp
@@ -22,7 +22,7 @@ using namespace crepe;
using namespace std;
PlayerSubScene::PlayerSubScene(Scene & scn) {
- GameObject player = scn.new_object("player", "player", vec2(300, 200));
+ GameObject player = scn.new_object("player", "player", vec2(-100, 200));
Asset player_bullet {"asset/other_effects/effect_smgbullet.png"};
Sprite & player_bullet_sprite = player.add_component<Sprite>(
@@ -147,13 +147,13 @@ PlayerSubScene::PlayerSubScene(Scene & scn) {
player.add_component<Rigidbody>(Rigidbody::Data {
.gravity_scale = PLAYER_GRAVITY_SCALE,
.body_type = Rigidbody::BodyType::DYNAMIC,
- //.linear_velocity = vec2(PLAYER_SPEED * 0.02, 0),
+ .linear_velocity = vec2(PLAYER_SPEED * 0.02, 0),
.collision_layers
= {COLL_LAY_BOT_TOP, COLL_LAY_ZAPPER, COLL_LAY_LASER, COLL_LAY_MISSILE, COLL_LAY_BULLET
},
.collision_layer = COLL_LAY_PLAYER,
});
- player.add_component<BehaviorScript>().set_script<PlayerScript>().active = true;
+ player.add_component<BehaviorScript>().set_script<PlayerScript>().active = false;
player.add_component<BehaviorScript>().set_script<CoinScript>();
player.add_component<BehaviorScript>().set_script<PlayerEndScript>().active = false;
diff --git a/game/workers/CollisionScript.cpp b/game/workers/CollisionScript.cpp
index deaf0ee..625044d 100644
--- a/game/workers/CollisionScript.cpp
+++ b/game/workers/CollisionScript.cpp
@@ -49,7 +49,7 @@ bool CollisionScript::on_collision(const CollisionEvent & ev) {
bs_panic.active = false;
return false;
- } else if (ev.info.other.metadata.tag == "missile") {
+ } else if (ev.info.other.metadata.tag == "missile" || ev.info.other.metadata.tag == "enemy_bullet") {
for (Animator & anim : animators) {
anim.active = false;
anim.set_anim(3);