git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/examples/cross-platform/multiplayer/src/multiplayer.c

      1 #include <gbdk/platform.h>
      2 
      3 #include <stdint.h>
      4 
      5 const uint8_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 
     12 joypads_t joypads;
     13 
     14 void main(void) {
     15     set_sprite_data(0, 4, sprite_data);
     16     for (uint8_t i = 0; i < 4; i++) {
     17         set_sprite_tile(i, i);
     18         move_sprite(i,
     19                     DEVICE_SPRITE_PX_OFFSET_X + (i << 3) + ((DEVICE_SCREEN_PX_WIDTH - (4 * 8)) / 2), 
     20                     DEVICE_SPRITE_PX_OFFSET_Y + ((DEVICE_SCREEN_PX_HEIGHT - 8) / 2));
     21     }
     22     SHOW_SPRITES;
     23 
     24     // Wait 4 frames
     25     // For SGB on PAL SNES this delay is required on startup, otherwise borders don't show up
     26     for (uint8_t i = 4; i != 0; i--) vsync();
     27 
     28     // init joypads
     29     joypad_init(4, &joypads);
     30     
     31     while(1) {
     32         // poll joypads
     33         joypad_ex(&joypads);
     34         // iterate joypads, move sprites
     35         for (uint8_t i = 0; i < joypads.npads; i++) {
     36             uint8_t joy = joypads.joypads[i];
     37             if (joy & J_LEFT) scroll_sprite(i, -1, 0);
     38             if (joy & J_RIGHT) scroll_sprite(i, 1, 0);
     39             if (joy & J_UP) scroll_sprite(i, 0, -1);
     40             if (joy & J_DOWN) scroll_sprite(i, 0, 1);
     41         }
     42         // start on joypad 1 resets position
     43         if (joypads.joy0 & J_START) {
     44             for (uint8_t i = 0; i < 4; i++) move_sprite(i, (i << 3) + 64, 64);
     45         }
     46         vsync();
     47     }
     48 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.