aboutsummaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorMax-001 <maxsmits21@kpnmail.nl>2025-01-10 17:07:28 +0100
committerMax-001 <maxsmits21@kpnmail.nl>2025-01-10 17:07:28 +0100
commit912774706bab1e7817facb3cff12e961a89d1980 (patch)
tree0896b12c29dccc247c69e54daaa32d8ce3097ed0 /game
parent90a33d36c34b1512270a6724564995dd8bf914a6 (diff)
parent7aa07561a52016007ff852acefa4db68260f0f1e (diff)
Merge remote-tracking branch 'origin/wouter/game-improvements' into max/game2
Diffstat (limited to 'game')
-rw-r--r--game/enemy/BattleScript.cpp36
-rw-r--r--game/enemy/BattleScript.h2
-rw-r--r--game/enemy/EnemyBulletScript.cpp2
-rw-r--r--game/enemy/EnemyBulletSubScene.cpp7
-rw-r--r--game/enemy/EnemyConfig.h1
-rw-r--r--game/enemy/EnemyPool.cpp2
-rw-r--r--game/enemy/EnemyPool.h5
-rw-r--r--game/enemy/EnemyScript.cpp128
-rw-r--r--game/enemy/EnemyScript.h14
-rw-r--r--game/enemy/EnemySubScene.cpp24
-rw-r--r--game/main.cpp1
-rw-r--r--game/player/PlayerBulletSubScene.cpp2
-rw-r--r--game/player/PlayerScript.cpp2
-rw-r--r--game/player/PlayerScript.h3
-rw-r--r--game/player/PlayerSubScene.cpp5
-rw-r--r--game/scheduler/ObjectsScheduler.cpp26
16 files changed, 200 insertions, 60 deletions
diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp
index 6d96ef6..798cbb9 100644
--- a/game/enemy/BattleScript.cpp
+++ b/game/enemy/BattleScript.cpp
@@ -1,5 +1,7 @@
#include "BattleScript.h"
+#include "EnemyConfig.h"
#include "EnemyScript.h"
+#include "api/Transform.h"
#include <crepe/api/AI.h>
#include <crepe/api/BehaviorScript.h>
#include <crepe/api/Metadata.h>
@@ -18,11 +20,10 @@ void BattleScript::init() {
void BattleScript::fixed_update(duration_t dt) {
if (!battle_active) return;
bool enemies_alive = false;
- RefVector<BehaviorScript> enemy_scripts
- = this->get_components_by_tag<BehaviorScript>("enemy");
+ RefVector<AI> enemy_ai = this->get_components_by_tag<AI>("enemy");
- for (BehaviorScript & script : enemy_scripts) {
- if (script.active) {
+ for (AI & ai : enemy_ai) {
+ if (ai.active) {
enemies_alive = true;
}
}
@@ -32,20 +33,29 @@ void BattleScript::fixed_update(duration_t dt) {
}
}
bool BattleScript::create_battle(const BattleStartEvent & e) {
- this->battle_active = true;
- RefVector<BehaviorScript> enemy_scripts
- = this->get_components_by_tag<BehaviorScript>("enemy");
- std::uniform_real_distribution<float> dist(10, 30);
- for (int i = 0; i < e.num_enemies; i++) {
- BehaviorScript & script = enemy_scripts[i];
- script.active = true;
+ this->battle_active = e.battle;
+ this->spawn_enemies(e.num_enemies);
+ return false;
+}
+void BattleScript::spawn_enemies(int amount) {
+ RefVector<AI> enemy_ai = this->get_components_by_tag<AI>("enemy");
+ std::uniform_real_distribution<float> dist(70, 150);
+ int spawned = 0;
+ for (int i = 0; i < ENEMY_POOL_MAX; i++) {
+ AI & ai = enemy_ai[i];
+ Transform & enemy_transform
+ = this->get_components_by_id<Transform>(ai.game_object_id).front();
+ if (ai.active == true || enemy_transform.position != ENEMY_POOL_LOCATION) continue;
this->queue_event<SpawnEnemyEvent>(
SpawnEnemyEvent {
.speed = dist(engine),
.column = i,
},
- script.game_object_id
+ ai.game_object_id
);
+ spawned++;
+ if (spawned >= amount) {
+ return;
+ }
}
- return false;
}
diff --git a/game/enemy/BattleScript.h b/game/enemy/BattleScript.h
index ddd0be1..57aa16c 100644
--- a/game/enemy/BattleScript.h
+++ b/game/enemy/BattleScript.h
@@ -9,6 +9,7 @@ struct BattleWonEvent : public crepe::Event {};
struct BattleStartEvent : public crepe::Event {
public:
int num_enemies = 0;
+ bool battle = false;
};
class BattleScript : public crepe::Script {
public:
@@ -20,5 +21,6 @@ private:
bool battle_active = false;
std::random_device rd;
std::default_random_engine engine;
+ void spawn_enemies(int amount);
bool create_battle(const BattleStartEvent & e);
};
diff --git a/game/enemy/EnemyBulletScript.cpp b/game/enemy/EnemyBulletScript.cpp
index 65c0c23..d208a88 100644
--- a/game/enemy/EnemyBulletScript.cpp
+++ b/game/enemy/EnemyBulletScript.cpp
@@ -18,7 +18,7 @@ void EnemyBulletScript::fixed_update(crepe::duration_t dt) {
Transform & cam_transform = this->get_components_by_name<Transform>("camera").front();
Rigidbody & bullet_body = this->get_component<Rigidbody>();
//move
- transform.position.x += bullet_body.data.linear_velocity.x * dt.count();
+ transform.position += bullet_body.data.linear_velocity * dt.count();
vec2 half_screen = camera.viewport_size / 2;
float despawn_location = cam_transform.position.x - half_screen.x - 50;
if (transform.position.x < despawn_location) {
diff --git a/game/enemy/EnemyBulletSubScene.cpp b/game/enemy/EnemyBulletSubScene.cpp
index ad2ca9d..bc31ba8 100644
--- a/game/enemy/EnemyBulletSubScene.cpp
+++ b/game/enemy/EnemyBulletSubScene.cpp
@@ -16,6 +16,7 @@
#include "EnemyBulletScript.h"
#include "EnemyBulletSubScene.h"
#include "EnemyScript.h"
+#include "api/Color.h"
using namespace crepe;
using namespace std;
int EnemyBulletSubScene::create(Scene & scn, int counter) {
@@ -27,19 +28,19 @@ int EnemyBulletSubScene::create(Scene & scn, int counter) {
Rigidbody & bullet_body = bullet.add_component<Rigidbody>(Rigidbody::Data {
.gravity_scale = 0,
.body_type = Rigidbody::BodyType::KINEMATIC,
-
- .linear_velocity = vec2 {-250, 0},
+ .linear_velocity = vec2 {-300, 0},
.kinematic_collision = false,
.collision_layers = {COLL_LAY_MISSILE, COLL_LAY_ZAPPER},
.collision_layer = COLL_LAY_BULLET
});
bullet_body.active = false;
- BoxCollider & bullet_collider = bullet.add_component<BoxCollider>(vec2(60, 30));
+ BoxCollider & bullet_collider = bullet.add_component<BoxCollider>(vec2(40, 10));
//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 {
+ .color = Color::BLUE,
.flip = {true, false},
.sorting_in_layer = SORT_IN_LAY_OBSTACLES,
.order_in_layer = 1,
diff --git a/game/enemy/EnemyConfig.h b/game/enemy/EnemyConfig.h
index f7b660a..f9fb469 100644
--- a/game/enemy/EnemyConfig.h
+++ b/game/enemy/EnemyConfig.h
@@ -5,3 +5,4 @@
// 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};
+static constexpr int ENEMY_POOL_MAX = 12;
diff --git a/game/enemy/EnemyPool.cpp b/game/enemy/EnemyPool.cpp
index a7179bf..135fc35 100644
--- a/game/enemy/EnemyPool.cpp
+++ b/game/enemy/EnemyPool.cpp
@@ -4,7 +4,7 @@ using namespace std;
void EnemyPool::create_enemies(crepe::Scene & scn) {
EnemySubScene enemy;
int amount = 0;
- while (amount < this->MAXIMUM_AMOUNT) {
+ while (amount < ENEMY_POOL_MAX) {
amount = enemy.create(scn, amount);
}
}
diff --git a/game/enemy/EnemyPool.h b/game/enemy/EnemyPool.h
index f4d6765..cfd0b1c 100644
--- a/game/enemy/EnemyPool.h
+++ b/game/enemy/EnemyPool.h
@@ -1,11 +1,8 @@
#pragma once
+#include "EnemyConfig.h"
#include <crepe/api/Scene.h>
-
class EnemyPool {
public:
void create_enemies(crepe::Scene & scn);
-
-private:
- static constexpr int MAXIMUM_AMOUNT = 10;
};
diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp
index 5c03539..0822c29 100644
--- a/game/enemy/EnemyScript.cpp
+++ b/game/enemy/EnemyScript.cpp
@@ -1,13 +1,16 @@
#include "EnemyScript.h"
#include "../Config.h"
#include "../Random.h"
-#include "EnemyConfig.h"
+#include "../enemy/EnemyConfig.h"
+#include "api/Color.h"
+#include "api/Sprite.h"
#include <crepe/api/AI.h>
#include <crepe/api/Animator.h>
#include <crepe/api/AudioSource.h>
#include <crepe/api/BoxCollider.h>
#include <crepe/api/ParticleEmitter.h>
#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Sprite.h>
#include <crepe/api/Transform.h>
#include <crepe/types.h>
#include <random>
@@ -16,7 +19,7 @@ using namespace std;
EnemyScript::EnemyScript() {
engine.seed(rd());
this->last_fired = std::chrono::steady_clock::now();
- this->shot_delay = std::chrono::duration<float>(3 + Random::f(1, 0));
+ this->shot_delay = std::chrono::duration<float>(1.5 + Random::f(2, 0));
}
void EnemyScript::init() {
Metadata & meta = this->get_component<Metadata>();
@@ -29,43 +32,78 @@ void EnemyScript::init() {
});
};
void EnemyScript::fixed_update(duration_t dt) {
- if (this->alive) {
- return;
+ if (!spawned) return;
+ auto now = std::chrono::steady_clock::now();
+ std::chrono::duration<float> elapsed_hit = now - last_hit;
+ //hit blink timer
+ if (elapsed_hit > blink_time) {
+ set_hit_blink(false);
}
Transform & transform = this->get_component<Transform>();
+ if (!this->alive) {
+ Camera & camera = this->get_components_by_name<Camera>("camera").front();
+ Transform & cam_transform = this->get_components_by_name<Transform>("camera").front();
+ vec2 half_screen = camera.viewport_size / 2;
+ float x_value = cam_transform.position.x - half_screen.x - 100;
+ if (transform.position.x < x_value) {
+ this->despawn_enemy();
+ }
+ return;
+ }
+
Transform & player_transform = this->get_components_by_name<Transform>("player").front();
Rigidbody & enemy_body = this->get_component<Rigidbody>();
AI & ai_component = this->get_component<AI>();
- //transform.position += enemy_body.data.linear_velocity * dt.count();
float direction_to_player_y = player_transform.position.y - transform.position.y;
float distance_to_player_y = std::abs(direction_to_player_y);
float adjustment_speed = speed * (distance_to_player_y / MAX_DISTANCE);
-
adjustment_speed = std::clamp(adjustment_speed, MIN_SPEED, MAX_SPEED);
- // Move the path nodes on the Y-axis
+ Rigidbody & player_body = this->get_components_by_tag<Rigidbody>("player").front();
+ // move path nodes
for (vec2 & path_node : ai_component.path) {
path_node.y += (direction_to_player_y > 0 ? 1 : -1) * adjustment_speed * dt.count();
+ path_node.x += player_body.data.linear_velocity.x * dt.count();
}
//bullet fire logic:
- auto now = std::chrono::steady_clock::now();
+
std::chrono::duration<float> elapsed = now - last_fired;
if (elapsed > shot_delay) {
- this->shoot(transform.position, 0);
+ this->shoot(transform.position);
last_fired = now;
- this->shot_delay = std::chrono::duration<float>(Random::f(4, 1));
+ this->shot_delay = std::chrono::duration<float>(Random::f(3, 1.5));
}
}
+
bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) {
+
this->speed = e.speed;
+ this->alive = true;
+ this->spawned = true;
+ this->health = 2;
+ RefVector<Animator> animators = this->get_components<Animator>();
+ for (Animator & anim : animators) {
+ anim.active = false;
+ anim.set_anim(0);
+ }
+ RefVector<Sprite> sprites = this->get_components<Sprite>();
+ for (Sprite & sprite : sprites) {
+ sprite.data.position_offset.x = 0;
+ }
+ Sprite & jetpack = sprites[2];
+ jetpack.data.position_offset.x = 20;
+ Sprite & gun = sprites[3];
+ gun.data.position_offset.x = -20;
AI & ai_component = this->get_component<AI>();
Transform & transform = this->get_component<Transform>();
Camera & camera = this->get_components_by_name<Camera>("camera").front();
Transform & cam_transform = this->get_components_by_name<Transform>("camera").front();
-
+ Rigidbody & rb = this->get_component<Rigidbody>();
+ rb.data.collision_layers = {COLL_LAY_BOT_TOP, COLL_LAY_PLAYER_BULLET};
+ rb.data.collision_layer = COLL_LAY_ENEMY;
vec2 half_screen = camera.viewport_size / 2;
- float x_value = cam_transform.position.x + half_screen.x - 50 * (1 + e.column);
+ float x_value = cam_transform.position.x + half_screen.x - 40 * (1 + e.column);
uniform_real_distribution<float> dist(
cam_transform.position.y - half_screen.y + 100,
cam_transform.position.y + half_screen.y - 100
@@ -75,31 +113,77 @@ bool EnemyScript::spawn_enemy(const SpawnEnemyEvent & e) {
= {cam_transform.position.x + camera.viewport_size.x / 2 + 100, random_height};
transform.position = spawn_location;
ai_component.path.clear();
- ai_component.make_oval_path(10, 10, vec2 {x_value, random_height}, 1.5708, true);
+ ai_component.make_oval_path(10, 30, vec2 {x_value, random_height}, 1.5708, true);
ai_component.active = true;
this->last_fired = std::chrono::steady_clock::now();
+
return false;
}
+void EnemyScript::set_hit_blink(bool status) {
+ RefVector<Sprite> sprites = this->get_components<Sprite>();
+ for (Sprite & sprite : sprites) {
+ if (status) {
+ sprite.data.color = Color::RED;
+ continue;
+ }
+ sprite.data.color = Color::WHITE;
+ }
+}
+
bool EnemyScript::on_collide(const CollisionEvent & e) {
+ if (!this->alive) return false;
if (e.info.other.metadata.tag == "player_bullet") {
- this->despawn_enemy();
+ this->health--;
+ last_hit = std::chrono::steady_clock::now();
+ //Sprite& sprite;
+ set_hit_blink(true);
+ if (health <= 0) {
+ this->death();
+ }
}
- Animator & body_animator = this->get_components<Animator>().front();
- body_animator.data.col = 2;
+
//body_animator.play();
- BehaviorScript & enemy_script = this->get_component<BehaviorScript>();
- enemy_script.active = false;
+
return false;
}
+void EnemyScript::death() {
+
+ Rigidbody & rb = this->get_component<Rigidbody>();
+ Transform & tr = this->get_component<Transform>();
+ RefVector<Animator> animators = this->get_components<Animator>();
+ for (Animator & anim : animators) {
+ anim.active = false;
+ anim.set_anim(3);
+ }
+ RefVector<Sprite> sprites = this->get_components<Sprite>();
+ for (Sprite & sprite : sprites) {
+ sprite.data.position_offset.x = 15;
+ }
+ rb.data.linear_velocity_coefficient = {0.5, 1};
+ rb.data.collision_layers = {COLL_LAY_BOT_TOP};
+ rb.data.collision_layer = 0;
+
+ rb.data.gravity_scale = 1;
+ tr.rotation = 90;
+ AI & ai = this->get_component<AI>();
+ ai.active = false;
+ this->alive = false;
+ AI & ai_component = this->get_component<AI>();
+ ai_component.active = false;
+}
void EnemyScript::despawn_enemy() {
Transform & transform = this->get_component<Transform>();
+ Rigidbody & rb = this->get_component<Rigidbody>();
+ rb.data.gravity_scale = 0;
+ rb.data.linear_velocity = {0, 0};
+ transform.rotation = 0;
transform.position = ENEMY_POOL_LOCATION;
- AI & ai_component = this->get_component<AI>();
- // Rigidbody& enemy_body
- ai_component.active = false;
+
+ this->spawned = false;
}
-void EnemyScript::shoot(const vec2 & location, float angle) {
+
+void EnemyScript::shoot(const vec2 & location) {
RefVector<Transform> bullet_transforms
= this->get_components_by_tag<Transform>("enemy_bullet");
diff --git a/game/enemy/EnemyScript.h b/game/enemy/EnemyScript.h
index 42ecac4..be71a78 100644
--- a/game/enemy/EnemyScript.h
+++ b/game/enemy/EnemyScript.h
@@ -13,19 +13,25 @@ public:
EnemyScript();
void init() override;
void fixed_update(crepe::duration_t dt) override;
- void shoot(const crepe::vec2 & position, float angle);
+ void shoot(const crepe::vec2 & position);
bool on_collide(const crepe::CollisionEvent & collisionData);
void despawn_enemy();
bool spawn_enemy(const SpawnEnemyEvent & e);
+ void death();
+ void set_hit_blink(bool status);
private:
std::random_device rd;
std::default_random_engine engine;
bool alive = false;
+ bool spawned = false;
float speed = 50;
- const float MIN_SPEED = 10;
- const float MAX_SPEED = 130;
- const float MAX_DISTANCE = 100;
+ int health = 2;
+ const float MIN_SPEED = 20;
+ const float MAX_SPEED = 150;
+ const float MAX_DISTANCE = 200;
std::chrono::time_point<std::chrono::steady_clock> last_fired;
+ std::chrono::time_point<std::chrono::steady_clock> last_hit;
std::chrono::duration<float> shot_delay = std::chrono::duration<float>(0);
+ std::chrono::duration<float> blink_time = std::chrono::duration<float>(0.1);
};
diff --git a/game/enemy/EnemySubScene.cpp b/game/enemy/EnemySubScene.cpp
index 607b9a9..c6aecec 100644
--- a/game/enemy/EnemySubScene.cpp
+++ b/game/enemy/EnemySubScene.cpp
@@ -31,8 +31,9 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) {
.collision_layer = COLL_LAY_ENEMY,
});
+ // normal body
Asset enemy_body_asset {"asset/workers/worker2Body.png"};
- enemy.add_component<BoxCollider>(vec2(50, 50));
+ enemy.add_component<BoxCollider>(vec2(40, 60));
Sprite & enemy_body_sprite = enemy.add_component<Sprite>(
enemy_body_asset,
Sprite::Data {
@@ -52,7 +53,7 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) {
}
);
body_animator.pause();
- enemy.add_component<BoxCollider>(vec2(40, 60), vec2(-20, 0));
+
Asset enemy_head_asset {"asset/workers/worker2Head.png"};
Sprite & enemy_head_sprite = enemy.add_component<Sprite>(
enemy_head_asset,
@@ -71,7 +72,9 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) {
.looping = true,
}
);
- enemy.add_component<CircleCollider>(25, vec2(0, -20));
+
+ //jetpack
+ //enemy.add_component<CircleCollider>(25, vec2(0, -20));
Asset enemy_jetpack_asset {"asset/barry/jetpackDefault.png"};
Sprite & enemy_jetpack_sprite = enemy.add_component<Sprite>(
enemy_jetpack_asset,
@@ -91,11 +94,24 @@ int EnemySubScene::create(Scene & scn, int enemy_counter) {
.looping = true,
}
);
+ //gun
+ Asset enemy_pistol_asset {"asset/workers/gun.png"};
+ Sprite & enemy_pistol_sprite = enemy.add_component<Sprite>(
+ enemy_pistol_asset,
+ Sprite::Data {
+ .flip = {false, false},
+ .sorting_in_layer = SORT_IN_LAY_WORKERS_FRONT,
+ .order_in_layer = 2,
+ .size = vec2(0, 20),
+ .position_offset = vec2(-20, 0),
+ }
+ );
enemy.add_component<AudioSource>(Asset("asset/sfx/bike_gun_2.ogg")).volume = 0.1;
AI & ai_component = enemy.add_component<AI>(3000);
ai_component.path_follow_on();
+ ai_component.active = false;
BehaviorScript & enemy_script
= enemy.add_component<BehaviorScript>().set_script<EnemyScript>();
- enemy_script.active = false;
+ //enemy_script.active = false;
return enemy_counter;
}
diff --git a/game/main.cpp b/game/main.cpp
index c9ad8c1..95cb35c 100644
--- a/game/main.cpp
+++ b/game/main.cpp
@@ -17,6 +17,7 @@ int main() {
Config::get_instance() = ENGINE_CONFIG;
Engine gameloop;
+
gameloop.add_scene<MainMenuScene>();
gameloop.add_scene<ShopMenuScene>();
gameloop.add_scene<GameScene>();
diff --git a/game/player/PlayerBulletSubScene.cpp b/game/player/PlayerBulletSubScene.cpp
index 5e1c66e..82ce4a9 100644
--- a/game/player/PlayerBulletSubScene.cpp
+++ b/game/player/PlayerBulletSubScene.cpp
@@ -24,7 +24,7 @@ int PlayerBulletSubScene::create(Scene & scn, int counter) {
Rigidbody & player_bullet_body = player_bullet.add_component<Rigidbody>(Rigidbody::Data {
.gravity_scale = 0,
.body_type = Rigidbody::BodyType::KINEMATIC,
- .linear_velocity = vec2 {400, 0},
+ .linear_velocity = vec2 {450, 0},
.angular_velocity = 300,
.kinematic_collision = false,
.collision_layers = {COLL_LAY_ENEMY, COLL_LAY_ZAPPER},
diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp
index 286cdaf..8cbe8dc 100644
--- a/game/player/PlayerScript.cpp
+++ b/game/player/PlayerScript.cpp
@@ -163,7 +163,7 @@ void PlayerScript::fixed_update(crepe::duration_t dt) {
if (current_jetpack_sound > 7) {
current_jetpack_sound = 0;
}
- } else if (transform.position.y == 195) {
+ } else if (transform.position.y == 200) {
Rigidbody & rb = this->body;
if (prev_anim != 0 && rb.data.linear_velocity.x != 0) {
for (Animator & anim : animators) {
diff --git a/game/player/PlayerScript.h b/game/player/PlayerScript.h
index 6875b05..6a7dedb 100644
--- a/game/player/PlayerScript.h
+++ b/game/player/PlayerScript.h
@@ -22,8 +22,9 @@ private:
private:
int prev_anim = 0;
std::chrono::time_point<std::chrono::steady_clock> last_fired;
+ std::chrono::time_point<std::chrono::steady_clock> last_switched;
std::chrono::duration<float> shot_delay = std::chrono::duration<float>(0.5);
-
+ std::chrono::duration<float> switch_delay = std::chrono::duration<float>(0.01);
int current_jetpack_sound = 0;
float & engine_gravity = crepe::Config::get_instance().physics.gravity;
diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp
index 3aeabfe..d0142e0 100644
--- a/game/player/PlayerSubScene.cpp
+++ b/game/player/PlayerSubScene.cpp
@@ -123,7 +123,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) {
.looping = true,
}
);
- player.add_component<BoxCollider>(vec2(50, 50));
+ player.add_component<BoxCollider>(vec2(50, 35));
Asset player_head_asset {"asset/barry/defaultHead.png"};
Sprite & player_head_sprite = player.add_component<Sprite>(
player_head_asset,
@@ -160,7 +160,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) {
.looping = true,
}
);
- player.add_component<BoxCollider>(vec2(40, 60), vec2(-20, 0));
+ player.add_component<BoxCollider>(vec2(40, 50), vec2(-20, 0));
player.add_component<Rigidbody>(Rigidbody::Data {
.gravity_scale = 1.0,
.body_type = Rigidbody::BodyType::DYNAMIC,
@@ -170,6 +170,7 @@ PlayerSubScene::PlayerSubScene(Scene & scn) {
},
.collision_layer = COLL_LAY_PLAYER,
});
+
player.add_component<BehaviorScript>().set_script<PlayerScript>().active = false;
player.add_component<BehaviorScript>().set_script<CoinScript>();
player.add_component<BehaviorScript>().set_script<PlayerEndScript>().active = false;
diff --git a/game/scheduler/ObjectsScheduler.cpp b/game/scheduler/ObjectsScheduler.cpp
index 36bf901..0839fe5 100644
--- a/game/scheduler/ObjectsScheduler.cpp
+++ b/game/scheduler/ObjectsScheduler.cpp
@@ -4,6 +4,7 @@
#include "../Config.h"
#include "../Random.h"
+#include "../enemy/EnemyScript.h"
#include "../missile/SpawnEvent.h"
#include "api/Rigidbody.h"
#include "api/Transform.h"
@@ -14,15 +15,34 @@ using namespace crepe;
void ObjectsScheduler::preset_0() {
trigger_event<MissileSpawnEvent>(MissileSpawnEvent {});
trigger_event<MissileSpawnEvent>(MissileSpawnEvent {});
+ this->trigger_event<BattleStartEvent>(BattleStartEvent {
+ .num_enemies = Random::i(2, 0),
+ .battle = false,
+ });
+}
+void ObjectsScheduler::preset_1() {
+ trigger_event<MissileSpawnEvent>(MissileSpawnEvent {});
+ this->trigger_event<BattleStartEvent>(BattleStartEvent {
+ .num_enemies = Random::i(2, 1),
+ .battle = false,
+ });
+}
+void ObjectsScheduler::preset_2() {
+ trigger_event<CreateZapperEvent>(CreateZapperEvent {});
+ this->trigger_event<BattleStartEvent>(BattleStartEvent {
+ .num_enemies = Random::i(2, 1),
+ .battle = false,
+ });
}
-void ObjectsScheduler::preset_1() { trigger_event<MissileSpawnEvent>(MissileSpawnEvent {}); }
-void ObjectsScheduler::preset_2() { trigger_event<CreateZapperEvent>(CreateZapperEvent {}); }
void ObjectsScheduler::preset_3() { trigger_event<CreateZapperEvent>(CreateZapperEvent {}); }
void ObjectsScheduler::preset_4() {}
void ObjectsScheduler::boss_fight_1() {
this->get_components_by_name<Rigidbody>("camera").front().get().data.linear_velocity.x = 0;
this->get_components_by_name<Rigidbody>("player").front().get().data.linear_velocity.x = 0;
- this->trigger_event<BattleStartEvent>(BattleStartEvent {.num_enemies = 2});
+ this->trigger_event<BattleStartEvent>(BattleStartEvent {
+ .num_enemies = 5,
+ .battle = true,
+ });
RefVector<Rigidbody> rb_back_forest
= this->get_components_by_tag<Rigidbody>("forest_background");