2024-07-08 00:44:20 +00:00
|
|
|
#include "title.h"
|
|
|
|
#include "ingame.h"
|
|
|
|
#include "../world.h"
|
|
|
|
#include "../player.h"
|
2024-08-21 13:55:34 +00:00
|
|
|
|
2024-09-16 13:17:00 +00:00
|
|
|
#include "twn_game_api.h"
|
2024-07-08 00:44:20 +00:00
|
|
|
|
2024-10-06 21:00:36 +00:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
2024-08-26 21:33:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
static void title_tick(State *state) {
|
|
|
|
SceneTitle *scn = (SceneTitle *)state->scene;
|
2024-07-08 00:44:20 +00:00
|
|
|
(void)scn;
|
|
|
|
|
2024-10-08 07:12:30 +00:00
|
|
|
if (input_is_action_just_pressed("ui_accept")) {
|
2024-07-08 00:44:20 +00:00
|
|
|
switch_to(state, ingame_scene);
|
2024-10-07 22:07:01 +00:00
|
|
|
return;
|
2024-07-08 00:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
m_sprite("/assets/title.png", ((Rect) {
|
2024-10-01 00:13:58 +00:00
|
|
|
((float)ctx.base_draw_w / 2) - ((float)320 / 2), 64, 320, 128 }));
|
2024-08-23 02:41:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* draw the tick count as an example of dynamic text */
|
2024-08-27 10:42:40 +00:00
|
|
|
size_t text_str_len = snprintf(NULL, 0, "%lu", state->ctx->tick_count) + 1;
|
2024-08-23 02:41:52 +00:00
|
|
|
char *text_str = cmalloc(text_str_len);
|
2024-08-27 10:42:40 +00:00
|
|
|
snprintf(text_str, text_str_len, "%lu", state->ctx->tick_count);
|
2024-08-23 02:41:52 +00:00
|
|
|
|
|
|
|
const char *font = "fonts/kenney-pixel.ttf";
|
|
|
|
int text_h = 32;
|
2024-10-07 14:53:09 +00:00
|
|
|
int text_w = draw_text_width(text_str, text_h, font);
|
2024-08-23 02:41:52 +00:00
|
|
|
|
2024-10-07 14:53:09 +00:00
|
|
|
draw_rectangle(
|
2024-09-23 17:43:16 +00:00
|
|
|
(Rect) {
|
2024-08-23 02:41:52 +00:00
|
|
|
.x = 0,
|
|
|
|
.y = 0,
|
|
|
|
.w = (float)text_w,
|
|
|
|
.h = (float)text_h,
|
|
|
|
},
|
2024-09-23 17:43:16 +00:00
|
|
|
(Color) { 0, 0, 0, 255 }
|
2024-08-23 02:41:52 +00:00
|
|
|
);
|
2024-10-07 14:53:09 +00:00
|
|
|
draw_text(
|
2024-08-23 02:41:52 +00:00
|
|
|
text_str,
|
2024-09-23 17:43:16 +00:00
|
|
|
(Vec2){ 0, 0 },
|
2024-08-23 02:41:52 +00:00
|
|
|
text_h,
|
2024-09-23 17:43:16 +00:00
|
|
|
(Color) { 255, 255, 255, 255 },
|
2024-08-23 02:41:52 +00:00
|
|
|
font
|
|
|
|
);
|
|
|
|
free(text_str);
|
2024-07-08 00:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
static void title_end(State *state) {
|
|
|
|
SceneTitle *scn = (SceneTitle *)state->scene;
|
2024-07-08 00:44:20 +00:00
|
|
|
player_destroy(scn->player);
|
|
|
|
world_destroy(scn->world);
|
2024-07-27 22:44:39 +00:00
|
|
|
free(state->scene);
|
2024-07-08 00:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
Scene *title_scene(State *state) {
|
2024-07-08 00:44:20 +00:00
|
|
|
(void)state;
|
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
SceneTitle *new_scene = ccalloc(1, sizeof *new_scene);
|
2024-07-08 00:44:20 +00:00
|
|
|
new_scene->base.tick = title_tick;
|
|
|
|
new_scene->base.end = title_end;
|
|
|
|
|
|
|
|
new_scene->world = world_create();
|
|
|
|
new_scene->player = player_create(new_scene->world);
|
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
return (Scene *)new_scene;
|
2024-07-08 00:44:20 +00:00
|
|
|
}
|