Gameboy Development Forum

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.

#1 2022-07-09 19:40:07

MadCornDog
New member
Registered: 2022-07-09
Posts: 2

Help with GBDK code!

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.

Code:

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

 

#2 2022-07-10 03:02:51

0x7f
Member
Registered: 2019-11-24
Posts: 65

Re: Help with GBDK code!

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

 

#3 2022-07-10 07:21:11

toxa
Member
Registered: 2020-02-13
Posts: 309

Re: Help with GBDK code!

what does joypad(J_RIGHT) do?

Offline

 

#4 2022-07-12 07:36:19

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: Help with GBDK code!

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)


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson