move platformes and scenery to /apps/demos/
This commit is contained in:
61
apps/demos/scenery/scenes/title.c
Normal file
61
apps/demos/scenery/scenes/title.c
Normal file
@ -0,0 +1,61 @@
|
||||
#include "title.h"
|
||||
#include "ingame.h"
|
||||
|
||||
#include "twn_game_api.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
static void title_tick(State *state) {
|
||||
SceneTitle *scn = (SceneTitle *)state->scene;
|
||||
(void)scn;
|
||||
|
||||
if (input_is_action_just_pressed("ui_accept")) {
|
||||
switch_to(state, ingame_scene);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_sprite("/assets/title.png", ((Rect) {
|
||||
((float)ctx.base_draw_w / 2) - ((float)320 / 2), 64, 320, 128 }));
|
||||
|
||||
|
||||
/* draw the tick count as an example of dynamic text */
|
||||
size_t text_str_len = snprintf(NULL, 0, "%lu", state->ctx->tick_count) + 1;
|
||||
char *text_str = cmalloc(text_str_len);
|
||||
snprintf(text_str, text_str_len, "%lu", state->ctx->tick_count);
|
||||
|
||||
const char *font = "/fonts/kenney-pixel.ttf";
|
||||
int text_h = 32;
|
||||
int text_w = draw_text_width(text_str, text_h, font);
|
||||
|
||||
draw_rectangle(
|
||||
(Rect) {
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.w = (float)text_w,
|
||||
.h = (float)text_h,
|
||||
},
|
||||
(Color) { 0, 0, 0, 255 }
|
||||
);
|
||||
draw_text(text_str, (Vec2){ 0, 0 }, text_h, (Color) { 255, 255, 255, 255 }, font);
|
||||
|
||||
free(text_str);
|
||||
}
|
||||
|
||||
|
||||
static void title_end(State *state) {
|
||||
free(state->scene);
|
||||
}
|
||||
|
||||
|
||||
Scene *title_scene(State *state) {
|
||||
(void)state;
|
||||
|
||||
SceneTitle *new_scene = ccalloc(1, sizeof *new_scene);
|
||||
new_scene->base.tick = title_tick;
|
||||
new_scene->base.end = title_end;
|
||||
|
||||
return (Scene *)new_scene;
|
||||
}
|
Reference in New Issue
Block a user