game/src/main.c

68 lines
1.8 KiB
C

/* main.c
* Initialization and game loop
*
* For license details see COPYING.
*/
#include <tonc.h>
#include "gbfs.h"
#include "globals.h" // Data types, miscellaneous structures
#include "load.h" // Load from rom/gbfs into memory
#include "controls.h" // Manage input & controls
OBJ_ATTR obj_buffer[128];
OBJ_AFFINE *obj_aff_buffer = (OBJ_AFFINE*)obj_buffer;
uint frame_counter = 0;
int obj_counter = 0;
// Make sure gbfs_start is a global even though it can't be initialized here
const GBFS_FILE *gbfs_start;
int main (void)
{
// Find the beginning of the GBFS 'sector'
gbfs_start = find_first_gbfs_file(find_first_gbfs_file);
// Load hub into palbank 0, charblock 0, and screenblock 30
load_hub(&pal_bg_mem[0], &tile_mem[0][0], &se_mem[30][0]);
// Load schnoz into tile_mem[4][0] and tile_mem[4][8]
// Length of "schnoz" is 7, and 2 frames pointed to by remaining arguments
load_sprite("schnoz", 7, 2, &tile_mem[4][0], &tile_mem[4][8]);
oam_init(obj_buffer, 128);
// not required to initialize player.x_prev and player.y_prev yet
struct spriteReg player = {&obj_buffer[0], 0, 0, 5, 80};
++obj_counter;
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;
while (1) {
vid_vsync();
++frame_counter;
key_poll();
player_update(&player, SCHNOZ_BSE, SCHNOZ_TGL);
player_scroll(&player, &bg1_pos);
oam_copy(oam_mem, obj_buffer, obj_counter);
REG_BG1HOFS = bg1_pos.x;
REG_BG1VOFS = bg1_pos.y;
}
return; // in case?
}