Map works!

This commit is contained in:
Pyrex 2024-02-26 20:19:22 -08:00
parent 055b3dd7b1
commit 9ef88fb34d
4 changed files with 43 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "art/game_demo_sprites.h" #include "art/game_demo_sprites.h"
#include "device/device.h" #include "device/device.h"
#include "map/game_map.h"
#include "game.h" #include "game.h"
#include "sys/sys.h" #include "sys/sys.h"
@ -13,6 +14,7 @@ int32_t ellipse_x1 = 96 * 4;
int32_t ellipse_y1 = 96 * 4; int32_t ellipse_y1 = 96 * 4;
int32_t ellipse_dx1 = 3; int32_t ellipse_dx1 = 3;
int32_t ellipse_dy1 = 4; int32_t ellipse_dy1 = 4;
int32_t map_x = 0;
const char* game_title() { const char* game_title() {
@ -47,6 +49,9 @@ void game_destroy() {
void game_update() { void game_update() {
game_frame += 4; game_frame += 4;
map_x += 1;
map_x %= 160;
ellipse_x0 += ellipse_dx0; ellipse_x0 += ellipse_dx0;
if (ellipse_x0 < 0 || ellipse_x0 > DEVICE_W * 4) { ellipse_dx0 *= -1; } if (ellipse_x0 < 0 || ellipse_x0 > DEVICE_W * 4) { ellipse_dx0 *= -1; }
ellipse_y0 += ellipse_dy0; ellipse_y0 += ellipse_dy0;
@ -101,4 +106,6 @@ void game_draw() {
16, 8, 16, 8,
false, false false, false
); );
sys_map_draw(game_map, game_demo_sprites, 0, 0, map_x, 8, 32, 18);
} }

View File

@ -1,5 +1,11 @@
#ifndef CROCPARTY_GAME_MAP_H #ifndef CROCPARTY_GAME_MAP_H
#define CROCPARTY_GAME_MAP_H #define CROCPARTY_GAME_MAP_H
#include "sys/sys.h"
extern sys_i32 game_map_player_start_x;
extern sys_i32 game_map_player_start_y;
extern sys_map game_map;
#endif #endif

View File

@ -267,6 +267,25 @@ void sys_sprite_draw_ext(
} }
} }
void sys_map_draw(
sys_map map,
sys_spritesheet spritesheet,
sys_i32 sx, sys_i32 sy,
sys_i32 tile_x, sys_i32 tile_y,
sys_i32 tile_w, sys_i32 tile_h
) {
for (sys_i32 ty = 0; ty < tile_h; ty++) {
for (sys_i32 tx = 0; tx < tile_w; tx++) {
sys_i32 real_tx = tx + tile_x;
sys_i32 real_ty = ty + tile_y;
if (real_tx < 0 || real_tx >= map.width) { continue; }
if (real_ty < 0 || real_ty >= map.height) { continue; }
sys_maptile tile = map.tiles[real_tx + map.width * real_ty];
sys_sprite_draw(spritesheet, tile, sx + tx * 8, sy + ty * 8);
}
}
}
// == internal primitives == // == internal primitives ==
void sys_pixel_internal_set(sys_i32 x, sys_i32 y, sys_color c) { void sys_pixel_internal_set(sys_i32 x, sys_i32 y, sys_color c) {
sys_color realc = sys_dpal[c]; sys_color realc = sys_dpal[c];

View File

@ -167,5 +167,16 @@ void sys_sprite_draw_ext(
// TODO: SSPR // TODO: SSPR
// TODO: FILLP? // TODO: FILLP?
void sys_map_draw(
// NOTE: not the same order of args
// as on pico 8
// but: more consistent!
sys_map map,
sys_spritesheet spritesheet,
sys_i32 sx, sys_i32 sy,
sys_i32 tile_x, sys_i32 tile_y,
sys_i32 tile_w, sys_i32 tile_h
// TODO: Layers?
);
#endif // CROCPARTY_SYS_GRAPHICS_H #endif // CROCPARTY_SYS_GRAPHICS_H