aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2025-01-03 21:02:48 +0100
committerJAROWMR <jarorutjes07@gmail.com>2025-01-03 21:02:48 +0100
commit5ae4e3f0e3ff1d111eaea54b7b0a0788203d9d72 (patch)
treeabd7e7965eaff19c76daecb8a3f4514106562a09
parent209957a36c19968292032ead5974a695b22ffceb (diff)
bug fix
-rw-r--r--game/coins/CoinSubScene.cpp2
-rw-r--r--game/mainmenu/BannerSubScene.cpp5
-rw-r--r--game/mainmenu/ButtonSubScene.cpp30
-rw-r--r--game/mainmenu/ButtonSubScene.h11
-rw-r--r--game/mainmenu/ITransitionScript.cpp5
-rw-r--r--game/mainmenu/MainMenuConfig.h12
-rw-r--r--game/mainmenu/MainMenuScene.cpp52
7 files changed, 95 insertions, 22 deletions
diff --git a/game/coins/CoinSubScene.cpp b/game/coins/CoinSubScene.cpp
index d30f5a4..58f74ef 100644
--- a/game/coins/CoinSubScene.cpp
+++ b/game/coins/CoinSubScene.cpp
@@ -8,6 +8,7 @@
#include <concepts>
#include <iostream>
#include "CoinScript.h"
+#include "../Config.h"
using namespace crepe;
using namespace std;
@@ -23,6 +24,7 @@ int CoinSubScene::create(Scene & scn){
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).active = false;
crepe::OptionalRef<crepe::Sprite> coin_sprite = coin.add_component<Sprite>(Asset{"asset/coin/coin1_TVOS.png"}, Sprite::Data{
diff --git a/game/mainmenu/BannerSubScene.cpp b/game/mainmenu/BannerSubScene.cpp
index ed093aa..ba4c126 100644
--- a/game/mainmenu/BannerSubScene.cpp
+++ b/game/mainmenu/BannerSubScene.cpp
@@ -33,6 +33,9 @@ void BannerSubScene::create(Scene & scn,const Data & data){
});
crepe::vec2 size = {data.banner_title_width,(data.banner_title_width/data.banner_title.size())*2};
- menu_banner.add_component<Text>( size, MainMenuConfig::FONT, Text::Data{.text_color = Color::WHITE,}, data.banner_title_offset + MainMenuConfig::FONTOFFSET, data.banner_title);
+ menu_banner.add_component<Text>( size, MainMenuConfig::FONT, Text::Data{
+ .world_space = true,
+ .text_color = Color::WHITE,
+ }, data.banner_title_offset + MainMenuConfig::FONTOFFSET, data.banner_title);
}
diff --git a/game/mainmenu/ButtonSubScene.cpp b/game/mainmenu/ButtonSubScene.cpp
index 8890ccc..53ac8d0 100644
--- a/game/mainmenu/ButtonSubScene.cpp
+++ b/game/mainmenu/ButtonSubScene.cpp
@@ -16,7 +16,7 @@ using namespace crepe;
using namespace std;
void ButtonSubScene::create(Scene & scn,const Data & data){
- GameObject button_object = scn.new_object("button","",data.position,0,data.scale);
+ GameObject button_object = scn.new_object("button",data.tag,data.position,0,data.scale);
this->set_button_overlay(button_object,data);
this->btn_text(button_object,data);
this->set_script(button_object,data);
@@ -27,6 +27,7 @@ void ButtonSubScene::btn_text(crepe::GameObject & button_object,const Data & dat
crepe::vec2 size = {data.text_width,(data.text_width/data.text.size())*2};
button_object.add_component<Text>(size, MainMenuConfig::FONT,Text::Data{
+ .world_space = data.worldspace,
.text_color = Color::WHITE,
}, data.text_offset+MainMenuConfig::FONTOFFSET, data.text);
}
@@ -55,6 +56,15 @@ void ButtonSubScene::set_icon(crepe::GameObject & button_object,const Data & dat
.sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+3,
.size = MainMenuConfig::ICON_SIZE,
.position_offset = data.icon_offset,
+ .world_space = data.worldspace,
+ });
+ break;
+ case IconSelect::COINS:
+ button_object.add_component<Sprite>(Asset("asset/ui/buttonCoinsSmall.png"),Sprite::Data{
+ .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+3,
+ .size = MainMenuConfig::ICON_SIZE,
+ .position_offset = data.icon_offset,
+ .world_space = data.worldspace,
});
break;
case IconSelect::NONE:
@@ -65,47 +75,53 @@ void ButtonSubScene::set_icon(crepe::GameObject & button_object,const Data & dat
void ButtonSubScene::set_button_overlay(crepe::GameObject & button_object,const Data & data){
switch (data.button_type) {
case ButtonSelect::LARGE:
- this->large_btn_overlay(button_object);
+ this->large_btn_overlay(button_object,data);
break;
case ButtonSelect::SMALL:
- this->small_btn_overlay(button_object);
+ this->small_btn_overlay(button_object,data);
break;
}
}
-void ButtonSubScene::large_btn_overlay(crepe::GameObject & button_object){
+void ButtonSubScene::large_btn_overlay(crepe::GameObject & button_object,const Data & data){
button_object.add_component<Sprite>(Asset("asset/ui/buttonBacking.png"),Sprite::Data{
.sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+1,
.size = MainMenuConfig::LARGE_OVERLAY_SIZE,
+ .world_space = data.worldspace,
});
button_object.add_component<Button>(MainMenuConfig::LARGE_OVERLAY_SIZE,Button::Data{});
- this->btn_color_side(button_object,SIDE_PANEL_OFFSET);
+ if(!data.color_side) return;
+ this->btn_color_side(button_object,SIDE_PANEL_OFFSET,data);
}
-void ButtonSubScene::small_btn_overlay(crepe::GameObject & button_object){
+void ButtonSubScene::small_btn_overlay(crepe::GameObject & button_object,const Data & data){
button_object.add_component<Sprite>(Asset("asset/ui/backbuttonright.png"),Sprite::Data{
.sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+1,
.size = MainMenuConfig::SMALL_OVERLAY_SIZE_RIGHT,
.position_offset = {20,0},
+ .world_space = data.worldspace,
});
button_object.add_component<Sprite>(Asset("asset/ui/backbuttonleft.png"),Sprite::Data{
.sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+1,
.size = MainMenuConfig::SMALL_OVERLAY_SIZE_LEFT,
.position_offset = {-80,0},
+ .world_space = data.worldspace,
});
button_object.add_component<Button>(vec2{MainMenuConfig::SMALL_OVERLAY_SIZE_LEFT.x+MainMenuConfig::SMALL_OVERLAY_SIZE_RIGHT.x,MainMenuConfig::SMALL_OVERLAY_SIZE_LEFT.y},Button::Data{});
}
-void ButtonSubScene::btn_color_side(crepe::GameObject & button_object,const vec2 & offset){
+void ButtonSubScene::btn_color_side(crepe::GameObject & button_object,const vec2 & offset,const Data & data){
button_object.add_component<Sprite>(Asset("asset/ui/buttonSmallBlue.png"),Sprite::Data{
.sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+2,
.size = MainMenuConfig::SIDE_PANEL_SIZE,
.position_offset = offset,
+ .world_space = data.worldspace,
});
button_object.add_component<Sprite>(Asset("asset/ui/buttonSmallBlue.png"),Sprite::Data{
.flip = {true,false},
.sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+2,
.size = MainMenuConfig::SIDE_PANEL_SIZE,
.position_offset = {-offset.x,offset.y},
+ .world_space = data.worldspace,
});
}
diff --git a/game/mainmenu/ButtonSubScene.h b/game/mainmenu/ButtonSubScene.h
index 6f183ed..843dbcd 100644
--- a/game/mainmenu/ButtonSubScene.h
+++ b/game/mainmenu/ButtonSubScene.h
@@ -1,6 +1,7 @@
#pragma once
#include <crepe/api/GameObject.h>
+#include <string>
#include "MainMenuConfig.h"
namespace crepe {
@@ -19,6 +20,7 @@ public:
//icon enum
enum class IconSelect {
SHOP,
+ COINS,
NONE,
};
//icon enum
@@ -37,13 +39,16 @@ public:
const ScriptSelect script_type = ScriptSelect::NONE;
const ButtonSelect button_type = ButtonSelect::LARGE;
const float scale = 1;
+ const bool worldspace = true;
+ const bool color_side = true;
+ const std::string & tag = "";
};
public:
void create(crepe::Scene & scn,const Data & data);
private:
- void large_btn_overlay(crepe::GameObject & button_object);
- void small_btn_overlay(crepe::GameObject & button_object);
- void btn_color_side(crepe::GameObject & button_object,const crepe::vec2 & offset);
+ void large_btn_overlay(crepe::GameObject & button_object,const Data & data);
+ void small_btn_overlay(crepe::GameObject & button_object,const Data & data);
+ void btn_color_side(crepe::GameObject & button_object,const crepe::vec2 & offset,const Data & data);
void btn_text(crepe::GameObject & button_object,const Data & data);
void set_script(crepe::GameObject & button_object,const Data & data);
void set_icon(crepe::GameObject & button_object,const Data & data);
diff --git a/game/mainmenu/ITransitionScript.cpp b/game/mainmenu/ITransitionScript.cpp
index 433f9f7..e923073 100644
--- a/game/mainmenu/ITransitionScript.cpp
+++ b/game/mainmenu/ITransitionScript.cpp
@@ -4,6 +4,7 @@
#include "iostream"
#include <crepe/api/Camera.h>
#include "MainMenuConfig.h"
+#include "types.h"
using namespace crepe;
using namespace std;
@@ -13,6 +14,10 @@ void ITransitionScript::frame_update(crepe::duration_t delta_time){
{
// cout << "transition:" << velocity << std::endl;
Transform & cam = this->get_components_by_name<Transform>(MainMenuConfig::CAMERA_NAME).front();
+ RefVector<Transform> info_tf = this->get_components_by_tag<Transform>(MainMenuConfig::MENU_INFO_TAG);
+ for (Transform & tf : info_tf) {
+ tf.position.y -= MainMenuConfig::VELOCITY_INFO_UP * delta_time.count();
+ }
if(velocity < MainMenuConfig::VELOCITY_MAX && cam.position.x < MainMenuConfig::SLOW_DOWN) velocity += MainMenuConfig::VELOCITY_STEP * delta_time.count();
else if(velocity > 20) velocity -= MainMenuConfig::VELOCITY_STEP * delta_time.count();
if(cam.position.x < MainMenuConfig::END) cam.position.x += (velocity * delta_time.count());
diff --git a/game/mainmenu/MainMenuConfig.h b/game/mainmenu/MainMenuConfig.h
index 9dbb838..99d29e8 100644
--- a/game/mainmenu/MainMenuConfig.h
+++ b/game/mainmenu/MainMenuConfig.h
@@ -9,9 +9,14 @@ struct MainMenuConfig {
static constexpr const char* CAMERA_NAME = "camera";
//main menu config
static constexpr float STARTMAP_OFFSET = 50;
- static constexpr crepe::vec2 MENU_OFFSET = {-400,-200};
+ static constexpr crepe::vec2 MENU_OFFSET = {0,0};
static constexpr float MENU_BUTTON_SPACING = 10;
- static constexpr crepe::vec2 MENU_OFFSET_BACKGROUND = {0,200};
+ static constexpr const char* MENU_BUTTON_NAME = "menu_button_background";
+ static constexpr crepe::vec2 MENU_OFFSET_BUTTON = {-400,-200};
+ static constexpr crepe::vec2 MENU_OFFSET_BUTTON_BACKGROUND = {-400,0};
+ static constexpr const char* MENU_INFO_TAG = "menu_info";
+ static constexpr crepe::vec2 MENU_OFFSET_INFO = {350,-365};
+ static constexpr crepe::vec2 MENU_OFFSET_INFO_BACKGROUND = {350,-365}; //375
//Scene names
static constexpr const char* START_SCENE = "scene1";
static constexpr const char* PREVIEW_SCENE = "scene1";
@@ -22,6 +27,7 @@ struct MainMenuConfig {
static constexpr float END = 300;
static constexpr float VELOCITY_MAX = 200;
static constexpr float VELOCITY_STEP = 200;
+ static constexpr float VELOCITY_INFO_UP = 30;
//button config
static constexpr const char* FONT = "Jetpackia";
static constexpr crepe::vec2 FONTOFFSET = {0,0};
@@ -30,5 +36,7 @@ struct MainMenuConfig {
static constexpr crepe::vec2 SMALL_OVERLAY_SIZE_LEFT = {50,100};
static constexpr crepe::vec2 SIDE_PANEL_SIZE = {50,150};
static constexpr crepe::vec2 ICON_SIZE = {50,50};
+ //total coins (move to main config)
+ static constexpr const char* TOTAL_COINS = "total_coins";
};
diff --git a/game/mainmenu/MainMenuScene.cpp b/game/mainmenu/MainMenuScene.cpp
index 1d2873e..e68696b 100644
--- a/game/mainmenu/MainMenuScene.cpp
+++ b/game/mainmenu/MainMenuScene.cpp
@@ -8,52 +8,86 @@
#include "MainMenuConfig.h"
#include "api/GameObject.h"
#include "api/Sprite.h"
+#include "manager/SaveManager.h"
using namespace crepe;
using namespace std;
void MainMenuScene::load_scene(){
+ ButtonSubScene button;
+
GameObject camera_object = this->new_object(MainMenuConfig::CAMERA_NAME);
camera_object.add_component<Camera>(ivec2(990, 720), vec2(1100, 800),
Camera::Data{
.bg_color = Color::RED,
});
+ camera_object.add_component<BehaviorScript>().set_script<TransitionStartScript>();
- GameObject menu = this->new_object("menu_background","",MainMenuConfig::MENU_OFFSET + MainMenuConfig::MENU_OFFSET_BACKGROUND);
- menu.add_component<Sprite>(
+
+ //Button menu
+ GameObject menu_button = this->new_object(MainMenuConfig::MENU_BUTTON_NAME,MainMenuConfig::MENU_BUTTON_NAME,MainMenuConfig::MENU_OFFSET);
+ menu_button.add_component<Sprite>(
Asset("asset/ui/background.png"),
Sprite::Data{
.sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+0,
.size = {300,860},
+ .position_offset = MainMenuConfig::MENU_OFFSET_BUTTON_BACKGROUND,
});
- menu.add_component<BehaviorScript>().set_script<TransitionStartScript>();
- ButtonSubScene button;
- vec2 pos = MainMenuConfig::MENU_OFFSET;
+ vec2 pos_btn = MainMenuConfig::MENU_OFFSET_BUTTON;
//Preview btn
button.create(*this,ButtonSubScene::Data{
.text = "PREVIEW",
.text_width = 200,
- .position = pos,
+ .position = pos_btn,
.script_type = ButtonSubScene::ScriptSelect::PREVIEW,
});
- pos.y += MainMenuConfig::MENU_BUTTON_SPACING + MainMenuConfig::LARGE_OVERLAY_SIZE.y;
+ //Shop btn
+ pos_btn.y += MainMenuConfig::MENU_BUTTON_SPACING + MainMenuConfig::LARGE_OVERLAY_SIZE.y;
button.create(*this,ButtonSubScene::Data{
.text = "SHOP",
.text_offset = {-20,0},
.text_width = 115,
.icon_offset = {60,0},
.icon_type = ButtonSubScene::IconSelect::SHOP,
- .position = pos,
+ .position = pos_btn,
.script_type = ButtonSubScene::ScriptSelect::SHOP,
});
-
//Start of map
StartSubScene start;
start.create(*this, MainMenuConfig::STARTMAP_OFFSET);
+
+ //INFO menu
+ GameObject menu_info = this->new_object("MENU_INFO_BACKGROUND",MainMenuConfig::MENU_INFO_TAG,MainMenuConfig::MENU_OFFSET);
+ menu_info.add_component<Sprite>(
+ Asset("asset/ui/itemsButtonBlankDark.png"),
+ Sprite::Data{
+ .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+0,
+ .size = {250,80},
+ .position_offset = MainMenuConfig::MENU_OFFSET_INFO,
+ .world_space = false,
+ });
+ SaveManager & savemgr = this->get_save_manager();
+ std::string number = std::to_string(savemgr.get<int>(MainMenuConfig::TOTAL_COINS,123).get());
+ float amount_number = static_cast<float>(number.size());
+ // savemgr.set(COIN_GAME_AMOUNT, amount);
+ button.create(*this,ButtonSubScene::Data{
+ .text = number,
+ .text_offset = {-10-(amount_number-1)*10,0},
+ .text_width = amount_number*20,
+ .icon_offset = {60,0},
+ .icon_type = ButtonSubScene::IconSelect::COINS,
+ .position = MainMenuConfig::MENU_OFFSET_INFO,
+ .script_type = ButtonSubScene::ScriptSelect::SHOP,
+ .scale = 0.6,
+ .worldspace = false,
+ .color_side = false,
+ .tag = MainMenuConfig::MENU_INFO_TAG,
+ });
+
}
string MainMenuScene::get_name() const { return "mainmenu"; }