From 7f7c5c56dce30d47c32fb57fad6d839d0990b054 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 8 Jan 2025 10:08:03 +0100 Subject: enemy spawn working + enemy shooting --- game/player/PlayerBulletSubScene.cpp | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 game/player/PlayerBulletSubScene.cpp (limited to 'game/player/PlayerBulletSubScene.cpp') diff --git a/game/player/PlayerBulletSubScene.cpp b/game/player/PlayerBulletSubScene.cpp new file mode 100644 index 0000000..eb34046 --- /dev/null +++ b/game/player/PlayerBulletSubScene.cpp @@ -0,0 +1,51 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../Config.h" + + +#include "PlayerBulletSubScene.h" +#include "PlayerScript.h" +#include "PlayerBulletScript.h" +using namespace crepe; +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); + + Rigidbody& player_bullet_body = player_bullet.add_component(Rigidbody::Data { + .gravity_scale = 0, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = vec2{-300,0}, + .collision_layers = {COLL_LAY_PLAYER}, + .collision_layer = COLL_LAY_BULLET, + + + }); + player_bullet_body.active = false; + BoxCollider& player_bullet_collider = player_bullet.add_component(vec2(60, 40)); + player_bullet_collider.active = false; + Asset player_bullet_asset {"asset/other_effects/effect_smgbullet_x2.png"}; + Sprite & player_bullet_sprite = player_bullet.add_component( + player_bullet_asset, + Sprite::Data { + .flip = {true,false}, + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 1, + .size = vec2(60,0), + } + ); + player_bullet.add_component().set_script(); + return counter; +} -- cgit v1.2.3