aboutsummaryrefslogtreecommitdiff
path: root/game/enemy/EnemyBulletSubScene.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 10:08:03 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2025-01-08 10:08:03 +0100
commit7f7c5c56dce30d47c32fb57fad6d839d0990b054 (patch)
treeeebc8d3f4c332d969f4a66a566edd844bd43387c /game/enemy/EnemyBulletSubScene.cpp
parentceb41b7ae7e2734af954364b319fc0b6f2a86c2f (diff)
enemy spawn working + enemy shooting
Diffstat (limited to 'game/enemy/EnemyBulletSubScene.cpp')
-rw-r--r--game/enemy/EnemyBulletSubScene.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp
new file mode 100644
index 0000000..1660607
--- /dev/null
+++ b/game/enemy/EnemyBulletSubScene.cpp
@@ -0,0 +1,51 @@
+#include <string>
+
+#include <crepe/api/GameObject.h>
+#include <crepe/api/Scene.h>
+#include <crepe/api/BoxCollider.h>
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/Animator.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/AI.h>
+#include "../Config.h"
+
+
+#include "EnemyBulletSubScene.h"
+#include "EnemyScript.h"
+#include "EnemyBulletScript.h"
+using namespace crepe;
+using namespace std;
+int EnemyBulletSubScene::create(Scene & scn){
+ vec2 size = {20, 20};
+
+ static int counter = 0;
+ string unique_name = "enemyBullet_" + to_string(counter++);
+ GameObject bullet = scn.new_object(unique_name.c_str(),"EnemyBullet",vec2{0,-750},0,1);
+
+ Rigidbody& bullet_body = bullet.add_component<Rigidbody>(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,
+
+
+ });
+ bullet_body.active = false;
+ BoxCollider& bullet_collider = bullet.add_component<BoxCollider>(vec2(60, 40));
+ 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,
+ .order_in_layer = 1,
+ .size = vec2(60,0),
+ }
+ );
+ bullet.add_component<BehaviorScript>().set_script<EnemyBulletScript>();
+ return counter;
+}