aboutsummaryrefslogtreecommitdiff
path: root/game/player
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 12:17:30 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 12:17:30 +0100
commit1a5744a3285a5ba5132fb4f6f031c27df1b64d33 (patch)
treee1a893eadc08da75910cd4a4e4608959bffde1b7 /game/player
parent49f0f0a24c1557a90530e0d2e0160e221644728a (diff)
enemy death working
Diffstat (limited to 'game/player')
-rw-r--r--game/player/PlayerBulletScript.cpp10
-rw-r--r--game/player/PlayerBulletSubScene.cpp18
-rw-r--r--game/player/PlayerEndScript.cpp2
-rw-r--r--game/player/PlayerScript.cpp12
-rw-r--r--game/player/PlayerSubScene.cpp2
5 files changed, 25 insertions, 19 deletions
diff --git a/game/player/PlayerBulletScript.cpp b/game/player/PlayerBulletScript.cpp
index 50b6617..2bd067d 100644
--- a/game/player/PlayerBulletScript.cpp
+++ b/game/player/PlayerBulletScript.cpp
@@ -17,7 +17,9 @@ void PlayerBulletScript::fixed_update(crepe::duration_t dt){
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& bullet_body = this->get_component<Rigidbody>();
+ transform.rotation += bullet_body.data.angular_velocity;
+ transform.position += bullet_body.data.linear_velocity * dt.count();
vec2 half_screen = camera.viewport_size / 2;
float despawn_location = cam_transform.position.x + half_screen.x + 50;
if(transform.position.x > despawn_location){
@@ -29,11 +31,13 @@ void PlayerBulletScript::despawn_bullet(){
Transform& transform = this->get_component<Transform>();
Rigidbody& bullet_body = this->get_component<Rigidbody>();
bullet_body.active = false;
+ BehaviorScript& bullet_script = this->get_component<BehaviorScript>();
+ bullet_script.active = false;
transform.position = {0,-850};
}
bool PlayerBulletScript::on_collide(const CollisionEvent& e){
- cout << "collision happened with " << e.info.other.metadata.tag << endl;
- //this->despawn_bullet();
+ cout << "player bullet collision happened with " << e.info.other.metadata.tag << endl;
+ this->despawn_bullet();
return false;
}
diff --git a/game/player/PlayerBulletSubScene.cpp b/game/player/PlayerBulletSubScene.cpp
index eb89260..4b36387 100644
--- a/game/player/PlayerBulletSubScene.cpp
+++ b/game/player/PlayerBulletSubScene.cpp
@@ -21,22 +21,24 @@ using namespace std;
int PlayerBulletSubScene::create(Scene & scn){
vec2 size = {20, 20};
static int counter = 0;
- string unique_name = "playerBullet_" + to_string(counter++);
- GameObject player_bullet = scn.new_object(unique_name.c_str(),"PlayerBullet",vec2{0,-850},0,1);
+ string unique_name = "player_bullet_" + to_string(counter++);
+ GameObject player_bullet = scn.new_object(unique_name.c_str(),"player_bullet",vec2{0,-850},0,1);
Rigidbody& player_bullet_body = player_bullet.add_component<Rigidbody>(Rigidbody::Data {
.gravity_scale = 0,
- .body_type = Rigidbody::BodyType::DYNAMIC,
+ .body_type = Rigidbody::BodyType::KINEMATIC,
.linear_velocity = vec2{300,0},
.angular_velocity = 150,
- // .collision_layers = {COLL_LAY_PLAYER},
- // .collision_layer = COLL_LAY_BULLET,
-
+ .kinematic_collision = false,
+ .collision_layers = {COLL_LAY_ENEMY},
+
+ .collision_layer = COLL_LAY_PLAYER_BULLET,
+
});
player_bullet_body.active = false;
BoxCollider& player_bullet_collider = player_bullet.add_component<BoxCollider>(vec2(60, 40));
- player_bullet_collider.active = false;
+ //player_bullet_collider.active = false;
Asset player_bullet_asset {"asset/other_effects/crepe.png"};
Sprite & player_bullet_sprite = player_bullet.add_component<Sprite>(
player_bullet_asset,
@@ -47,6 +49,6 @@ int PlayerBulletSubScene::create(Scene & scn){
.size = vec2(30,0),
}
);
- player_bullet.add_component<BehaviorScript>().set_script<PlayerBulletScript>();
+ player_bullet.add_component<BehaviorScript>().set_script<PlayerBulletScript>().active = false;
return counter;
}
diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp
index 92e48e3..fb18f2f 100644
--- a/game/player/PlayerEndScript.cpp
+++ b/game/player/PlayerEndScript.cpp
@@ -1,4 +1,3 @@
-#include <iostream>
#include "PlayerEndScript.h"
#include "../Config.h"
@@ -24,7 +23,6 @@ void PlayerEndScript::init() {
}
bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) {
- cout << "collision player" << endl;
if (ev.info.other.metadata.name == "floor") {
Transform & transform_player
= this->get_components_by_name<Transform>("player").front();
diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp
index 4e253f4..dc3eec3 100644
--- a/game/player/PlayerScript.cpp
+++ b/game/player/PlayerScript.cpp
@@ -61,7 +61,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) {
audio.play();
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 = true;
anim.set_anim(5);
@@ -157,21 +157,23 @@ void PlayerScript::fixed_update(crepe::duration_t dt) {
}
void PlayerScript::shoot(const vec2& location,float angle){
- cout << "player shot" << endl;
- RefVector<Transform> bullet_transforms = this->get_components_by_tag<Transform>("PlayerBullet");
+ //cout << "player shot" << endl;
+ RefVector<Transform> bullet_transforms = this->get_components_by_tag<Transform>("player_bullet");
for(Transform& bullet_pos : bullet_transforms){
//cout << "bullet pos x: " << bullet_pos.position.x << " y: " << bullet_pos.position.y << endl;
if(bullet_pos.position.x == 0 && bullet_pos.position.y == -850){
- cout << "bullet found\n";
+ //cout << "bullet found\n";
bullet_pos.position = location;
bullet_pos.position.x += 20;
- cout << "bullet pos x: " << bullet_pos.position.x << " y: " << bullet_pos.position.y << endl;
+ //cout << "bullet pos x: " << bullet_pos.position.x << " y: " << bullet_pos.position.y << endl;
Rigidbody& bullet_body = this->get_components_by_id<Rigidbody>(bullet_pos.game_object_id).front();
BoxCollider bullet_collider = this->get_components_by_id<BoxCollider>(bullet_pos.game_object_id).front();
//bullet_collider.active = true;
bullet_body.active = true;
+ BehaviorScript& bullet_script = this->get_components_by_id<BehaviorScript>(bullet_pos.game_object_id).front();
+ bullet_script.active = true;
return;
}
}
diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp
index be104b5..1203ca0 100644
--- a/game/player/PlayerSubScene.cpp
+++ b/game/player/PlayerSubScene.cpp
@@ -152,7 +152,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) {
= {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 = false;
+ player.add_component<BehaviorScript>().set_script<PlayerScript>().active = true;
player.add_component<BehaviorScript>().set_script<CoinScript>();
player.add_component<BehaviorScript>().set_script<PlayerEndScript>().active = false;