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 2016-06-17 03:49:16

urban07
New member
Registered: 2016-06-07
Posts: 2

GBDK input detection - how to detect 2 joypad() inputs at once?

Hi!
I'm kind of new to GBDK programming and I was wondering how to detect gameboy input, when I want to check if 2 buttons are pressed at once?
Let's say I want to do a platformer and be able to go right and jump at the same time - how to do it?

I made a simple program that prints joypad() output in a while(1) - it doesn't make much sense to human, but what I found out is that there are different outputs if you press just A, just B, and both at once.

I came up with something like this, but I'm not sure if it's the right way:

if(joypad() == J_RIGHT) {
  for(i=0; i<=5; i=i+1) {
    move_player_right();
    if(joypad() == J_A) {
      jump();
    }
    delay(20);
  }
}

I didn't really test it yet, it's just an idea.

Some help, please? smile

Offline

 

#2 2016-06-17 04:09:44

rychan
Member
From: Paignton, Devon, UK
Registered: 2015-12-16
Posts: 103
Website

Re: GBDK input detection - how to detect 2 joypad() inputs at once?

replace

joypad() ==

with

joypad() &

that should set you on your way wink

Offline

 

#3 2016-06-17 04:44:11

urban07
New member
Registered: 2016-06-07
Posts: 2

Re: GBDK input detection - how to detect 2 joypad() inputs at once?

Whoa!
Thanks, mate - I get it now big_smile

Btw. your games are pretty cool big_smile

Offline

 

#4 2016-06-17 08:28:04

rychan
Member
From: Paignton, Devon, UK
Registered: 2015-12-16
Posts: 103
Website

Re: GBDK input detection - how to detect 2 joypad() inputs at once?

Hey, thanks smile It's become a passion over the year I've been playing with it! Please post how you get along smile

Offline

 

#5 2016-06-20 19:30:11

caseyweederman
New member
Registered: 2016-06-03
Posts: 2

Re: GBDK input detection - how to detect 2 joypad() inputs at once?

Ooh, I just reached this point in sprite properties - a byte of flags. I guess joypad() returns eight bits, one for each button input? You might read 01000001 (invented example) as "right arrow and B button are held"?
I just realized how perfect it is that there are exactly eight inputs.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson