aboutsummaryrefslogtreecommitdiff
path: root/game/coins
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2025-01-08 15:03:14 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2025-01-08 15:03:14 +0100
commit261a2cfd2bedafbc7fcf54e1b86adee206dea519 (patch)
treef099bca292e99ae54035f9a5ac7a455eec073c3e /game/coins
parentd9c67da9b8c2d8d25ef4dd2c700ddc78573d3a60 (diff)
parent0b9574bdd6c5968c07bcf165d66032b75649b5da (diff)
merge w/ master
Diffstat (limited to 'game/coins')
-rw-r--r--game/coins/CoinPool.cpp10
-rw-r--r--game/coins/CoinPoolSubScene.cpp13
-rw-r--r--game/coins/CoinPoolSubScene.h (renamed from game/coins/CoinPool.h)7
-rw-r--r--game/coins/CoinScript.cpp68
-rw-r--r--game/coins/CoinScript.h2
-rw-r--r--game/coins/CoinSubScene.cpp71
-rw-r--r--game/coins/CoinSubScene.h2
-rw-r--r--game/coins/CoinSystemScript.cpp142
-rw-r--r--game/coins/CoinSystemScript.h105
9 files changed, 254 insertions, 166 deletions
diff --git a/game/coins/CoinPool.cpp b/game/coins/CoinPool.cpp
deleted file mode 100644
index 5720c2f..0000000
--- a/game/coins/CoinPool.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include "CoinPool.h"
-#include "CoinSubScene.h"
-
-using namespace crepe;
-using namespace std;
-
-void CoinPool::create_coins(crepe::Scene & scn) {
- CoinSubScene coin;
- while(coin.create(scn) < this->MAXIMUM_AMOUNT);
-}
diff --git a/game/coins/CoinPoolSubScene.cpp b/game/coins/CoinPoolSubScene.cpp
new file mode 100644
index 0000000..f8b5b70
--- /dev/null
+++ b/game/coins/CoinPoolSubScene.cpp
@@ -0,0 +1,13 @@
+#include "CoinPoolSubScene.h"
+#include "CoinSubScene.h"
+
+using namespace crepe;
+using namespace std;
+
+void CoinPoolSubScene::create_coins(crepe::Scene & scn) {
+ int amount = 0;
+ CoinSubScene coin;
+ while (amount < this->MAXIMUM_AMOUNT) {
+ amount = coin.create(scn, amount);
+ }
+}
diff --git a/game/coins/CoinPool.h b/game/coins/CoinPoolSubScene.h
index 83058f7..07626d6 100644
--- a/game/coins/CoinPool.h
+++ b/game/coins/CoinPoolSubScene.h
@@ -1,12 +1,11 @@
#pragma once
-#include "api/Scene.h"
+#include <crepe/api/Scene.h>
-
-class CoinPool {
+class CoinPoolSubScene {
public:
void create_coins(crepe::Scene & scn);
+
private:
static constexpr int MAXIMUM_AMOUNT = 100;
};
-
diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp
index 5d4e8fe..514f4de 100644
--- a/game/coins/CoinScript.cpp
+++ b/game/coins/CoinScript.cpp
@@ -1,29 +1,71 @@
#include "CoinScript.h"
-#include "api/CircleCollider.h"
-#include "api/Sprite.h"
+
#include "manager/SaveManager.h"
+
#include "../Config.h"
-#include "../Events.h"
+#include "../hud/HudScript.h"
+
+#include <crepe/api/Animator.h>
+#include <crepe/api/AudioSource.h>
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Sprite.h>
using namespace crepe;
using namespace std;
-bool CoinScript::on_collision(const CollisionEvent & collisionData){
- if(collisionData.info.other.metadata.tag != "coin") return true;
- this->get_components_by_name<Sprite>("").front().get().active = false;
- this->get_components_by_name<CircleCollider>("").front().get().active = false;
+bool CoinScript::on_collision(const CollisionEvent & collisionData) {
+ if (collisionData.info.other.metadata.tag != "coin") return false;
+ if (!this->get_components_by_name<Sprite>(collisionData.info.other.metadata.name)
+ .front()
+ .get()
+ .active)
+ return false;
+ this->get_components_by_name<Sprite>(collisionData.info.other.metadata.name)
+ .front()
+ .get()
+ .active
+ = false;
+ this->get_components_by_name<CircleCollider>(collisionData.info.other.metadata.name)
+ .front()
+ .get()
+ .active
+ = false;
this->amount++;
- return true;
+
+ AudioSource & audio = this->get_components_by_id<AudioSource>(
+ collisionData.info.other.metadata.game_object_id
+ )
+ .front();
+ audio.play();
+
+ this->get_components_by_name<Sprite>(collisionData.info.other.metadata.name)
+ .back()
+ .get()
+ .active
+ = true;
+ this->get_components_by_name<Animator>(collisionData.info.other.metadata.name)
+ .back()
+ .get()
+ .active
+ = true;
+
+ return false;
+}
+
+void CoinScript::init() {
+ this->subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool {
+ return this->on_collision(ev);
+ });
}
-void CoinScript::init(){
- this->subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); });
- this->subscribe<EndGameEvent>([this](const EndGameEvent e)-> bool { return this->save(); });
+void CoinScript::fixed_update(crepe::duration_t dt) {
+ this->trigger_event(GetCoinEvent {
+ .amount_of_coins = this->amount,
+ });
}
-bool CoinScript::save(){
+bool CoinScript::save() {
SaveManager & savemgr = this->get_save_manager();
savemgr.set(TOTAL_COINS_RUN, this->amount);
- this->amount = 0;
return false;
}
diff --git a/game/coins/CoinScript.h b/game/coins/CoinScript.h
index e88a860..5718025 100644
--- a/game/coins/CoinScript.h
+++ b/game/coins/CoinScript.h
@@ -5,8 +5,10 @@
class CoinScript : public crepe::Script {
public:
void init() override;
+ void fixed_update(crepe::duration_t dt) override;
bool on_collision(const crepe::CollisionEvent & collisionData);
bool save();
+
private:
int amount = 0;
};
diff --git a/game/coins/CoinSubScene.cpp b/game/coins/CoinSubScene.cpp
index 3914921..d154819 100644
--- a/game/coins/CoinSubScene.cpp
+++ b/game/coins/CoinSubScene.cpp
@@ -1,41 +1,64 @@
#include "CoinSubScene.h"
-#include "api/Animator.h"
-#include "api/BehaviorScript.h"
-#include "api/CircleCollider.h"
-#include "api/Rigidbody.h"
-#include "api/Scene.h"
-#include "api/AudioSource.h"
-#include "CoinScript.h"
+
#include "../Config.h"
+#include <crepe/api/Animator.h>
+#include <crepe/api/AudioSource.h>
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Scene.h>
+
using namespace crepe;
using namespace std;
-int CoinSubScene::create(Scene & scn){
+int CoinSubScene::create(Scene & scn, int coin_counter) {
vec2 size = {20, 20};
- static int coin_counter = 0;
string unique_name = "coin_" + to_string(coin_counter++);
- GameObject coin = scn.new_object(unique_name.c_str(),"coin",vec2{650,0},0,1);
- coin.add_component<Rigidbody>(Rigidbody::Data{
+ GameObject coin = scn.new_object(unique_name.c_str(), "coin", vec2 {650, 0}, 0, 1);
+ coin.add_component<Rigidbody>(Rigidbody::Data {
.body_type = Rigidbody::BodyType::KINEMATIC,
.kinematic_collision = false,
.collision_layers = {COLL_LAY_PLAYER},
});
- coin.add_component<CircleCollider>((size.x / 2)-3).active = false;
- crepe::OptionalRef<crepe::Sprite> coin_sprite = coin.add_component<Sprite>(Asset{"asset/coin/coin1_TVOS.png"}, Sprite::Data{
- .sorting_in_layer = SORT_IN_LAY_COINS,
- .order_in_layer = 0,
- .size = size,
- });
+ coin.add_component<CircleCollider>((size.x / 2) - 3).active = false;
+ crepe::OptionalRef<crepe::Sprite> coin_sprite = coin.add_component<Sprite>(
+ Asset {"asset/coin/coin1_TVOS.png"},
+ Sprite::Data {
+ .sorting_in_layer = SORT_IN_LAY_COINS,
+ .order_in_layer = 0,
+ .size = size,
+ }
+ );
coin_sprite->active = false;
- coin.add_component<Animator>(coin_sprite, ivec2{32, 32}, uvec2{8, 1},
- Animator::Data{
- .fps = 15,
- .looping = true,
- });
- coin.add_component<AudioSource>(Asset{"asset/sfx/coin_pickup_1.ogg"});
- coin.add_component<BehaviorScript>().set_script<CoinScript>();
+ coin.add_component<Animator>(
+ coin_sprite, ivec2 {32, 32}, uvec2 {8, 1},
+ Animator::Data {
+ .fps = 15,
+ .looping = true,
+ }
+ );
+ coin.add_component<AudioSource>(Asset {"asset/sfx/coin_pickup_1.ogg"}).volume = 3;
+
+ Sprite & pick_up = coin.add_component<Sprite>(
+ Asset {"asset/coin/coinCollect1_TVOS.png"},
+ Sprite::Data {
+ .sorting_in_layer = SORT_IN_LAY_COINS,
+ .order_in_layer = 1,
+ .size = size * 2,
+ }
+ );
+ pick_up.active = false;
+ coin.add_component<Animator>(
+ pick_up, ivec2 {64, 64}, uvec2 {5, 1},
+ Animator::Data {
+ .fps = 5,
+ .looping = false,
+ }
+ )
+ .active
+ = false;
+
return coin_counter;
}
diff --git a/game/coins/CoinSubScene.h b/game/coins/CoinSubScene.h
index f85f427..7a1c60a 100644
--- a/game/coins/CoinSubScene.h
+++ b/game/coins/CoinSubScene.h
@@ -8,5 +8,5 @@ class Scene;
class CoinSubScene {
public:
- int create(crepe::Scene & scn);
+ int create(crepe::Scene & scn, int coin_counter);
};
diff --git a/game/coins/CoinSystemScript.cpp b/game/coins/CoinSystemScript.cpp
index c9c301e..f9816c9 100644
--- a/game/coins/CoinSystemScript.cpp
+++ b/game/coins/CoinSystemScript.cpp
@@ -1,25 +1,22 @@
#include "CoinSystemScript.h"
-#include "CoinPool.h"
-#include "api/CircleCollider.h"
-#include "api/Metadata.h"
-#include "api/Sprite.h"
-#include "api/Transform.h"
+
#include <random>
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Metadata.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+
using namespace crepe;
using namespace std;
-std::vector<CoinSystemScript::CoinData> CoinSystemScript::coin_locations;
-
-void CoinSystemScript::init() {
- engine.seed(rd());
-}
+void CoinSystemScript::init() { engine.seed(rd()); }
-void CoinSystemScript::add_location(const crepe::vec2& location){
+void CoinSystemScript::add_location(const crepe::vec2 & location) {
coin_locations.push_back(CoinData(location));
}
-float CoinSystemScript::preset_1(const vec2 & begin_position){
+float CoinSystemScript::preset_1(const vec2 & begin_position) {
vec2 top = {begin_position.x, begin_position.y - (this->ROW_OFFSET_1)};
vec2 bottom = {begin_position.x, begin_position.y + (this->ROW_OFFSET_1)};
@@ -30,7 +27,7 @@ float CoinSystemScript::preset_1(const vec2 & begin_position){
}
// Add locations for the bottom row
- bottom.x +=this->COLUM_OFFSET_1 * COLUM_AMOUNT_1;
+ bottom.x += this->COLUM_OFFSET_1 * COLUM_AMOUNT_1;
for (int i = 0; i < COLUM_AMOUNT_1; ++i) {
add_location(bottom);
bottom.x += this->COLUM_OFFSET_1;
@@ -44,22 +41,24 @@ float CoinSystemScript::preset_1(const vec2 & begin_position){
}
// Add locations for the next set of the bottom row
- bottom.x +=this->COLUM_OFFSET_1 * COLUM_AMOUNT_1;
+ bottom.x += this->COLUM_OFFSET_1 * COLUM_AMOUNT_1;
for (int i = 0; i < COLUM_AMOUNT_1; ++i) {
add_location(bottom);
bottom.x += this->COLUM_OFFSET_1;
}
- return bottom.x-begin_position.x;
+ return bottom.x - begin_position.x;
}
-float CoinSystemScript::preset_2(const vec2 & begin_position){
- vec2 top = {begin_position.x+this->COLUM_OFFSET_2, begin_position.y - this->ROW_OFFSET_2};
+float CoinSystemScript::preset_2(const vec2 & begin_position) {
+ vec2 top
+ = {begin_position.x + this->COLUM_OFFSET_2, begin_position.y - this->ROW_OFFSET_2};
vec2 middle = begin_position;
- vec2 bottom = {begin_position.x+this->COLUM_OFFSET_2, begin_position.y + this->ROW_OFFSET_2};
+ vec2 bottom
+ = {begin_position.x + this->COLUM_OFFSET_2, begin_position.y + this->ROW_OFFSET_2};
// Add locations for the next set of the bottom row
- for (int i = 0; i < COLUM_AMOUNT_2-2; ++i) {
+ for (int i = 0; i < COLUM_AMOUNT_2 - 2; ++i) {
add_location(bottom);
bottom.x += this->COLUM_OFFSET_2;
}
@@ -71,18 +70,17 @@ float CoinSystemScript::preset_2(const vec2 & begin_position){
}
// Add locations for the next set of the top row
- for (int i = 0; i < COLUM_AMOUNT_2-2; ++i) {
+ for (int i = 0; i < COLUM_AMOUNT_2 - 2; ++i) {
add_location(top);
top.x += this->COLUM_OFFSET_2;
}
- return middle.x-begin_position.x;
+ return middle.x - begin_position.x;
}
-float CoinSystemScript::preset_3(const vec2 & begin_position){
+float CoinSystemScript::preset_3(const vec2 & begin_position) {
vec2 location = {begin_position.x, begin_position.y - (this->ROW_OFFSET_3)};
-
// Add locations for the top row
for (int i = 0; i < COLUM_AMOUNT_3; ++i) {
add_location(location);
@@ -90,7 +88,7 @@ float CoinSystemScript::preset_3(const vec2 & begin_position){
}
// Add locations for the bottom row
- location.y +=this->ROW_OFFSET_3;
+ location.y += this->ROW_OFFSET_3;
location.x += this->COLUM_OFFSET_3;
for (int i = 0; i < COLUM_AMOUNT_3; ++i) {
add_location(location);
@@ -98,20 +96,19 @@ float CoinSystemScript::preset_3(const vec2 & begin_position){
}
// Add locations for the next set of the top row
- location.y +=this->ROW_OFFSET_3;
+ location.y += this->ROW_OFFSET_3;
location.x += this->COLUM_OFFSET_3;
for (int i = 0; i < COLUM_AMOUNT_3; ++i) {
add_location(location);
location.x += this->COLUM_OFFSET_3;
}
- return location.x-begin_position.x;
+ return location.x - begin_position.x;
}
-float CoinSystemScript::preset_4(const vec2 & begin_position){
+float CoinSystemScript::preset_4(const vec2 & begin_position) {
vec2 location = {begin_position.x, begin_position.y + (this->ROW_OFFSET_4)};
-
// Add locations for the top row
for (int i = 0; i < COLUM_AMOUNT_4; ++i) {
add_location(location);
@@ -119,7 +116,7 @@ float CoinSystemScript::preset_4(const vec2 & begin_position){
}
// Add locations for the bottom row
- location.y -=this->ROW_OFFSET_4;
+ location.y -= this->ROW_OFFSET_4;
location.x += this->COLUM_OFFSET_4;
for (int i = 0; i < COLUM_AMOUNT_4; ++i) {
add_location(location);
@@ -127,32 +124,29 @@ float CoinSystemScript::preset_4(const vec2 & begin_position){
}
// Add locations for the next set of the top row
- location.y -=this->ROW_OFFSET_4;
+ location.y -= this->ROW_OFFSET_4;
location.x += this->COLUM_OFFSET_4;
for (int i = 0; i < COLUM_AMOUNT_4; ++i) {
add_location(location);
location.x += this->COLUM_OFFSET_4;
}
- return location.x-begin_position.x;
+ return location.x - begin_position.x;
}
-float CoinSystemScript::preset_5(const vec2 & begin_position){
- vec2 location = {begin_position.x, begin_position.y-ROW_OFFSET_5/2};
- for (int i = 0; i < COLUM_AMOUNT_5; ++i){
+float CoinSystemScript::preset_5(const vec2 & begin_position) {
+ vec2 location = {begin_position.x, begin_position.y - ROW_OFFSET_5 / 2};
+ for (int i = 0; i < COLUM_AMOUNT_5; ++i) {
add_location(location);
location.x += this->COLUM_OFFSET_5;
}
- return location.x-begin_position.x;
+ return location.x - begin_position.x;
}
-
-
-void CoinSystemScript::frame_update(crepe::duration_t dt)
-{
+void CoinSystemScript::frame_update(crepe::duration_t dt) {
this->despawn_coins();
this->generate_locations();
- this->spawn_coins();
+ this->spawn_coins();
}
void CoinSystemScript::despawn_coins() {
@@ -162,22 +156,26 @@ void CoinSystemScript::despawn_coins() {
// Retrieve all active coin sprites tagged as "coin"
RefVector<Sprite> coin_sprites = this->get_components_by_tag<Sprite>("coin");
- for (Sprite& coin_sprite : coin_sprites) {
+ for (Sprite & coin_sprite : coin_sprites) {
if (!coin_sprite.active) continue; // Skip inactive sprites
// Retrieve the corresponding Transform, Metadata, and CircleCollider components
- Transform& coin_transform = this->get_components_by_id<Transform>(coin_sprite.game_object_id).front().get();
- Metadata& coin_metadata = this->get_components_by_id<Metadata>(coin_sprite.game_object_id).front().get();
- CircleCollider& coin_collider = this->get_components_by_id<CircleCollider>(coin_sprite.game_object_id).front().get();
+ Transform & coin_transform
+ = this->get_components_by_id<Transform>(coin_sprite.game_object_id).front().get();
+ Metadata & coin_metadata
+ = this->get_components_by_id<Metadata>(coin_sprite.game_object_id).front().get();
+ CircleCollider & coin_collider
+ = this->get_components_by_id<CircleCollider>(coin_sprite.game_object_id)
+ .front()
+ .get();
// Check if the coin is out of bounds based on DESPAWN_DISTANCE
if (coin_transform.position.x < position - this->DESPAWN_DISTANCE) {
// Find the coin in the coin_locations vector using its name
auto it = std::find_if(
- coin_locations.begin(),
- coin_locations.end(),
- [&coin_metadata](const CoinData& data) {
- return data.name == coin_metadata.name;
+ coin_locations.begin(), coin_locations.end(),
+ [&coin_metadata](const CoinData & data) {
+ return data.name == coin_metadata.name;
}
);
@@ -191,31 +189,46 @@ void CoinSystemScript::despawn_coins() {
}
}
-void CoinSystemScript::spawn_coins(){
+void CoinSystemScript::spawn_coins() {
// Get the current x-position of the CoinSystem's Transform component
float position = this->get_component<Transform>().position.x;
// Iterate through the list of coin locations
- for (auto& coin : coin_locations) {
+ for (auto & coin : coin_locations) {
// Skip this coin if it is already active
- if (coin.active)continue;
+ if (coin.active) continue;
// Skip this coin if it is not within the defined spawn area
- if (coin.start_location.x < this->SPAWN_DISTANCE + position || coin.start_location.x > this->SPAWN_AREA + this->SPAWN_DISTANCE + position) continue;
-
+ if (coin.start_location.x < this->SPAWN_DISTANCE + position
+ || coin.start_location.x > this->SPAWN_AREA + this->SPAWN_DISTANCE + position)
+ continue;
+
// Retrieve all sprites tagged as "coin"
RefVector<Sprite> coin_sprites = this->get_components_by_tag<Sprite>("coin");
// Check for an available (inactive) coin sprite
- for (Sprite& coin_sprite : coin_sprites) {
+ for (Sprite & coin_sprite : coin_sprites) {
// Skip this sprite if it is already active
if (coin_sprite.active) continue;
+ if (coin_sprite.data.order_in_layer == 1) {
+ coin_sprite.active = false;
+ continue;
+ }
// Found an available (inactive) coin sprite
// Retrieve its associated components
- Transform & coin_transform = this->get_components_by_id<Transform>(coin_sprite.game_object_id).front().get();
- Metadata & coin_metadata = this->get_components_by_id<Metadata>(coin_sprite.game_object_id).front().get();
- CircleCollider & coin_collider = this->get_components_by_id<CircleCollider>(coin_sprite.game_object_id).front().get();
-
+ Transform & coin_transform
+ = this->get_components_by_id<Transform>(coin_sprite.game_object_id)
+ .front()
+ .get();
+ Metadata & coin_metadata
+ = this->get_components_by_id<Metadata>(coin_sprite.game_object_id)
+ .front()
+ .get();
+ CircleCollider & coin_collider
+ = this->get_components_by_id<CircleCollider>(coin_sprite.game_object_id)
+ .front()
+ .get();
+
// Assign data and set active
coin.name = coin_metadata.name;
coin.active = true;
@@ -223,26 +236,23 @@ void CoinSystemScript::spawn_coins(){
coin_collider.active = true;
coin_transform.position = coin.start_location;
- // Break out of the inner loop since we've assigned this coin to an available sprite
+ // Break out of the inner loop since we've assigned this coin to an available sprite
break;
}
}
}
-void CoinSystemScript::generate_locations(){
+void CoinSystemScript::generate_locations() {
float position = this->get_component<Transform>().position.x;
- if(position + SPAWN_DISTANCE + SYSTEM_POSITION_OFFSET < this->system_position) return;
+ if (position + SPAWN_DISTANCE + SYSTEM_POSITION_OFFSET < this->system_position) return;
std::discrete_distribution<int> dist(weights.begin(), weights.end());
int selected_index = dist(engine);
std::uniform_real_distribution<float> space_dist(SPAWN_SPACING_MIN, SPAWN_SPACING_MAX);
float spacing = space_dist(engine);
-
+
// Call the corresponding function and return the new x position
- this->system_position += functions[selected_index]({this->system_position,0});
+ this->system_position += functions[selected_index]({this->system_position, 0});
this->system_position += spacing;
}
-
-
-
diff --git a/game/coins/CoinSystemScript.h b/game/coins/CoinSystemScript.h
index f558f08..5c94273 100644
--- a/game/coins/CoinSystemScript.h
+++ b/game/coins/CoinSystemScript.h
@@ -1,27 +1,33 @@
#pragma once
-#include "types.h"
-#include <string>
-#include "api/CircleCollider.h"
-#include "api/Script.h"
-#include "api/Sprite.h"
-#include "api/Transform.h"
#include <random>
+#include <string>
+
+#include <crepe/api/CircleCollider.h>
+#include <crepe/api/Script.h>
+#include <crepe/api/Sprite.h>
+#include <crepe/api/Transform.h>
+#include <crepe/types.h>
class CoinSystemScript : public crepe::Script {
private:
- struct CoinData{
- crepe::vec2 start_location = {0,0};
+ struct CoinData {
+ crepe::vec2 start_location = {0, 0};
std::string name = "";
bool active = false;
- CoinData(crepe::vec2 start_location) : start_location(start_location),name(""), active(false) {}
+ CoinData(crepe::vec2 start_location)
+ : start_location(start_location),
+ name(""),
+ active(false) {}
};
+
public:
CoinSystemScript() {};
void init() override;
void frame_update(crepe::duration_t dt) override;
+
private:
- void add_location(const crepe::vec2& location);
+ void add_location(const crepe::vec2 & location);
void despawn_coins();
void spawn_coins();
void generate_locations();
@@ -30,68 +36,71 @@ private:
float preset_3(const crepe::vec2 & begin_position);
float preset_4(const crepe::vec2 & begin_position);
float preset_5(const crepe::vec2 & begin_position);
+
private:
- std::vector<std::function<float(const crepe::vec2&)>> functions = {
- [this](const crepe::vec2& pos) { return preset_1(pos); },
- [this](const crepe::vec2& pos) { return preset_2(pos); },
- [this](const crepe::vec2& pos) { return preset_3(pos); },
- [this](const crepe::vec2& pos) { return preset_4(pos); },
- [this](const crepe::vec2& pos) { return preset_5(pos); }
- };
- std::vector<int> weights = {20, 20,20,20, 20};
+ std::vector<std::function<float(const crepe::vec2 &)>> functions
+ = {[this](const crepe::vec2 & pos) { return preset_1(pos); },
+ [this](const crepe::vec2 & pos) { return preset_2(pos); },
+ [this](const crepe::vec2 & pos) { return preset_3(pos); },
+ [this](const crepe::vec2 & pos) { return preset_4(pos); },
+ [this](const crepe::vec2 & pos) { return preset_5(pos); }};
+ std::vector<int> weights = {20, 20, 20, 20, 20};
std::random_device rd;
std::default_random_engine engine;
- float system_position = 1200;
+ float system_position = 1400;
static constexpr float SYSTEM_POSITION_OFFSET = 200;
+
private:
static constexpr float SPAWN_SPACING_MIN = 400;
static constexpr float SPAWN_SPACING_MAX = 1000;
static constexpr float SPAWN_DISTANCE = 600;
static constexpr float DESPAWN_DISTANCE = 600;
static constexpr float SPAWN_AREA = 50;
- static std::vector<CoinData> coin_locations;
+ std::vector<CoinData> coin_locations;
+
private:
-// preset one settings
-// ***** *****
-//
-//
-//
-// ***** *****
+ // preset one settings
+ // ***** *****
+ //
+ //
+ //
+ // ***** *****
static constexpr float ROW_OFFSET_1 = 100;
static constexpr float COLUM_OFFSET_1 = 25;
static constexpr int COLUM_AMOUNT_1 = 5;
+
private:
-// preset two settings
-//
-// ********
-// **********
-// ********
-//
+ // preset two settings
+ //
+ // ********
+ // **********
+ // ********
+ //
static constexpr float ROW_OFFSET_2 = 25;
static constexpr float COLUM_OFFSET_2 = 25;
static constexpr int COLUM_AMOUNT_2 = 10;
-// preset three settings
-// ***
-//
-// ***
-//
-// ***
+ // preset three settings
+ // ***
+ //
+ // ***
+ //
+ // ***
static constexpr float ROW_OFFSET_3 = 100;
static constexpr float COLUM_OFFSET_3 = 25;
static constexpr int COLUM_AMOUNT_3 = 3;
-// preset four settings
-// ***
-//
-// ***
-//
-// ***
+ // preset four settings
+ // ***
+ //
+ // ***
+ //
+ // ***
static constexpr float ROW_OFFSET_4 = 100;
static constexpr float COLUM_OFFSET_4 = 25;
static constexpr int COLUM_AMOUNT_4 = 3;
-// preset five settings
-//
-// ***
-//
+ // preset five settings
+ //
+ // ***
+ //
static constexpr float ROW_OFFSET_5 = 25;
static constexpr float COLUM_OFFSET_5 = 25;
static constexpr int COLUM_AMOUNT_5 = 3;