Support significant parts of pico 8 graphics

This commit is contained in:
2024-02-25 18:38:53 -08:00
parent 95c03d25d5
commit 30e4d544fd
11 changed files with 225 additions and 15 deletions

View File

@ -3,5 +3,5 @@ cc_library(
srcs = glob(["*.c"]),
hdrs = glob(["*.h"]),
visibility = ["//visibility:public"],
deps = ["//device:device"]
deps = ["//device:device", "//sys:sys"]
)

View File

@ -1,23 +1,36 @@
#include "device/device.h"
#include "game.h"
#include "sys/sys.h"
uint32_t game_frame;
const char* game_title() {
return "Croc Party!";
}
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++) {
device_palette[
(x << 5)|(y << 2)|(z)
] =
sys_spal_set(
(x << 5)|(y << 2)|(z),
((x * 255)/7) << 24 |
((y * 255)/7) << 16 |
((z * 255)/3) << 8;
((z * 255)/3) << 8
);
}
}
}
sys_spal_set(0xfe, 0xffffffff);
}
void game_destroy() {
sys_destroy();
}
void game_update() {
@ -25,6 +38,8 @@ void game_update() {
}
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);
@ -35,12 +50,12 @@ void game_draw() {
g = 255 - g;
b = 255 - b;
}
uint8_t color = (r >> 5) << 5 | (g >> 5) << 2 | (b >> 6);
device_pixels[y][x] = color;
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++) {
device_pixels[0][i] = device_buttons[i] ? 0x00 : 0xff;
sys_pixel_set(i, 0, device_buttons[i] ? 0x00 : 0xff);
}
}

View File

@ -1,7 +1,10 @@
#ifndef CROCPARTY_GAME_H
#define CROCPARTY_GAME_H
const char* game_title();
void game_init();
void game_destroy();
void game_update();
void game_draw();