Fix flipping sprites, start work on player

This commit is contained in:
Pyrex 2024-02-27 15:35:51 -08:00
parent d823220e90
commit 57e025e6aa
4 changed files with 19 additions and 6 deletions

Binary file not shown.

BIN
game/art/game_player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 B

View File

@ -126,7 +126,7 @@ void game_draw() {
0,
x1, y1-64,
16, 8,
false, false
true, true
);
sys_map_draw(game_map, game_tiles, 0, 0, map_x, 0, 32, 18);

View File

@ -12,7 +12,7 @@ void sys_scanline_internal_set(
sys_i32 x0, sys_i32 x1, sys_i32 y, sys_color c, bool fill
);
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);
void sys_sprite_internal_draw(sys_i32 x, sys_i32 y, sys_sprite s, bool flip_x, bool flip_y);
// == public ==
void sys_clip_set(sys_i32 x0, sys_i32 y0, sys_i32 x1, sys_i32 y1) {
@ -258,11 +258,20 @@ void sys_sprite_draw_ext(
// (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;
sys_i32 sx_adj = flip_x ? w - 1 - sx : sx;
sys_i32 sy_adj = flip_y ? h - 1 - sy : sy;
sys_i32 tile =
n + sx_adj + sy_adj * spritesheet.width;
if (tile < 0 || tile >= spritesheet.width * spritesheet.height) {
continue;
}
sys_sprite_internal_draw(x + sx * 8, y + sy * 8, spritesheet.sprites[tile]);
sys_sprite_internal_draw(
x + sx * 8,
y + sy * 8,
spritesheet.sprites[tile],
flip_x,
flip_y
);
}
}
}
@ -332,10 +341,14 @@ 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) {
void sys_sprite_internal_draw(
sys_i32 x, sys_i32 y, sys_sprite s, bool flip_x, bool flip_y
) {
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]);
sys_i32 px_adj = flip_x ? 7 - px : px;
sys_i32 py_adj = flip_y ? 7 - py : py;
sys_pixel_internal_set(x + px, y + py, s.pixels[py_adj][px_adj]);
}
}
}