96 lines
2.8 KiB
C
96 lines
2.8 KiB
C
#include <tonc.h>
|
|
#include "gbfs.h"
|
|
|
|
OBJ_ATTR obj_buffer[128];
|
|
OBJ_AFFINE *obj_aff_buffer= (OBJ_AFFINE*)obj_buffer;
|
|
|
|
typedef struct {
|
|
OBJ_ATTR *obj;
|
|
u32 tid, pb;
|
|
int x, y, x_prev, y_prev;
|
|
} sprite_reg;
|
|
|
|
int main (void)
|
|
{
|
|
// Find the beginning of the GBFS 'sector'
|
|
const GBFS_FILE *gbfs_start = find_first_gbfs_file(find_first_gbfs_file);
|
|
|
|
// LZ77 decompress needed GBFS files to VRAM
|
|
LZ77UnCompVram((u32*) gbfs_get_obj(gbfs_start, "hub.pal.bin", NULL), &pal_bg_mem[0]);
|
|
LZ77UnCompVram((u32*) gbfs_get_obj(gbfs_start, "hub.img.bin", NULL), &tile_mem[0][0]);
|
|
LZ77UnCompVram((u32*) gbfs_get_obj(gbfs_start, "hub.map.bin", NULL), &se_mem[30][0]);
|
|
|
|
LZ77UnCompVram((u32*) gbfs_get_obj(gbfs_start, "schnoz.pal.bin", NULL), pal_obj_mem);
|
|
LZ77UnCompVram((u32*) gbfs_get_obj(gbfs_start, "schnoz_f1.img.bin", NULL), &tile_mem[4][0]);
|
|
LZ77UnCompVram((u32*) gbfs_get_obj(gbfs_start, "schnoz_f2.img.bin", NULL), &tile_mem[4][8]);
|
|
|
|
oam_init(obj_buffer, 128);
|
|
sprite_reg player = {&obj_buffer[0], 0, 0, 5, 80};
|
|
obj_set_attr(
|
|
player.obj,
|
|
ATTR0_TALL,
|
|
ATTR1_SIZE_32 | ATTR1_HFLIP,
|
|
ATTR2_PALBANK(player.pb) | player.tid
|
|
);
|
|
obj_set_pos(player.obj, player.x, player.y);
|
|
|
|
oam_copy(oam_mem, obj_buffer, 1);
|
|
|
|
BG_POINT bg1_pos = {0, 96};
|
|
|
|
// Use background 1 to leave background 0 free for sprites to move behind
|
|
REG_BG1CNT= BG_CBB(0) | BG_SBB(30) | BG_4BPP | BG_REG_64x32;
|
|
REG_DISPCNT = DCNT_BG1 | DCNT_OBJ | DCNT_OBJ_1D;
|
|
|
|
u32 fcounter = 0;
|
|
while (1) {
|
|
vid_vsync();
|
|
key_poll();
|
|
++fcounter;
|
|
|
|
player.x_prev = player.x;
|
|
player.y_prev = player.y;
|
|
player.x += key_tri_horz();
|
|
player.y += key_tri_vert();
|
|
|
|
if ((key_tri_horz() || key_tri_vert()) && !(fcounter % 16)) {
|
|
player.tid ^= 8;
|
|
} else if (!(key_tri_horz() || key_tri_vert())) {
|
|
player.tid = 0;
|
|
}
|
|
|
|
if (key_tri_horz() > 0) {
|
|
player.obj->attr1 |= ATTR1_HFLIP;
|
|
} else if (key_tri_horz() < 0) {
|
|
player.obj->attr1 &= ~ATTR1_HFLIP;
|
|
}
|
|
|
|
if ((player.x >= 3*(SCREEN_WIDTH/4)-15) && (bg1_pos.x < 512-SCREEN_WIDTH)) {
|
|
++bg1_pos.x;
|
|
player.x = clamp(player.x, 0, 3*(SCREEN_WIDTH/4)-15);
|
|
} else if ((player.x <= (SCREEN_WIDTH/4)-15) && (bg1_pos.x > 0)) {
|
|
--bg1_pos.x;
|
|
player.x = clamp(player.x, (SCREEN_WIDTH/4)-15, SCREEN_WIDTH-15);
|
|
}
|
|
|
|
if ((player.y >= 3*(SCREEN_HEIGHT/4)-31) && (bg1_pos.y < 256-SCREEN_HEIGHT)) {
|
|
++bg1_pos.y;
|
|
player.y = clamp(player.y, 0, 3*(SCREEN_HEIGHT/4)-31);
|
|
} else if ((player.y <= (SCREEN_HEIGHT/4)-31) && (bg1_pos.y > 0)) {
|
|
--bg1_pos.y;
|
|
player.y = clamp(player.y, (SCREEN_HEIGHT/4)-31, SCREEN_HEIGHT-31);
|
|
}
|
|
|
|
player.x = clamp(player.x, 0, SCREEN_WIDTH-15);
|
|
player.y = clamp(player.y, -9, SCREEN_HEIGHT-31);
|
|
|
|
obj_set_pos(player.obj, player.x, player.y);
|
|
player.obj->attr2 = ATTR2_BUILD(player.tid, player.pb, 0);
|
|
oam_copy(oam_mem, obj_buffer, 1);
|
|
|
|
REG_BG1HOFS = bg1_pos.x;
|
|
REG_BG1VOFS = bg1_pos.y;
|
|
}
|
|
}
|
|
|