Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Experimento con emscripten y SDL

1178 views
1
#include "engine.h"
2
3
void background_render_handler(actor *a)
4
{
5
background_actor *bg = (background_actor *)a;
6
7
sprite_render(&(bg->background_sprite));
8
SDL_Rect dest = {.x = 0, .y = 0, .w = eng.grid_width * TILE_DIMENSION, .h = STATUS_BAR_HEIGHT * TILE_DIMENSION};
9
SDL_RenderCopy (eng.renderer, bg->status_bar, NULL, &dest);
10
11
SDL_QueryTexture(bg->status_text,
12
NULL, NULL, &dest.w, &dest.h);
13
dest.x = 80;
14
dest.y = 20;
15
SDL_RenderCopy (eng.renderer, bg->status_text, NULL, &dest);
16
}
17
18
background_actor *background_actor_init(background_actor *bg)
19
{
20
actor_init(&bg->a, background_render_handler, NULL);
21
sprite_init(
22
&bg->background_sprite,
23
eng.grid_width * TILE_DIMENSION,
24
eng.grid_height * TILE_DIMENSION,
25
&eng.sand_decal);
26
bg->background_sprite.r[0] = 0;
27
bg->background_sprite.r[1] = STATUS_BAR_HEIGHT * TILE_DIMENSION;
28
29
bg->status_bar = eng.textures[STATUS_BAR_TEXTURE]; // SDL_CreateTextureFromSurface(eng.renderer, status_surface);
30
31
bg->font = TTF_OpenFont(STATUS_TEXT_FONT, STATUS_TEXT_SIZE);
32
background_actor_update_scoreboard(bg);
33
34
return bg;
35
}
36
37
background_actor *background_actor_update_scoreboard(background_actor *bg)
38
{
39
SDL_Color fg={93,93,93,255};
40
char msg[201];
41
sprintf(msg, "score: %02u", eng.score);
42
SDL_Surface *status_text_surface = TTF_RenderText_Blended(bg->font, msg, fg);
43
bg->status_text = SDL_CreateTextureFromSurface(eng.renderer, status_text_surface);
44
SDL_FreeSurface(status_text_surface);
45
46
return bg;
47
}
48
49