aboutsummaryrefslogtreecommitdiff
path: root/src/game_loop/ui.c
blob: 60dbfc2baa23ff4887553ca0a188b83e63f381a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "game_loop/ui.h"

void hh_ui_show_hp(int* idx, hh_entity* player, uint8_t max_hp, vec_cor cam_pos) {
	for (int i = 0; i < max_hp; i++) {
		int tilemap_idx = HH_TM_HUD_HEART_OFFSET + (player->hp > i?0:1),
			palette_idx = HH_PAL_IDX_HUD;
		hh_show_quad(idx, &(hh_s_rendering){
			.frame0 = tilemap_idx,
			.palette = palette_idx,
			.fam = (hh_s_ppu_loc_fam_entry){
				.horizontal_flip = false, .vertical_flip = false,
				.palette_index = palette_idx,
				.tilemap_index = tilemap_idx,
				.position_x = 8 + i*15, .position_y = 8
			}
		});
	}
}
void hh_ui_show_char(int* idx, char* str, vec2 pos) {
	int i = 0;
	int tilemap_idx,
		palette_idx = 6;
	while (str[i] != '\0') {
		if(str[i] >= 'A' && str[i] <= 'Z'){
			tilemap_idx = HH_TM_FONT_OFFSET + str[i]-'A'+10;
		} else if (str[i] >= 'a' && str[i] <= 'z') {
			tilemap_idx = HH_TM_FONT_OFFSET + str[i]-'a'+10;
		} else if (str[i] >= '0' && str[i] <= '9'){
			tilemap_idx = HH_TM_FONT_OFFSET + str[i]-48;
		} else {
			return;
		}
		hh_show_quad(idx, &(hh_s_rendering){
			.frame0 = tilemap_idx,
			.palette = palette_idx,
			.fam = (hh_s_ppu_loc_fam_entry){
				.horizontal_flip = false, .vertical_flip = false,
				.palette_index = palette_idx,
				.tilemap_index = tilemap_idx,
				.position_x = pos.x + i*15, .position_y = pos.y
			}
		});
		i++;
	}
		
}

void itoa(char *c, int i) {
	c[0] = i + '0';
	c[1] = '\0';
}

void hh_shift_selected(uint8_t *pos, bool dir, uint8_t min, uint8_t max) {
	if (dir) {
		*pos = MIN(*pos+1,max);
	} else {
		*pos = MAX(*pos-1,min);
	}
}