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.

Ads

#1 2023-08-11 23:37:14

MisterBull92
New member
Registered: 2023-08-11
Posts: 2

Newbie McNoobster here: Moving a box around the Gameboy Screen. Help!

so I've just got into the Gameboy development scene and I've managed to code a simple gb app moving a simple box around the screen via the d-pad. Hurrah, beautiful delicious progress!

Problems?
1. the box leaves a black trail behind it indicating that there is no clearing the buffer of previous pixels. What would be gbdk equivalent of a simple CLS function here?

2. How would I go about moving my box in diagonals? I've tried combining joypad() readouts like J_UP && J_LEFT to move the box up and left at a diagonal but I cant seem to make that sort of thing work

Keep in mind I am also new to C programing altogether. My previous coding experience is in Blitz Basic, Blitz3D, Blitz Max, QBasic (that one was a good while back), some javascript. I dont know if many of you here are familiar with any of those coding languages but there ya go smile

PS: I tried joining your discord channel but it keeps throwing me to my main Discord front page here in my browser. Does your discord actually exist? The IRC chanel looks empty tongue

edit: here's my code so far:

Code:

#include <gb/gb.h>
#include <gbdk/console.h>
#include <gb/drawing.h>

#include <stdint.h>
#include <stdio.h>
#include <string.h>

int playerX=32, playerY=32;
int joyGet;

int main(void){    
    
    SHOW_BKG;
    SHOW_SPRITES;    
    DISPLAY_ON;
    
    while(1) {
        
        joyGet = joypad();
            
            if ( joyGet == J_UP    ){playerY--;}
            if ( joyGet == J_DOWN  ){playerY++;}
            if ( joyGet == J_LEFT  ){playerX--;}
            if ( joyGet == J_RIGHT ){playerX++;}
            
        box(playerX,playerY,playerX+8,playerY+8,1);
        delay(20);
        
        gprintf("playerX: %d",playerX); gotogxy(0,0);
        gprintf("playerY: %d",playerY); gotogxy(0,1);
        
        vsync();
    }
}

Last edited by MisterBull92 (2023-08-11 23:43:38)

Offline

 

#2 2023-08-25 03:31:05

bbbbbr
Member
Registered: 2019-03-04
Posts: 127

Re: Newbie McNoobster here: Moving a box around the Gameboy Screen. Help!

&& is logical AND, & is bitwise AND

To test just one button from the joypad input, do a bit test which masks out all other button bits such as  (joyGet & J_UP) instead of  (joyGet == J_UP). That way if multiple buttons are pressed the individual bit tests will still work, whereas the == test only works if just one single button is pressed and all others are released..

It will be easier to develop using sprites and/or background tiles/maps for graphics instead of APA graphics mode which is rather slow. There are some examples in the gbdk-2020 install,along with some tutorial links in the manual.

Not sure which discord link you are trying, but you can find them here:
gbdev: https://gbdev.io/chat.html
gbdk: https://github.com/gbdk-2020/gbdk-2020#discord-servers

Last edited by bbbbbr (2023-08-25 03:31:44)

Offline

 

#3 2023-08-26 20:35:08

MisterBull92
New member
Registered: 2023-08-11
Posts: 2

Re: Newbie McNoobster here: Moving a box around the Gameboy Screen. Help!

bbbbbr wrote:

&& is logical AND, & is bitwise AND

To test just one button from the joypad input, do a bit test which masks out all other button bits such as  (joyGet & J_UP) instead of  (joyGet == J_UP). That way if multiple buttons are pressed the individual bit tests will still work, whereas the == test only works if just one single button is pressed and all others are released..

It will be easier to develop using sprites and/or background tiles/maps for graphics instead of APA graphics mode which is rather slow. There are some examples in the gbdk-2020 install,along with some tutorial links in the manual.

Not sure which discord link you are trying, but you can find them here:
gbdev: https://gbdev.io/chat.html
gbdk: https://github.com/gbdk-2020/gbdk-2020#discord-servers

Thanks for the post, yeah I've figured out the graphics mode was awful for a number of reasons. I've since "graduated" to using sprites and background data. Thanks for explaining the & / && / == stuff though, that's a new lesson for me to digest and use in my current project!

the discord links you sent me do work, I think the ones I followed before were old links posted somewhere on this forum. The guys on the discord have been some good help tonight with understanding some code.

Again, thanks! big_smile

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson