sgb_multiplayer.c (1552B)
1#include <gb/gb.h> 2#include <stdint.h> 3#include <gb/sgb.h> 4 5uint8_t sprite_data[] = { 6 0x3C,0x3C,0x42,0x7E,0x99,0xFF,0xA9,0xFF,0x89,0xFF,0x89,0xFF,0x42,0x7E,0x3C,0x3C, 7 0x3C,0x3C,0x42,0x7E,0xB9,0xFF,0x89,0xFF,0x91,0xFF,0xB9,0xFF,0x42,0x7E,0x3C,0x3C, 8 0x3C,0x3C,0x42,0x7E,0x99,0xFF,0x89,0xFF,0x99,0xFF,0x89,0xFF,0x5A,0x7E,0x3C,0x3C, 9 0x3C,0x3C,0x42,0x7E,0xA9,0xFF,0xA9,0xFF,0xB9,0xFF,0x89,0xFF,0x42,0x7E,0x3C,0x3C 10}; 11 12joypads_t joypads; 13 14void main(void) { 15 BGP_REG = OBP0_REG = OBP1_REG = 0xE4; 16 set_sprite_data(0, 4, sprite_data); 17 for (uint8_t i = 0; i < 4; i++) { 18 set_sprite_tile(i, i); 19 move_sprite(i, (i << 3) + 64, 64); 20 } 21 SHOW_SPRITES; 22 23 // Wait 4 frames 24 // For SGB on PAL SNES this delay is required on startup, otherwise borders don't show up 25 for (uint8_t i = 4; i != 0; i--) wait_vbl_done(); 26 27 // init joypads 28 joypad_init(4, &joypads); 29 30 while(1) { 31 // poll joypads 32 joypad_ex(&joypads); 33 // iterate joypads, move sprites 34 for (uint8_t i = 0; i < joypads.npads; i++) { 35 uint8_t joy = joypads.joypads[i]; 36 if (joy & J_LEFT) scroll_sprite(i, -1, 0); 37 if (joy & J_RIGHT) scroll_sprite(i, 1, 0); 38 if (joy & J_UP) scroll_sprite(i, 0, -1); 39 if (joy & J_DOWN) scroll_sprite(i, 0, 1); 40 } 41 // start on joypad 1 resets position 42 if (joypads.joy0 & J_START) { 43 for (uint8_t i = 0; i < 4; i++) move_sprite(i, (i << 3) + 64, 64); 44 } 45 wait_vbl_done(); 46 } 47}