diff options
| -rw-r--r-- | game/Config.h | 7 | ||||
| -rw-r--r-- | game/coins/CoinSubScene.cpp | 6 | ||||
| -rw-r--r-- | game/hud/HudConfig.h | 7 | ||||
| -rw-r--r-- | game/hud/HudScript.cpp | 13 | ||||
| -rw-r--r-- | game/hud/HudSubScene.cpp | 12 | 
5 files changed, 34 insertions, 11 deletions
diff --git a/game/Config.h b/game/Config.h index 81dd7ea..c09a965 100644 --- a/game/Config.h +++ b/game/Config.h @@ -5,6 +5,7 @@ static constexpr int SORT_IN_LAY_BACK_BACKGROUND = 3; // For all scenes  static constexpr int SORT_IN_LAY_BACKGROUND = 4; // For all scenes  static constexpr int SORT_IN_LAY_FORE_BACKGROUND = 5; // For all scenes  static constexpr int SORT_IN_LAY_PARTICLES_BACKGROUND = 6; // For all scenes +static constexpr int SORT_IN_LAY_COINS = 7; // Only for GameScene  static constexpr int SORT_IN_LAY_OBSTACLES = 8; // Only for GameScene  static constexpr int SORT_IN_LAY_PLAYER = 10; // Only for GameScene  static constexpr int SORT_IN_LAY_PARTICLES_FOREGROUND = 15; // Only for GameScene @@ -22,14 +23,12 @@ static constexpr int GAME_HEIGHT = 800; // In game units  static constexpr int VIEWPORT_X = 1100; // In game units  // 'GAME_HEIGHT' (below) should be replaced by '500' when game development is finished -static constexpr int VIEWPORT_Y = GAME_HEIGHT; // In game units +static constexpr int VIEWPORT_Y = 500; // In game units  // Font settings  static constexpr const char* FONT = "Jetpackia";  static constexpr crepe::vec2 FONTOFFSET = {0,0}; -// Save data -  // Amount of coins in game   static constexpr const char* TOTAL_COINS_GAME = "total_coins_game"; @@ -40,7 +39,7 @@ static constexpr const char* TOTAL_COINS_RUN = "total_coins_run";  static constexpr const char* DISTANCE_GAME = "distance_game";  static constexpr const char* DISTANCE_RUN = "distance_run"; -// Global tags and names +// Player config  static constexpr const char* PLAYER_NAME = "player";  static constexpr int PLAYER_SPEED = 7500; // In game units  static constexpr int PLAYER_GRAVITY_SCALE = 60; // In game units diff --git a/game/coins/CoinSubScene.cpp b/game/coins/CoinSubScene.cpp index 58f74ef..604af78 100644 --- a/game/coins/CoinSubScene.cpp +++ b/game/coins/CoinSubScene.cpp @@ -26,10 +26,10 @@ int CoinSubScene::create(Scene & scn){  		.kinematic_collision = false,  		.collision_layers = {COLL_LAY_PLAYER},  	}); -	coin.add_component<CircleCollider>(size.x / 2).active = false; +	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 = 100, -																	 .order_in_layer = 100, +																   .sorting_in_layer = SORT_IN_LAY_COINS, +																	 .order_in_layer = 0,  																   .size = size,  															   });  	coin_sprite->active = false; diff --git a/game/hud/HudConfig.h b/game/hud/HudConfig.h index 5972f0a..e3497fb 100644 --- a/game/hud/HudConfig.h +++ b/game/hud/HudConfig.h @@ -5,6 +5,7 @@ static constexpr crepe::vec2 TOP_LEFT = {-530,-230};  static constexpr const char* HUD_DISTANCE = "hud_distance";  static constexpr const char* HUD_BEST = "hud_best";	  static constexpr const char* HUD_COINS = "hud_coins";	 +static constexpr const char* HUD_FPS = "hud_fps";	  // Distance  static constexpr const char* DISTANCE_PLACEHOLDER = "0000m"; @@ -24,4 +25,10 @@ static constexpr const char* COINS = "0000";  static constexpr int COINS_LENGTH = 4;  static constexpr float COINS_CHAR_WIDTH = 10;  static constexpr crepe::vec2 COINS_OFFSET = {0,50}; + +// FPS +static constexpr const char* FPS = "00"; +static constexpr int FPS_LENGTH = 2; +static constexpr float FPS_CHAR_WIDTH = 10; +static constexpr crepe::vec2 FPS_OFFSET = {1030,0};  	
\ No newline at end of file diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index deeea14..71c84a1 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -21,8 +21,6 @@ void HudScript::init() {  void HudScript::frame_update(crepe::duration_t dt) { -	// string number = std::to_string(savemgr->get<int>(DISTANCE_RUN,0).get()); -  	// Distance  	Text & txt_dt = this->get_components_by_name<Text>(HUD_DISTANCE).front();  	Transform & tf = this->get_components_by_name<Transform>(PLAYER_NAME).front(); @@ -37,4 +35,15 @@ void HudScript::frame_update(crepe::duration_t dt) {  	txt_co.text = amount_of_coins;  	txt_co.dimensions = {COINS_CHAR_WIDTH*amount_of_coins.size(),(COINS_CHAR_WIDTH)*2};  	txt_co.offset = TOP_LEFT+FONTOFFSET+COINS_OFFSET + vec2{amount_of_coins.size() * COINS_CHAR_WIDTH/2,0}; + +	// FPS +	Text & txt_fps = this->get_components_by_name<Text>(HUD_FPS).front(); +	float fps = this->get_loop_timer().get_fps(); +	string fps_amount = to_string(this->get_loop_timer().get_fps()); +	txt_fps.text = fps_amount; +	txt_fps.dimensions = {FPS_CHAR_WIDTH*fps_amount.size(),(FPS_CHAR_WIDTH)*2}; +	txt_fps.offset = TOP_LEFT+FONTOFFSET+FPS_OFFSET + vec2{fps_amount.size() * FPS_CHAR_WIDTH/2,0}; +	if(fps >= 30) txt_fps.data.text_color = Color::YELLOW; +	if(fps >= 50) txt_fps.data.text_color = Color::GREEN; +	if(fps < 30) txt_fps.data.text_color = Color::RED;  } diff --git a/game/hud/HudSubScene.cpp b/game/hud/HudSubScene.cpp index 126f933..dd36d1c 100644 --- a/game/hud/HudSubScene.cpp +++ b/game/hud/HudSubScene.cpp @@ -28,9 +28,17 @@ void HudSubScene::create(Scene & scn){  	// Coins  	GameObject hud_coin = scn.new_object(HUD_COINS); -	crepe::vec2 size = {COINS_CHAR_WIDTH*COINS_LENGTH,(COINS_CHAR_WIDTH)*2}; -	hud_coin.add_component<Text>(size, FONT,Text::Data{ +	crepe::vec2 size_coin = {COINS_CHAR_WIDTH*COINS_LENGTH,(COINS_CHAR_WIDTH)*2}; +	hud_coin.add_component<Text>(size_coin, FONT,Text::Data{  		.world_space = false,  		.text_color = Color::YELLOW,  	}, TOP_LEFT+FONTOFFSET+COINS_OFFSET + vec2{COINS_LENGTH * COINS_CHAR_WIDTH/2,0}, COINS); + +	// Fps +	GameObject hud_fps = scn.new_object(HUD_FPS); +	crepe::vec2 size_fps = {FPS_CHAR_WIDTH*FPS_LENGTH,(FPS_CHAR_WIDTH)*2}; +	hud_fps.add_component<Text>(size_fps, FONT,Text::Data{ +		.world_space = false, +		.text_color = Color::GREEN, +	}, TOP_LEFT+FONTOFFSET+FPS_OFFSET + vec2{FPS_LENGTH * FPS_CHAR_WIDTH/2,0}, FPS);  }  |