aboutsummaryrefslogtreecommitdiff
path: root/game/enemy/EnemyBulletSubScene.cpp
blob: dd7967812570b0b0cb1cd99c1bf7591ca16da605 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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 "EnemyConfig.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 = "enemy_bullet_" + to_string(counter++);
	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{-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, 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_OBSTACLES,
			.order_in_layer = 1,
			.size = vec2(60,0),
		}
	);
	bullet.add_component<BehaviorScript>().set_script<EnemyBulletScript>();
	return counter;
}