diff --git a/game/BUILD b/game/BUILD index 9c7315b..0a4e026 100644 --- a/game/BUILD +++ b/game/BUILD @@ -2,12 +2,30 @@ load("@bazel_skylib//rules:run_binary.bzl", "run_binary") cc_library( name = "game", - srcs = glob(["*.c"]) + [":art/game_tiles.c", ":map/game_map.c"], - hdrs = glob(["*.h"]) + [":art/game_tiles.h", ":map/game_map.h"], + srcs = glob(["*.c"]) + [ + "art/game_player.c", + "art/game_tiles.c", + "map/game_map.c", + ], + hdrs = glob(["*.h", "art/*.h", "map/*.h"]), visibility = ["//visibility:public"], deps = ["//device:device", "//sys:sys"] ) +run_binary( + name = "game_player", + args = [ + "game_player", + "64", # n sprites + "0", # key color + "$(location :art/game_player.png)", + "$(location :art/game_player.c)" + ], + srcs = [":art/game_player.png"], + outs = [":art/game_player.c"], + tool = "//pytools:spritesheet", +) + run_binary( name = "game_tiles", args = [ diff --git a/game/art/game_player.aseprite b/game/art/game_player.aseprite index d61f8ef..77e866b 100644 Binary files a/game/art/game_player.aseprite and b/game/art/game_player.aseprite differ diff --git a/game/art/game_player.h b/game/art/game_player.h new file mode 100644 index 0000000..4b61848 --- /dev/null +++ b/game/art/game_player.h @@ -0,0 +1,8 @@ +#ifndef CROCPARTY_GAME_PLAYER_H +#define CROCPARTY_GAME_PLAYER_H + +#include "sys/sys.h" + +extern sys_spritesheet game_player; + +#endif // CROCPARTY_GAME_PLAYER_H \ No newline at end of file diff --git a/game/art/game_player.png b/game/art/game_player.png index 3429398..f55bfd4 100644 Binary files a/game/art/game_player.png and b/game/art/game_player.png differ diff --git a/game/game.c b/game/game.c index 91c8b7c..2abf1fe 100644 --- a/game/game.c +++ b/game/game.c @@ -1,3 +1,4 @@ +#include "art/game_player.h" #include "art/game_tiles.h" #include "device/device.h" #include "map/game_map.h" @@ -6,17 +7,6 @@ uint32_t game_frame; -int32_t ellipse_x0 = 32 * 4; -int32_t ellipse_y0 = 32 * 4; -int32_t ellipse_dx0 = 1; -int32_t ellipse_dy0 = 2; -int32_t ellipse_x1 = 96 * 4; -int32_t ellipse_y1 = 96 * 4; -int32_t ellipse_dx1 = 3; -int32_t ellipse_dy1 = 4; -int32_t map_x = 0; - - const char* game_title() { return "Croc Party!"; } @@ -24,40 +14,7 @@ const char* game_title() { void game_init() { sys_init(); - game_frame = 0; - - for (uint32_t x = 0; x < 8; x++) { - for (uint32_t y = 0; y < 8; y++) { - for (uint32_t z = 0; z < 4; z++) { - sys_spal_set( - (x << 5)|(y << 2)|(z), - - ((x * 255)/7) << 24 | - ((y * 255)/7) << 16 | - ((z * 255)/3) << 8 - ); - } - } - } - sys_spal_set(0xfe, 0xffffffff); - - // pico palette - sys_spal_set(0x0, 0x000000ff); - sys_spal_set(0x1, 0x1d2b53ff); - sys_spal_set(0x2, 0x7e2553ff); - sys_spal_set(0x3, 0x008751ff); - sys_spal_set(0x4, 0xab5236ff); - sys_spal_set(0x5, 0x5f574fff); - sys_spal_set(0x6, 0xc2c3c7ff); - sys_spal_set(0x7, 0xfff1e8ff); - sys_spal_set(0x8, 0xff004dff); - sys_spal_set(0x9, 0xffa300ff); - sys_spal_set(0xa, 0xffec27ff); - sys_spal_set(0xb, 0x00e436ff); - sys_spal_set(0xc, 0x29adffff); - sys_spal_set(0xd, 0x83769cff); - sys_spal_set(0xe, 0xff77a8ff); - sys_spal_set(0xf, 0xffccaaff); + game_palette_init(); } void game_destroy() { @@ -65,69 +22,16 @@ void game_destroy() { } void game_update() { - game_frame += 4; - -/* - map_x += 1; - map_x += 32; - map_x %= 64; - map_x -= 32; - */ - - ellipse_x0 += ellipse_dx0; - if (ellipse_x0 < 0 || ellipse_x0 > DEVICE_W * 4) { ellipse_dx0 *= -1; } - ellipse_y0 += ellipse_dy0; - if (ellipse_y0 < 0 || ellipse_y0 > DEVICE_H * 4) { ellipse_dy0 *= -1; } - - ellipse_x1 += ellipse_dx1; - if (ellipse_x1 < 0 || ellipse_x1 > DEVICE_W * 4) { ellipse_dx1 *= -1; } - ellipse_y1 += ellipse_dy1; - if (ellipse_y1 < 0 || ellipse_y1 > DEVICE_H * 4) { ellipse_dy1 *= -1; } + game_frame += 1; } void game_draw() { - sys_dpal_set(0xff, 0xfe); // map to a non-transparent color - - for (int x = 0; x < DEVICE_W; x++) { - for (int y = 0; y < DEVICE_H; y++) { - uint32_t r = (x * 255)/(DEVICE_W - 1); - uint32_t g = (y * 255)/(DEVICE_H - 1); - uint32_t b = game_frame & 0x100 ? 0xff - game_frame & 0xff : game_frame & 0xff; - if (x % 4 == 2 && y % 4 == 2) { - r = 255 - r; - g = 255 - g; - b = 255 - b; - } - sys_color color = (r >> 5) << 5 | (g >> 5) << 2 | (b >> 6); - sys_pixel_set(x, y, color); - } - } - - for (int i = 0; i < DEVICE_BUTTON_N; i++) { - sys_pixel_set(i, 0, device_buttons[i] ? 0x00 : 0xff); - } - - int x0 = ellipse_x0 / 4; - int y0 = ellipse_y0 / 4; - int x1 = ellipse_x1 / 4; - int y1 = ellipse_y1 / 4; - sys_oval_draw_ext(x0, y0, x1, y1, 10, true); - sys_oval_draw_ext(x0, y0, x1, y1, 248, false); - sys_circ_draw_ext(x0, y0, 4, 252, true); - sys_circ_draw_ext(x0, y0, 6, 248, false); - sys_circ_draw_ext(x0, y0, 8, 244, false); - sys_line_draw(x0, y0, x1, y1, 254); - - sys_print("Hello, blood\nsources!", x1, y1, 224); - sys_dpal_reset(); + sys_cls(9); + sys_map_draw(game_map, game_tiles, 0, 0, 0, 0, 32, 18); sys_sprite_draw_ext( - game_tiles, - 0, - x1, y1-64, - 16, 8, - true, true + game_player, + (game_frame / 8) % 4 * 2, 144, 88, 2, 2, + false, false ); - - sys_map_draw(game_map, game_tiles, 0, 0, map_x, 0, 32, 18); } diff --git a/game/game.h b/game/game.h index 9f223a0..04fff7b 100644 --- a/game/game.h +++ b/game/game.h @@ -1,6 +1,8 @@ #ifndef CROCPARTY_GAME_H #define CROCPARTY_GAME_H +#include "game_palette.h" + const char* game_title(); void game_init(); void game_destroy(); diff --git a/game/game_palette.c b/game/game_palette.c new file mode 100644 index 0000000..119da58 --- /dev/null +++ b/game/game_palette.c @@ -0,0 +1,21 @@ +#include "game_palette.h" + +void game_palette_init() { + // Pico 8 palette + sys_spal_set(0x00, 0x000000ff); + sys_spal_set(0x01, 0x1d2b53ff); + sys_spal_set(0x02, 0x7e2553ff); + sys_spal_set(0x03, 0x008751ff); + sys_spal_set(0x04, 0xab5236ff); + sys_spal_set(0x05, 0x5f574fff); + sys_spal_set(0x06, 0xc2c3c7ff); + sys_spal_set(0x07, 0xfff1e8ff); + sys_spal_set(0x08, 0xff004dff); + sys_spal_set(0x09, 0xffa300ff); + sys_spal_set(0x0a, 0xffec27ff); + sys_spal_set(0x0b, 0x00e436ff); + sys_spal_set(0x0c, 0x29adffff); + sys_spal_set(0x0d, 0x83769cff); + sys_spal_set(0x0e, 0xff77a8ff); + sys_spal_set(0x0f, 0xffccaaff); +} \ No newline at end of file diff --git a/game/game_palette.h b/game/game_palette.h new file mode 100644 index 0000000..040ef0c --- /dev/null +++ b/game/game_palette.h @@ -0,0 +1,6 @@ +#ifndef GAME_PALETTE_H +#define GAME_PALETTE_H + +void game_palette_init(); + +#endif // GAME_PALETTE_H \ No newline at end of file diff --git a/pytools/spritesheet.py b/pytools/spritesheet.py index 12dc1fa..5643b1f 100644 --- a/pytools/spritesheet.py +++ b/pytools/spritesheet.py @@ -25,7 +25,7 @@ sys_spritesheet {{spritesheet_name}} = { def main(spritesheet_name, n_sprites, key_color, fname_png, fname_c): sprites, width, height = load_sprites(fname_png, key_color) - assert(len(sprites) == n_sprites), f"must be exactly {n_sprites} sprites" + assert(len(sprites) == n_sprites), f"must be exactly {n_sprites} sprites, not {len(sprites)}" with open(fname_c, "wt") as output: output.write( diff --git a/sdl_host/main.c b/sdl_host/main.c index 63318cc..fc6bceb 100644 --- a/sdl_host/main.c +++ b/sdl_host/main.c @@ -95,7 +95,7 @@ void sdl_host_suggest_dimensions(uint32_t* window_w, uint32_t* window_h) { dm.h = 0; } - for (int scalar = 2; scalar >= 1; scalar--) { + for (int scalar = 4; scalar >= 1; scalar--) { uint32_t w = DEVICE_W * scalar; uint32_t h = DEVICE_H * scalar; if (w <= dm.w && h <= dm.h) {