diff options
| author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-08 12:38:24 +0100 | 
|---|---|---|
| committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2025-01-08 12:38:24 +0100 | 
| commit | 9625b751757b8828b0edb0b7543c7cadfd25c119 (patch) | |
| tree | 864d26cb57fe11887f4cd10923cd9a9d0b823af4 | |
| parent | dc5d46426b30303843e8746d514db6f55ce1495b (diff) | |
enemy sequence working
| -rw-r--r-- | game/enemy/EnemyBulletScript.cpp | 4 | ||||
| -rw-r--r-- | game/enemy/EnemyBulletSubScene.cpp | 10 | ||||
| -rw-r--r-- | game/enemy/EnemyConfig.h | 7 | ||||
| -rw-r--r-- | game/enemy/EnemyScript.cpp | 8 | ||||
| -rw-r--r-- | game/enemy/EnemySubScene.cpp | 18 | ||||
| -rw-r--r-- | game/player/PlayerBulletScript.cpp | 2 | ||||
| -rw-r--r-- | game/player/PlayerBulletSubScene.cpp | 7 | ||||
| -rw-r--r-- | game/player/PlayerScript.cpp | 9 | 
8 files changed, 33 insertions, 32 deletions
| diff --git a/game/enemy/EnemyBulletScript.cpp b/game/enemy/EnemyBulletScript.cpp index ba27b9d..55160ab 100644 --- a/game/enemy/EnemyBulletScript.cpp +++ b/game/enemy/EnemyBulletScript.cpp @@ -3,6 +3,8 @@  #include <crepe/api/Camera.h>  #include <crepe/api/Rigidbody.h>  #include <crepe/api/Metadata.h> + +#include "EnemyConfig.h"  using namespace crepe;  using namespace std;  void EnemyBulletScript::init(){ @@ -28,7 +30,7 @@ void EnemyBulletScript::despawn_bullet(){  	Transform& transform = this->get_component<Transform>();  	Rigidbody& bullet_body = this->get_component<Rigidbody>();  	bullet_body.active = false; -	transform.position = {0,-750}; +	transform.position = ENEMY_BULLET_POOL_LOCATION;  }  bool EnemyBulletScript::on_collide(const CollisionEvent& e){ diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp index 488dc03..dd79678 100644 --- a/game/enemy/EnemyBulletSubScene.cpp +++ b/game/enemy/EnemyBulletSubScene.cpp @@ -10,7 +10,7 @@  #include <crepe/api/Sprite.h>  #include <crepe/api/AI.h>  #include "../Config.h" - +#include "EnemyConfig.h"  #include "EnemyBulletSubScene.h"  #include "EnemyScript.h" @@ -22,26 +22,26 @@ int EnemyBulletSubScene::create(Scene & scn){  	static int counter = 0;  	string unique_name = "enemy_bullet_" + to_string(counter++); -	GameObject bullet = scn.new_object(unique_name.c_str(),"enemy_bullet",vec2{0,-750},0,1); +	GameObject bullet = scn.new_object(unique_name.c_str(),"enemy_bullet",ENEMY_BULLET_POOL_LOCATION,0,1);  	Rigidbody& bullet_body = bullet.add_component<Rigidbody>(Rigidbody::Data {  		.gravity_scale = 0,  		.body_type = Rigidbody::BodyType::KINEMATIC, -		.linear_velocity = vec2{-300,0}, +		.linear_velocity = vec2{-250,0},  		.kinematic_collision = false,  		.collision_layers = {COLL_LAY_MISSILE},  		.collision_layer = COLL_LAY_BULLET  	});  	bullet_body.active = false; -	BoxCollider& bullet_collider = bullet.add_component<BoxCollider>(vec2(60, 40)); +	BoxCollider& bullet_collider = bullet.add_component<BoxCollider>(vec2(60, 30));  	//bullet_collider.active = false;  	Asset bullet_asset {"asset/other_effects/effect_smgbullet_x2.png"};  	Sprite & bullet_sprite = bullet.add_component<Sprite>(  		bullet_asset,  		Sprite::Data {  			.flip = {true,false}, -			.sorting_in_layer = SORT_IN_LAY_PLAYER, +			.sorting_in_layer = SORT_IN_LAY_OBSTACLES,  			.order_in_layer = 1,  			.size = vec2(60,0),  		} diff --git a/game/enemy/EnemyConfig.h b/game/enemy/EnemyConfig.h new file mode 100644 index 0000000..f7b660a --- /dev/null +++ b/game/enemy/EnemyConfig.h @@ -0,0 +1,7 @@ +#pragma once +#include <crepe/types.h> + +//button config +// static constexpr crepe::vec2 PLAYER_BULLET_POOL_LOCATION = {0, -850}; +static constexpr crepe::vec2 ENEMY_BULLET_POOL_LOCATION = {0, -750}; +static constexpr crepe::vec2 ENEMY_POOL_LOCATION = {0, -650}; diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp index 2bdab2c..4b75846 100644 --- a/game/enemy/EnemyScript.cpp +++ b/game/enemy/EnemyScript.cpp @@ -9,12 +9,13 @@  #include <crepe/types.h>  #include <random>  #include "../Random.h" +#include "EnemyConfig.h"  using namespace crepe;  using namespace std;  EnemyScript::EnemyScript(){  	engine.seed(rd());  	this->last_fired = std::chrono::steady_clock::now(); -	this->shot_delay = std::chrono::duration<float>(2.5 + Random::f(0,1)); +	this->shot_delay = std::chrono::duration<float>(3 + Random::f(0,1));  }  void EnemyScript::init(){  	Metadata& meta = this->get_component<Metadata>(); @@ -51,7 +52,7 @@ void EnemyScript::fixed_update(duration_t dt) {  	if (elapsed > shot_delay) {      	this->shoot(transform.position,0);  		last_fired = now; -		this->shot_delay = std::chrono::duration<float>(Random::f(0.8,4)); +		this->shot_delay = std::chrono::duration<float>(Random::f(1,4));  	}  } @@ -71,7 +72,6 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent& e){  	float random_height = dist(engine);  	vec2 spawn_location = {cam_transform.position.x + camera.viewport_size.x / 2 + 100,random_height};  	transform.position = spawn_location; -	// transform.position = vec2{cam_transform}  	ai_component.path.clear();  	ai_component.make_oval_path(10, 10, vec2{x_value,random_height}, 1.5708, true);  	ai_component.active = true; @@ -86,7 +86,7 @@ bool EnemyScript::on_collide(const CollisionEvent & e){  }  void EnemyScript::despawn_enemy(){  	Transform& transform = this->get_component<Transform>(); -	transform.position = vec2{0,-650}; +	transform.position = ENEMY_POOL_LOCATION;  	AI& ai_component = this->get_component<AI>();  	// Rigidbody& enemy_body  	ai_component.active = false; diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp index 43f9b33..66aedd5 100644 --- a/game/enemy/EnemySubScene.cpp +++ b/game/enemy/EnemySubScene.cpp @@ -1,7 +1,6 @@  #include <string> -#include "EnemySubScene.h" -#include "EnemyScript.h" +  #include <crepe/api/GameObject.h>  #include <crepe/api/Scene.h>  #include <crepe/api/BoxCollider.h> @@ -10,21 +9,24 @@  #include <crepe/api/BehaviorScript.h>  #include <crepe/api/Animator.h>  #include <crepe/api/Sprite.h> -  #include <crepe/api/AI.h> +  #include "../Config.h" +#include "EnemySubScene.h" +#include "EnemyScript.h" +#include "EnemyConfig.h"  using namespace crepe;  using namespace std; +//#TODO add sound  int EnemySubScene::create(Scene & scn){  	vec2 size = {20, 20};  	static int enemy_counter = 0;  	string unique_name = "enemy_" + to_string(enemy_counter++); -	GameObject enemy = scn.new_object(unique_name.c_str(),"enemy",vec2{0,-650},0,1); +	GameObject enemy = scn.new_object(unique_name.c_str(),"enemy",ENEMY_POOL_LOCATION,0,1);  	enemy.add_component<Rigidbody>(Rigidbody::Data {  		.gravity_scale = 0, -		  		.body_type = Rigidbody::BodyType::DYNAMIC,  		.max_linear_velocity = 400,  		.collision_layers = {COLL_LAY_BOT_TOP,COLL_LAY_PLAYER_BULLET}, @@ -37,7 +39,7 @@ int EnemySubScene::create(Scene & scn){  		enemy_body_asset,  		Sprite::Data {  			.flip = {true,false}, -			.sorting_in_layer = SORT_IN_LAY_PLAYER, +			.sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT,  			.order_in_layer = 0,  			.size = vec2(0, 50),  		} @@ -59,7 +61,7 @@ int EnemySubScene::create(Scene & scn){  		enemy_head_asset,  		Sprite::Data {  			.flip = {true,false}, -			.sorting_in_layer = SORT_IN_LAY_PLAYER, +			.sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT,  			.order_in_layer = 1,  			.size = vec2(0, 50),  			.position_offset = vec2(0, -20), @@ -78,7 +80,7 @@ int EnemySubScene::create(Scene & scn){  		enemy_jetpack_asset,  		Sprite::Data {  			.flip = {true,false}, -			.sorting_in_layer = SORT_IN_LAY_PLAYER, +			.sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT,  			.order_in_layer = 2,  			.size = vec2(0, 60),  			.position_offset = vec2(20, 0), diff --git a/game/player/PlayerBulletScript.cpp b/game/player/PlayerBulletScript.cpp index 2bd067d..6beb9f1 100644 --- a/game/player/PlayerBulletScript.cpp +++ b/game/player/PlayerBulletScript.cpp @@ -1,4 +1,3 @@ -#include <iostream>  #include <crepe/api/Camera.h>  #include <crepe/api/Rigidbody.h> @@ -37,7 +36,6 @@ void PlayerBulletScript::despawn_bullet(){  }  bool PlayerBulletScript::on_collide(const CollisionEvent& e){ -	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 4b36387..4ad236c 100644 --- a/game/player/PlayerBulletSubScene.cpp +++ b/game/player/PlayerBulletSubScene.cpp @@ -1,4 +1,3 @@ -#include <iostream>  #include <string>  #include <crepe/api/GameObject.h> @@ -37,14 +36,14 @@ int PlayerBulletSubScene::create(Scene & scn){  	});  	player_bullet_body.active = false; -	BoxCollider& player_bullet_collider = player_bullet.add_component<BoxCollider>(vec2(60, 40)); -	//player_bullet_collider.active = false; +	BoxCollider& player_bullet_collider = player_bullet.add_component<BoxCollider>(vec2(30, 30)); +  	Asset player_bullet_asset {"asset/other_effects/crepe.png"};  	Sprite & player_bullet_sprite = player_bullet.add_component<Sprite>(  		player_bullet_asset,  		Sprite::Data {  			.flip = {true,false}, -			.sorting_in_layer = SORT_IN_LAY_PLAYER, +			.sorting_in_layer = SORT_IN_LAY_OBSTACLES,  			.order_in_layer = 1,  			.size = vec2(30,0),  		} diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index dc3eec3..7bc5e55 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -1,4 +1,3 @@ -#include <iostream>  #include "PlayerScript.h"  #include "../Config.h" @@ -157,25 +156,19 @@ 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>("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"; +  			bullet_pos.position = location;  			bullet_pos.position.x += 20; -			//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;  		}  	} -	cout << "bullet not found\n";  } |