Get the croc into the engine

This commit is contained in:
Pyrex 2024-02-27 15:57:37 -08:00
parent 57e025e6aa
commit 08f279e340
10 changed files with 67 additions and 108 deletions

View File

@ -2,12 +2,30 @@ load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
cc_library( cc_library(
name = "game", name = "game",
srcs = glob(["*.c"]) + [":art/game_tiles.c", ":map/game_map.c"], srcs = glob(["*.c"]) + [
hdrs = glob(["*.h"]) + [":art/game_tiles.h", ":map/game_map.h"], "art/game_player.c",
"art/game_tiles.c",
"map/game_map.c",
],
hdrs = glob(["*.h", "art/*.h", "map/*.h"]),
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = ["//device:device", "//sys:sys"] 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( run_binary(
name = "game_tiles", name = "game_tiles",
args = [ args = [

Binary file not shown.

8
game/art/game_player.h Normal file
View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 380 B

After

Width:  |  Height:  |  Size: 372 B

View File

@ -1,3 +1,4 @@
#include "art/game_player.h"
#include "art/game_tiles.h" #include "art/game_tiles.h"
#include "device/device.h" #include "device/device.h"
#include "map/game_map.h" #include "map/game_map.h"
@ -6,17 +7,6 @@
uint32_t game_frame; 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() { const char* game_title() {
return "Croc Party!"; return "Croc Party!";
} }
@ -24,40 +14,7 @@ const char* game_title() {
void game_init() { void game_init() {
sys_init(); sys_init();
game_frame = 0; game_palette_init();
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);
} }
void game_destroy() { void game_destroy() {
@ -65,69 +22,16 @@ void game_destroy() {
} }
void game_update() { void game_update() {
game_frame += 4; game_frame += 1;
/*
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; }
} }
void game_draw() { void game_draw() {
sys_dpal_set(0xff, 0xfe); // map to a non-transparent color sys_cls(9);
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_map_draw(game_map, game_tiles, 0, 0, 0, 0, 32, 18);
sys_sprite_draw_ext( sys_sprite_draw_ext(
game_tiles, game_player,
0, (game_frame / 8) % 4 * 2, 144, 88, 2, 2,
x1, y1-64, false, false
16, 8,
true, true
); );
sys_map_draw(game_map, game_tiles, 0, 0, map_x, 0, 32, 18);
} }

View File

@ -1,6 +1,8 @@
#ifndef CROCPARTY_GAME_H #ifndef CROCPARTY_GAME_H
#define CROCPARTY_GAME_H #define CROCPARTY_GAME_H
#include "game_palette.h"
const char* game_title(); const char* game_title();
void game_init(); void game_init();
void game_destroy(); void game_destroy();

21
game/game_palette.c Normal file
View File

@ -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);
}

6
game/game_palette.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef GAME_PALETTE_H
#define GAME_PALETTE_H
void game_palette_init();
#endif // GAME_PALETTE_H

View File

@ -25,7 +25,7 @@ sys_spritesheet {{spritesheet_name}} = {
def main(spritesheet_name, n_sprites, key_color, fname_png, fname_c): def main(spritesheet_name, n_sprites, key_color, fname_png, fname_c):
sprites, width, height = load_sprites(fname_png, key_color) 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: with open(fname_c, "wt") as output:
output.write( output.write(

View File

@ -95,7 +95,7 @@ void sdl_host_suggest_dimensions(uint32_t* window_w, uint32_t* window_h) {
dm.h = 0; 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 w = DEVICE_W * scalar;
uint32_t h = DEVICE_H * scalar; uint32_t h = DEVICE_H * scalar;
if (w <= dm.w && h <= dm.h) { if (w <= dm.w && h <= dm.h) {