Settle the window size and UIs
parent
b36592311a
commit
f5fa46aeeb
5
main.c
5
main.c
|
@ -3,6 +3,7 @@
|
|||
#include "scene_impl.h"
|
||||
#include "ent_impl.h"
|
||||
#include "mempool.h"
|
||||
#include "constants.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#define N_SCENES 4
|
||||
|
@ -15,8 +16,8 @@ static GameEngine_t engine = {
|
|||
.assets = {0}
|
||||
};
|
||||
|
||||
const int screenWidth = 1280;
|
||||
const int screenHeight = 640;
|
||||
const int screenWidth = VIEWABLE_MAP_WIDTH * TILE_SIZE;
|
||||
const int screenHeight = VIEWABLE_MAP_HEIGHT * TILE_SIZE;
|
||||
|
||||
// Maintain own queue to handle key presses
|
||||
struct sc_queue_32 key_buffer;
|
||||
|
|
|
@ -32,7 +32,7 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
CAirTimer_t* p_air = get_component(p_ent, CAIRTIMER_T);
|
||||
|
||||
Sprite_t* spr = get_sprite(&scene->engine->assets, "p_bigbubble");
|
||||
Vector2 air_pos = {data->game_rec.x + data->game_rec.width - 32, data->game_rec.y + data->game_rec.height - 32};
|
||||
Vector2 air_pos = {data->game_rec.width - 32, data->game_rec.height - 32};
|
||||
for (uint8_t i = 0; i < p_air->curr_count; i++)
|
||||
{
|
||||
draw_sprite(spr, 0, air_pos, 0, false);
|
||||
|
@ -41,18 +41,14 @@ static void level_scene_render_func(Scene_t* scene)
|
|||
}
|
||||
}
|
||||
// For DEBUG
|
||||
const int gui_x = data->game_rec.x + data->game_rec.width + 10;
|
||||
//sprintf(buffer, "Spawn Entity: %s", get_spawn_selection_string(current_spawn_selection));
|
||||
//DrawText(buffer, gui_x, 240, 12, BLACK);
|
||||
sprintf(buffer, "Number of Entities: %u", sc_map_size_64v(&scene->ent_manager.entities));
|
||||
DrawText(buffer, gui_x, 70, 12, BLACK);
|
||||
sprintf(buffer, "FPS: %u", GetFPS());
|
||||
DrawText(buffer, gui_x, 120, 12, BLACK);
|
||||
int gui_x = 5;
|
||||
sprintf(buffer, "%u %u", sc_map_size_64v(&scene->ent_manager.entities), GetFPS());
|
||||
DrawText(buffer, gui_x, data->game_rec.height - 12, 12, WHITE);
|
||||
|
||||
print_mempool_stats(buffer);
|
||||
DrawText(buffer, gui_x, 150, 12, BLACK);
|
||||
DrawRectangle(0, 0, data->game_rec.width, 0, (Color){0,0,0,64});
|
||||
sprintf(buffer, "Chests: %u / %u", data->coins.current, data->coins.total);
|
||||
DrawText(buffer, gui_x, data->game_rec.y + data->game_rec.height, 24, BLACK);
|
||||
gui_x = data->game_rec.width - MeasureText(buffer, 24) - 5;
|
||||
DrawText(buffer, gui_x, 0, 24, RED);
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
|
@ -488,8 +484,7 @@ void init_game_scene(LevelScene_t* scene)
|
|||
init_level_scene_data(
|
||||
&scene->data, MAX_N_TILES, all_tiles,
|
||||
(Rectangle){
|
||||
(scene->scene.engine->intended_window_size.x- VIEWABLE_MAP_WIDTH*TILE_SIZE) / 2.0f,
|
||||
(scene->scene.engine->intended_window_size.y- VIEWABLE_MAP_HEIGHT*TILE_SIZE) / 2.0f,
|
||||
0,0,
|
||||
VIEWABLE_MAP_WIDTH*TILE_SIZE, VIEWABLE_MAP_HEIGHT*TILE_SIZE
|
||||
}
|
||||
);
|
||||
|
@ -504,13 +499,9 @@ void init_game_scene(LevelScene_t* scene)
|
|||
scene->data.game_rec
|
||||
);
|
||||
add_scene_layer(
|
||||
&scene->scene, scene->scene.engine->intended_window_size.x,
|
||||
scene->scene.engine->intended_window_size.y,
|
||||
(Rectangle){
|
||||
0, 0,
|
||||
scene->scene.engine->intended_window_size.x,
|
||||
scene->scene.engine->intended_window_size.y
|
||||
}
|
||||
&scene->scene,
|
||||
scene->data.game_rec.width, scene->data.game_rec.height,
|
||||
scene->data.game_rec
|
||||
);
|
||||
|
||||
create_player(&scene->scene.ent_manager);
|
||||
|
|
|
@ -58,6 +58,7 @@ static void level_select_do_action(Scene_t* scene, ActionType_t action, bool pre
|
|||
if (!pressed)
|
||||
{
|
||||
unsigned int prev_sel = data->scroll_area.curr_selection;
|
||||
// TODO: Add scene offset to scroll area calculation
|
||||
if (vert_scrollarea_set_pos(&data->scroll_area, scene->mouse_pos) != data->scroll_area.n_items)
|
||||
{
|
||||
vert_scrollarea_refocus(&data->scroll_area);
|
||||
|
@ -96,18 +97,21 @@ static void level_select_do_action(Scene_t* scene, ActionType_t action, bool pre
|
|||
}
|
||||
}
|
||||
|
||||
#define START_X 300
|
||||
#define START_Y 100
|
||||
#define FONT_SIZE 30
|
||||
#define TEXT_PADDING 3
|
||||
#define DISPLAY_AREA_HEIGHT 400
|
||||
#define SCROLL_TOTAL_HEIGHT 800
|
||||
#define DISPLAY_AREA_HEIGHT 200
|
||||
#define SCROLL_TOTAL_HEIGHT 300
|
||||
void init_level_select_scene(LevelSelectScene_t* scene)
|
||||
{
|
||||
init_scene(&scene->scene, &level_select_do_action, 0);
|
||||
add_scene_layer(
|
||||
&scene->scene, 400, 800,
|
||||
(Rectangle){START_X, START_Y, 400, 800}
|
||||
&scene->scene, scene->scene.engine->intended_window_size.x,
|
||||
scene->scene.engine->intended_window_size.y,
|
||||
(Rectangle){
|
||||
0, 0,
|
||||
scene->scene.engine->intended_window_size.x,
|
||||
scene->scene.engine->intended_window_size.y
|
||||
}
|
||||
);
|
||||
vert_scrollarea_init(&scene->data.scroll_area, (Rectangle){50, 100, 150, DISPLAY_AREA_HEIGHT - 100}, (Vector2){150, SCROLL_TOTAL_HEIGHT});
|
||||
vert_scrollarea_set_item_dims(&scene->data.scroll_area, FONT_SIZE, TEXT_PADDING);
|
||||
|
|
|
@ -3,22 +3,21 @@
|
|||
#include "raymath.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define START_X 300
|
||||
|
||||
static void menu_scene_render_func(Scene_t* scene)
|
||||
{
|
||||
MenuSceneData_t* data = &(CONTAINER_OF(scene, MenuScene_t, scene)->data);
|
||||
|
||||
Sprite_t* spr = get_sprite(&scene->engine->assets, "title_spr");
|
||||
Rectangle render_rec = scene->layers.render_layers[0].render_area;
|
||||
BeginTextureMode(scene->layers.render_layers[0].layer_tex);
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Bunny's Spelunking Adventure", START_X, 100, 32, BLACK);
|
||||
int title_width = MeasureText("Bunny's Spelunking Adventure", 32);
|
||||
DrawText("Bunny's Spelunking Adventure", (render_rec.width - title_width) / 2, 20, 32, BLACK);
|
||||
UI_button(data->buttons, "Start");
|
||||
UI_button(data->buttons + 1, "Sandbox");
|
||||
UI_button(data->buttons + 2, "Continue");
|
||||
UI_button(data->buttons + 3, "Exit");
|
||||
UI_button(data->buttons + 1, "Continue");
|
||||
UI_button(data->buttons + 2, "Exit");
|
||||
|
||||
draw_sprite(spr, 0, (Vector2){START_X + 200, 120}, 0, false);
|
||||
draw_sprite(spr, 0, (Vector2){render_rec.width / 2, 50}, 0, false);
|
||||
EndTextureMode();
|
||||
}
|
||||
|
||||
|
@ -29,10 +28,7 @@ static void exec_component_function(Scene_t* scene, int sel)
|
|||
case 0:
|
||||
change_scene(scene->engine, LEVEL_SELECT_SCENE);
|
||||
break;
|
||||
case 1:
|
||||
change_scene(scene->engine, SANDBOX_SCENE);
|
||||
break;
|
||||
case 3:
|
||||
case 2:
|
||||
scene->state = 0;
|
||||
break;
|
||||
default:
|
||||
|
@ -143,23 +139,25 @@ void init_menu_scene(MenuScene_t* scene)
|
|||
sc_array_add(&scene->scene.systems, &gui_loop);
|
||||
sc_array_add(&scene->scene.systems, &menu_scene_render_func);
|
||||
|
||||
int button_x = scene->scene.engine->intended_window_size.x / 4;
|
||||
int button_y = scene->scene.engine->intended_window_size.y / 4;
|
||||
scene->data.buttons[0] = (UIComp_t) {
|
||||
.bbox = {START_X,255,125,30},
|
||||
.bbox = {button_x,button_y,125,30},
|
||||
.state = STATE_NORMAL,
|
||||
.alpha = 1.0
|
||||
};
|
||||
scene->data.buttons[1] = (UIComp_t) {
|
||||
.bbox = {START_X,300,125,30},
|
||||
.bbox = {button_x,button_y+45,125,30},
|
||||
.state = STATE_NORMAL,
|
||||
.alpha = 1.0
|
||||
};
|
||||
scene->data.buttons[2] = (UIComp_t) {
|
||||
.bbox = {START_X,345,125,30},
|
||||
.bbox = {button_x,button_y+90,125,30},
|
||||
.state = STATE_NORMAL,
|
||||
.alpha = 1.0
|
||||
};
|
||||
scene->data.buttons[3] = (UIComp_t) {
|
||||
.bbox = {START_X,390,125,30},
|
||||
.bbox = {button_x,button_y+135,125,30},
|
||||
.state = STATE_NORMAL,
|
||||
.alpha = 1.0
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue