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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#include "MissileSubScene.h"
#include "../Config.h"
#include "../missile/MissileScript.h"
#include <crepe/api/AI.h>
#include <crepe/api/Animator.h>
#include <crepe/api/AudioSource.h>
#include <crepe/api/BehaviorScript.h>
#include <crepe/api/CircleCollider.h>
#include <crepe/api/Scene.h>
#include <crepe/api/Sprite.h>
#include <crepe/types.h>
#include <random>
using namespace crepe;
void MissileSubScene::create(crepe::Scene & scn) {
std::random_device rd;
std::mt19937 gen(rd());
GameObject missle = scn.new_object("missile", "missile", {0, 0}, 0, 1);
Asset missle_ss {"asset/obstacles/missile/missile.png"};
Asset missle_thruster_ss {"asset/obstacles/missile/missileEffects.png"};
Asset missile_explosion_ss {"asset/obstacles/missile/missileExplosion.png"};
Asset explosion_sound {"asset/sfx/rocket_explode_1.ogg"};
Asset missile_fire {"asset/sfx/missile_launch.ogg"};
missle.add_component<BehaviorScript>().set_script<MissileScript>().active = false;
auto & sound = missle.add_component<AudioSource>(missile_fire);
sound.volume = 0.5;
auto & sound2 = missle.add_component<AudioSource>(explosion_sound);
sound2.volume = 3;
// sprites
auto & missle_sprite = missle.add_component<Sprite>(
missle_ss,
Sprite::Data {
.flip = {true, false},
.sorting_in_layer = SORT_IN_LAY_OBSTACLES,
.size = {0, 35},
}
);
auto & missle_thruster_sprite = missle.add_component<Sprite>(
missle_thruster_ss,
Sprite::Data {
.flip = {true, false},
.sorting_in_layer = SORT_IN_LAY_OBSTACLES,
.size = {0, 35},
.position_offset = {-20, 0},
}
);
auto & missile_explosion_sprite = missle.add_component<Sprite>(
missile_explosion_ss,
Sprite::Data {
.sorting_in_layer = SORT_IN_LAY_OBSTACLES,
.size = {0, 50},
}
);
// Animations
missle.add_component<Animator>(
missle_sprite, ivec2 {32, 32}, uvec2 {4, 1},
Animator::Data {
.fps = 15,
.looping = true,
}
);
missle.add_component<Animator>(
missle_thruster_sprite, ivec2 {64, 64}, uvec2 {4, 2},
Animator::Data {
.fps = 15,
.looping = true,
}
);
auto & explosion_anim = missle.add_component<Animator>(
missile_explosion_sprite, ivec2 {64, 64}, uvec2 {8, 1},
Animator::Data {
.fps = 10,
}
);
missile_explosion_sprite.active = false;
explosion_anim.active = false;
std::uniform_int_distribution<> dist(200, 250);
missle.add_component<Rigidbody>(Rigidbody::Data {
.body_type = Rigidbody::BodyType::KINEMATIC,
.max_linear_velocity = static_cast<float>(dist(gen)),
.kinematic_collision = false,
.collision_layers = {COLL_LAY_PLAYER, COLL_LAY_BOT_TOP},
.collision_layer = COLL_LAY_MISSILE,
});
missle.add_component<CircleCollider>(3);
auto & missle_ai = missle.add_component<AI>(1000);
}
|