It is recommended to read the previous articles to better understand this one:
In this article, we will reuse the sprite from the previous article but we will move it around the screen using the movement arrows.
vi 02.c
#include <gb/gb.h>
#include <stdio.h>
#include "Carita.c"
void main(){
set_sprite_data(0, 2, Carita);
set_sprite_tile(0, 0);
move_sprite(0, 88, 78);
SHOW_SPRITES;
while(1){
switch(joypad()){
case J_LEFT:
scroll_sprite(0,-2,0);
break;
case J_RIGHT:
scroll_sprite(0,2,0);
break;
case J_UP:
scroll_sprite(0,0,-2);
break;
case J_DOWN:
scroll_sprite(0,0,2);
break;
}
delay(100);
}
}
We compile the game and load it into the emulator:
~/GBDEV/gbdk/bin/lcc 02.c -o 02.gb