Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
Hi. I'm making a small game where you are a character and you move around the screen with the up down left and right keys so I wrote my code like this to make him move but he won't move.
void main() { UINT8 xvel = 0; UINT8 yvel = 0; UINT8 playerSpd = 1; set_sprite_data(0,4,player); set_sprite_tile(0,0); move_sprite(0, 88, 78); SHOW_SPRITES; while(1){ xvel = (joypad(J_RIGHT) - joypad(J_LEFT)) * playerSpd; yvel = (joypad(J_DOWN) - joypad(J_UP)) * playerSpd; scroll_sprite(0,xvel,yvel); xvel = 0; yvel = 0; } }
I've used similar code in other languages and other game engines before and it has worked fine. How come it's not working here in C?
Last edited by MadCornDog (2022-07-09 19:45:45)
Offline
Hi,
try to declare xvel and yvel as signed variables. In addition its no good idea to use multiplications when they are not necessary.
You should read the GBDK manual: https://gbdk-2020.github.io/gbdk-2020/d … manual.pdf
Offline
what does joypad(J_RIGHT) do?
Offline
Another problem is you're not moving the sprite with move_sprite.
You just set it at move_sprite(0, 88, 78);
And why not just use if (key(J_RIGHT) playerx++;
and then set move_sprite to move_sprite(0, playerx, playery); ?
Youd also need to declare key as a UBYTE.
Last edited by chris (2022-07-12 07:37:20)
Offline