Load Ultimate Lizard Total Destruction spritesheet

This commit is contained in:
2024-02-26 17:31:58 -08:00
parent 79eb52e282
commit f6d942c614
6 changed files with 91 additions and 9 deletions

View File

@ -15,6 +15,11 @@ typedef uint64_t sys_glyph;
typedef struct {
sys_color pixels[SYS_SPRITE_H][SYS_SPRITE_W];
} sys_sprite;
typedef struct {
sys_sprite* sprites;
uint32_t width;
uint32_t height;
} sys_spritesheet;
sys_screen_color sys_make_screen_color(uint8_t r, uint8_t g, uint8_t b);

View File

@ -11,7 +11,8 @@ void sys_pixel_internal_set(sys_i32 x, sys_i32 y, sys_color c);
void sys_scanline_internal_set(
sys_i32 x0, sys_i32 x1, sys_i32 y, sys_color c, bool fill
);
void sys_glyph_draw(sys_i32 x, sys_i32 y, sys_glyph g, sys_color c);
void sys_glyph_internal_draw(sys_i32 x, sys_i32 y, sys_glyph g, sys_color c);
void sys_sprite_internal_draw(sys_i32 x, sys_i32 y, sys_sprite s);
// == public ==
void sys_clip_set(sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1) {
@ -63,7 +64,7 @@ void sys_print(char* str, sys_i32 x, sys_i32 y, sys_color col) {
if (c == 0) { break; }
if (c == '\n') { x = x_orig; y += 8; continue; }
if (c == '\r') { x = x_orig; continue; }
sys_glyph_draw(x, y, sys_font_small[c], col);
sys_glyph_internal_draw(x, y, sys_font_small[c], col);
x += 8;
}
}
@ -232,6 +233,40 @@ void sys_dpal_reset() {
}
}
void sys_sprite_draw(
sys_spritesheet spritesheet,
sys_i32 n,
sys_i32 x, sys_i32 y
) {
sys_sprite_draw_ext(
spritesheet,
n,
x, y,
1, 1,
false, false
);
}
void sys_sprite_draw_ext(
sys_spritesheet spritesheet,
sys_i32 n,
sys_i32 x, sys_i32 y,
sys_i32 w, sys_i32 h,
bool flip_x, bool flip_y
) {
// map n to a specific entity on the spritesheet
// (this is necessary for w and h)
for (int sy = 0; sy < h; sy++) {
for (int sx = 0; sx < w; sx++) {
sys_i32 tile = n + sx + sy * spritesheet.width;
if (tile < 0 || tile >= spritesheet.width * spritesheet.height) {
continue;
}
sys_sprite_internal_draw(x + sx * 8, y + sy * 8, spritesheet.sprites[tile]);
}
}
}
// == internal primitives ==
void sys_pixel_internal_set(sys_i32 x, sys_i32 y, sys_color c) {
sys_color realc = sys_dpal[c];
@ -265,7 +300,7 @@ void sys_scanline_internal_set(
}
}
void sys_glyph_draw(sys_i32 x, sys_i32 y, sys_glyph g, sys_color c) {
void sys_glyph_internal_draw(sys_i32 x, sys_i32 y, sys_glyph g, sys_color c) {
// iterate through the bits of the glyph, and draw the character
// if that bit is set
for (int py = 0; py < 8; py++) {
@ -276,4 +311,12 @@ void sys_glyph_draw(sys_i32 x, sys_i32 y, sys_glyph g, sys_color c) {
}
}
}
}
void sys_sprite_internal_draw(sys_i32 x, sys_i32 y, sys_sprite s) {
for (int py = 0; py < 8; py++) {
for (int px = 0; px < 8; px++) {
sys_pixel_internal_set(x + px, y + py, s.pixels[py][px]);
}
}
}

View File

@ -83,7 +83,7 @@ void sys_camera_reset();
*
* If r is negative, the circle is not drawn.
*
* This is a special case of sys_circ_oval_draw_ext.
* This is a special case of sys_oval_draw_ext.
*/
void sys_circ_draw(sys_i32 x, sys_i32 y, sys_i32 r, sys_color c);
void sys_circ_fill(sys_i32 x, sys_i32 y, sys_i32 r, sys_color c);
@ -146,7 +146,24 @@ void sys_dpal_set(sys_color c0, sys_color c1);
*/
void sys_dpal_reset();
// TODO: SPR
/**
* Draw a given sprite.
*
* w, h default to 1.
* flip_x and flip_y default to false.
*/
void sys_sprite_draw(
sys_spritesheet spritesheet,
sys_i32 n,
sys_i32 x, sys_i32 y
);
void sys_sprite_draw_ext(
sys_spritesheet spritesheet,
sys_i32 n,
sys_i32 x, sys_i32 y,
sys_i32 w, sys_i32 h,
bool flip_x, bool flip_y
);
// TODO: SSPR
// TODO: FILLP?