crocparty/game/game.c

112 lines
2.8 KiB
C
Raw Normal View History

#include "art/game_demo_sprites.h"
2024-02-26 00:40:33 +00:00
#include "device/device.h"
2024-02-27 04:19:22 +00:00
#include "map/game_map.h"
2024-02-25 03:00:23 +00:00
#include "game.h"
#include "sys/sys.h"
2024-02-25 03:00:23 +00:00
uint32_t game_frame;
2024-02-26 06:23:43 +00:00
int32_t ellipse_x0 = 32 * 4;
int32_t ellipse_y0 = 32 * 4;
2024-02-26 06:10:21 +00:00
int32_t ellipse_dx0 = 1;
int32_t ellipse_dy0 = 2;
2024-02-26 06:23:43 +00:00
int32_t ellipse_x1 = 96 * 4;
int32_t ellipse_y1 = 96 * 4;
2024-02-26 06:10:21 +00:00
int32_t ellipse_dx1 = 3;
int32_t ellipse_dy1 = 4;
2024-02-27 04:19:22 +00:00
int32_t map_x = 0;
2024-02-26 06:10:21 +00:00
const char* game_title() {
return "Croc Party!";
}
2024-02-25 03:00:23 +00:00
void game_init() {
sys_init();
2024-02-25 03:00:23 +00:00
game_frame = 0;
2024-02-26 01:54:57 +00:00
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),
2024-02-26 01:54:57 +00:00
((x * 255)/7) << 24 |
((y * 255)/7) << 16 |
((z * 255)/3) << 8
);
2024-02-26 01:54:57 +00:00
}
}
}
sys_spal_set(0xfe, 0xffffffff);
}
void game_destroy() {
sys_destroy();
2024-02-25 03:00:23 +00:00
}
void game_update() {
2024-02-26 01:54:57 +00:00
game_frame += 4;
2024-02-26 06:10:21 +00:00
2024-02-27 04:19:22 +00:00
map_x += 1;
map_x %= 160;
2024-02-26 06:10:21 +00:00
ellipse_x0 += ellipse_dx0;
2024-02-26 06:23:43 +00:00
if (ellipse_x0 < 0 || ellipse_x0 > DEVICE_W * 4) { ellipse_dx0 *= -1; }
2024-02-26 06:10:21 +00:00
ellipse_y0 += ellipse_dy0;
2024-02-26 20:42:07 +00:00
if (ellipse_y0 < 0 || ellipse_y0 > DEVICE_H * 4) { ellipse_dy0 *= -1; }
2024-02-26 06:10:21 +00:00
ellipse_x1 += ellipse_dx1;
2024-02-26 20:42:07 +00:00
if (ellipse_x1 < 0 || ellipse_x1 > DEVICE_W * 4) { ellipse_dx1 *= -1; }
2024-02-26 06:10:21 +00:00
ellipse_y1 += ellipse_dy1;
2024-02-26 06:23:43 +00:00
if (ellipse_y1 < 0 || ellipse_y1 > DEVICE_H * 4) { ellipse_dy1 *= -1; }
2024-02-25 03:00:23 +00:00
}
void game_draw() {
sys_dpal_set(0xff, 0xfe); // map to a non-transparent color
2024-02-25 03:00:23 +00:00
for (int x = 0; x < DEVICE_W; x++) {
for (int y = 0; y < DEVICE_H; y++) {
2024-02-26 01:54:57 +00:00
uint32_t r = (x * 255)/(DEVICE_W - 1);
uint32_t g = (y * 255)/(DEVICE_H - 1);
2024-02-25 05:04:20 +00:00
uint32_t b = game_frame & 0x100 ? 0xff - game_frame & 0xff : game_frame & 0xff;
2024-02-25 03:00:23 +00:00
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);
2024-02-25 03:00:23 +00:00
}
}
2024-02-26 00:25:34 +00:00
for (int i = 0; i < DEVICE_BUTTON_N; i++) {
sys_pixel_set(i, 0, device_buttons[i] ? 0x00 : 0xff);
2024-02-26 00:25:34 +00:00
}
2024-02-26 06:10:21 +00:00
2024-02-26 06:23:43 +00:00
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);
2024-02-26 20:42:07 +00:00
sys_print("Hello, blood\nsources!", x1, y1, 224);
sys_dpal_reset();
sys_sprite_draw_ext(
game_demo_sprites,
0,
x1, y1-64,
16, 8,
false, false
);
2024-02-27 04:19:22 +00:00
sys_map_draw(game_map, game_demo_sprites, 0, 0, map_x, 8, 32, 18);
2024-02-25 03:00:23 +00:00
}