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.

Coding > trouble with timers

#17778 - Darmstadium - Sun Mar 14, 2004 6:26 pm

I'm making a very simple game called konect four, a rip of that game connect four. For those of you who don't know what it is, it's a game where you have a board standing up vertically. It has 7 holes across the top where you can drop pieces down. Now in my game, to select what column the user wants their piece to go in, I have an arrow that they can move across the top of the board. The arrow works like this: there is a variable that keeps track of over what column the arrow is. Then there is a function that takes that info and actually moves the arrow sprite to where it should be on the screen. Every time the user presses left or right, the variable that keeps track of the arrow's position is incremented or decremented. The problem is that the arrow moves impossibly fast and you can't get it over the column you want. I tried using a timer to stop my game from taking further input until the timer gets full, but the timer doesn't seem to be working because the arrow still scrolls at insane speeds, though it does pause for 1 sec every once in a while. I would really really appreciate any help anybody could give me.

#17780 - poslundc - Sun Mar 14, 2004 6:51 pm

Don't use timers. Instead, either don't accept another button press until the button has been released, or in the case of keypad movement use a variable to track how many frames have passed and only move the arrow after a sizeable delay has passed. (Use an even longer delay when the key is initially pressed before you start repeating for an effect similar to when you hold down a key on a computer keyboard.)

Read this thread - especially the stuff about finite state machines - for information on how to construct your control loop.

Dan.

#17781 - DekuTree64 - Sun Mar 14, 2004 6:53 pm

Sounds like you're just checking the keypad register and incrementing the pos if the keys are down. That means you'll move once per frame while the key is down, or 60 spaces/second. Chech the key pressing threads that have been going on lately for info on how to do a good input system. I think one was in hardware and the other was in beginners or something.

EDIT: Dan beat me to it, and was more informative as well. Ignore this post then.

#17783 - Lupin - Sun Mar 14, 2004 6:57 pm

i think the threads didn't really come up with a usefull result...

I am using a timer that i set to freq 64 and just check for key down, i wonder if i waste processing power by checking so often. I would use interrupts if i would know how to let my interrupt fire on button up event...

edit: woot, this is my 2^8th post!

#17787 - poslundc - Sun Mar 14, 2004 7:10 pm

Lupin wrote:
i think the threads didn't really come up with a usefull result...


Then you should read them again, because...

Quote:
I am using a timer that i set to freq 64 and just check for key down, i wonder if i waste processing power by checking so often. I would use interrupts if i would know how to let my interrupt fire on button up event...


... this is an extremely wasteful and overcomplicated way to handle user input.

Dan.

#17791 - Lupin - Sun Mar 14, 2004 7:43 pm

well, i took a look at the threads and all the code shown there is put in the mainloop of my game, but because of my game running at different speeds depending on the scene complexity the input may go wrong (eg. moving too fast at high fps and too slow on low fps)
_________________
Team Pokeme
My blog and PM ASM tutorials

#17792 - Darmstadium - Sun Mar 14, 2004 7:59 pm

Thanks a lot you guys! I'm not sure that I entirely understand the concept of finate state machines but I got my arrow to work how I want it. Again, thank you all!