cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

sgb_multiplayer.c (1382B)


      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    // init joypads
     24    joypad_init(4, &joypads);
     25    
     26    while(1) {
     27        // poll joypads
     28        joypad_ex(&joypads);
     29        // iterate joypads, move sprites
     30        for (uint8_t i = 0; i < joypads.npads; i++) {
     31            uint8_t joy = joypads.joypads[i];
     32            if (joy & J_LEFT) scroll_sprite(i, -1, 0);
     33            if (joy & J_RIGHT) scroll_sprite(i, 1, 0);
     34            if (joy & J_UP) scroll_sprite(i, 0, -1);
     35            if (joy & J_DOWN) scroll_sprite(i, 0, 1);
     36        }
     37        // start on joypad 1 resets position
     38        if (joypads.joy0 & J_START) {
     39            for (uint8_t i = 0; i < 4; i++) move_sprite(i, (i << 3) + 64, 64);
     40        }
     41        wait_vbl_done();
     42    }
     43}