gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > help with key press

#39064 - ghost Leinad - Mon Apr 04, 2005 2:41 am

hi..im a young proggramer trying to make games...im from Mexico, i just started a week ago, i?m new at this and im makin' a frogger clon(very bizarre)... but i can't check for just one press...mi frog jumps down 20 pixels everytime and im one press jumps five or more times...how can i check the single press?
i heard something about button states but i can't change my button state and then return to the original without using another key...example...my frog jumps with the KEY_DOWN and my buttonstate become =1 to retunr the buttonstate to 0 i need to press the KEY_A...

ah another thing...how can i slow mi snake...(im also making(or trying to make) a snake clon) but this the problem...my snake sprite is a 8*8 and for example if I press the KEY_DOWN the snake goes down 1 pixel at time but i want to make the snake to move 8 pixels at time but when i do this my snake becomes very fast...how can i slow things down?


by the way..sorry about my english..im just learning... i hope you can first undertand me and then help me

thanks!

#39066 - tepples - Mon Apr 04, 2005 3:10 am

ghost Leinad wrote:
hi..im a young proggramer trying to make games...im from Mexico, i just started a week ago, i?m new at this and im makin' a frogger clone(very bizarre)... but i can't check for just one press...my frog jumps down 20 pixels everytime and in one press jumps five or more times...how can i check the single press?

Are you making sure to check for keypresses only once per vblank?

Quote:
but i can't change my button state and then return to the original without using another key...example...my frog jumps with the KEY_DOWN and my buttonstate become =1 to retunr the buttonstate to 0 i need to press the KEY_A...

That's not what was meant. Keep a key state for each button: for KEY_DOWN you'd store either "pressed" or "unpressed", and the frog would move only if last state was "unpressed" and current state is "pressed".

Quote:
how can i slow my snake...(im also making(or trying to make) a snake clone) but this the problem...my snake sprite is a 8*8 and for example if I press the KEY_DOWN the snake goes down 1 pixel at time but i want to make the snake to move 8 pixels at time but when i do this my snake becomes very fast...how can i slow things down?

Wait several vblanks before moving the snake. If you move the snake only once every six vblanks, it'll go six times slower than if you move the snake every vblank.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#39208 - ghost Leinad - Wed Apr 06, 2005 12:28 am

let me see if I get it...i need a key state for each button...example KEY_DOWN pressed =state0 and KEY_DOWN unpressed=1 if I try to press the KEY_DOWN while mi button state is 0...then nothing will happen right?

and the wait for VBLANK is already done..tanx....
but do you know a simple Delay function in GBA like in c (to make timers or something)

by the way the snake project is harder than i though jejeje...this is what i've done so far...
the snake head move in all directions
the 1 food is eadible
and the 1 food makes my snake grow larger

but the second food mess all things...

or i can get all the foods but no food makes my snake grow

tanx for your help