core combo mechanic with classy HUD
This commit is contained in:
parent
8254b76c77
commit
c1107cf675
|
@ -62,7 +62,9 @@ set(ASSETS
|
|||
assets-cg/menu_title.png
|
||||
# HUD
|
||||
assets-cg/hud.png
|
||||
assets-cg/hud_arcade_font.png
|
||||
assets-cg/hud_backpack.ase
|
||||
assets-cg/hud_combo.png
|
||||
assets-cg/hud_delay.png
|
||||
assets-cg/hud_flag.png
|
||||
assets-cg/hud_itemslots.png
|
||||
|
|
|
@ -15,6 +15,9 @@ hud_backpack.ase:
|
|||
center: 0, 0
|
||||
next: Idle=Idle, Open=Idle, InventoryOpen=InventoryIdle, InventoryIdle=InventoryIdle, InventoryClose=Idle
|
||||
|
||||
hud_arcade_font.png:
|
||||
profile: p8
|
||||
|
||||
font_rogue.png:
|
||||
type: font
|
||||
name: font_rogue
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 758 B |
12
src/game.c
12
src/game.c
|
@ -40,6 +40,8 @@ bool game_load(game_t *g, level_t const *level)
|
|||
g->wave_number = 0;
|
||||
g->wave_spawned = 0;
|
||||
g->wave_left = NULL;
|
||||
g->combo = 0;
|
||||
g->combo_health = fix(0);
|
||||
|
||||
g->hud_xp_anim.frame = anims_hud_xp_Idle.start[0];
|
||||
g->hud_xp_anim.elapsed = 0;
|
||||
|
@ -293,6 +295,10 @@ void game_remove_dead_entities(game_t *g)
|
|||
g->hud_xp_anim.elapsed = 0;
|
||||
}
|
||||
|
||||
/* Update player combo */
|
||||
g->combo++;
|
||||
g->combo_health = fix(1);
|
||||
|
||||
entity_mark_to_delete(e);
|
||||
}
|
||||
}
|
||||
|
@ -465,6 +471,12 @@ void game_update_effects(game_t *g, fixed_t dt)
|
|||
f->invulnerability_delay = max(f->invulnerability_delay - dt, fix(0));
|
||||
f->speed_delay = max(f->speed_delay - dt, fix(0));
|
||||
}
|
||||
|
||||
g->combo_health -= dt / 5;
|
||||
if(g->combo_health <= 0) {
|
||||
g->combo_health = 0;
|
||||
g->combo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void game_update_aoes(game_t *g, fixed_t dt)
|
||||
|
|
|
@ -49,6 +49,10 @@ typedef struct game {
|
|||
int wave_number;
|
||||
int wave_spawned;
|
||||
uint8_t *wave_left;
|
||||
/* Current combo score and its health (measured between 0 and 1, decreases
|
||||
at a variable rate) */
|
||||
int combo;
|
||||
fixed_t combo_health;
|
||||
|
||||
/* XP bar animation */
|
||||
anim_state_t hud_xp_anim;
|
||||
|
|
58
src/render.c
58
src/render.c
|
@ -473,6 +473,50 @@ int render_small_text(int x, int y, int color, char const *text, int size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int render_arcade_char_size(int c)
|
||||
{
|
||||
if(c < '0' || c > '9')
|
||||
return 0;
|
||||
return 7 - (c == '1' || c == '7') + (c == '4');
|
||||
}
|
||||
|
||||
int render_arcade_dsize(int value)
|
||||
{
|
||||
char str[16];
|
||||
sprintf(str, "%d", value);
|
||||
|
||||
int pixels = 0;
|
||||
for(int i = 0; str[i]; i++)
|
||||
pixels += render_arcade_char_size(str[i]);
|
||||
return pixels;
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
void render_arcade(int x, int y, int halign, int value, int color_style)
|
||||
{
|
||||
extern bopti_image_t img_hud_arcade_font;
|
||||
int w = render_arcade_dsize(value);
|
||||
if(halign == DTEXT_RIGHT)
|
||||
x -= w;
|
||||
else if(halign == DTEXT_CENTER)
|
||||
x -= (w >> 1);
|
||||
|
||||
/* Auto style based on the number of digits */
|
||||
if(color_style < 0)
|
||||
color_style = (value >= 10) + (value >= 100);
|
||||
|
||||
char str[16];
|
||||
sprintf(str, "%d", value);
|
||||
|
||||
for(int i = 0; str[i]; i++) {
|
||||
int w = render_arcade_char_size(str[i]);
|
||||
dsubimage(x, y, &img_hud_arcade_font, 1 + 9 * (str[i] - '0'),
|
||||
1 + 9 * color_style, w, 8, DIMAGE_NONE);
|
||||
x += w;
|
||||
}
|
||||
}
|
||||
|
||||
static void print_stat_opt(int x, int y, int stat, int reference,
|
||||
char const *format, ...)
|
||||
{
|
||||
|
@ -596,10 +640,8 @@ void render_game(game_t const *g, bool show_hitboxes)
|
|||
extern font_t font_hud;
|
||||
player_data_t *player_data = player_f->player;
|
||||
dfont(&font_hud);
|
||||
dprint_opt(164, HUD_Y - 5, RGB24(0x15171a), C_NONE, DTEXT_CENTER,
|
||||
DTEXT_TOP, "%d", player_data->xp_level);
|
||||
dprint_opt(164, HUD_Y - 6, RGB24(0xabb1ba), C_NONE, DTEXT_CENTER,
|
||||
DTEXT_TOP, "%d", player_data->xp_level);
|
||||
dprint(167, HUD_Y - 5, RGB24(0x15171a), "%d", player_data->xp_level);
|
||||
dprint(167, HUD_Y - 6, RGB24(0xabb1ba), "%d", player_data->xp_level);
|
||||
dfont(&font_rogue);
|
||||
|
||||
/* Render life bar */
|
||||
|
@ -656,6 +698,14 @@ void render_game(game_t const *g, bool show_hitboxes)
|
|||
/* Render backpack icon */
|
||||
anim_frame_render(skill_x(5)+2, HUD_Y-33+2, g->hud_backpack_anim.frame);
|
||||
|
||||
/* Render combo score */
|
||||
extern bopti_image_t img_hud_combo;
|
||||
fill_height = fround(img_hud_combo.height * g->combo_health);
|
||||
dsubimage(224, HUD_Y - 9 - fill_height, &img_hud_combo,
|
||||
0, img_hud_combo.height - fill_height, img_hud_combo.width,
|
||||
fill_height, DIMAGE_NONE);
|
||||
render_arcade(234, HUD_Y-25, DTEXT_CENTER, g->combo, -1);
|
||||
|
||||
if(g->menu_time > 0) {
|
||||
int x1 = cubic(-130, 0, g->menu_time, fix(1));
|
||||
int x2 = DWIDTH - 130 - x1;
|
||||
|
|
|
@ -74,3 +74,7 @@ void render_pfg_all2one(pfg_all2one_t const *paths, camera_t const *c,
|
|||
|
||||
/* Render one of some predefined short strings using an image. */
|
||||
int render_small_text(int x, int y, int color, char const *text, int size);
|
||||
|
||||
/* Colored arcade font. */
|
||||
int render_arcade_dsize(int value);
|
||||
void render_arcade(int x, int y, int halign, int value, int color_style);
|
||||
|
|
Loading…
Reference in New Issue