TNT Basic Forums > Programming Q&A
Tap key?
< Last Thread     Next Thread >
Thread        Post A Reply

02-01-2006 19:13

Posted by:

Lund, Sweden

Click Here to Email Gustav   Find more posts by Gustav

Hello guys! First I just want to say that TNTBasic is wonderful! And then I have a question about "pressed(?)". I want to write a "Frog Xing" kind of game, and lets say that the player sprite is 20 by 20 pixels.
And then we press the up-key and that makes the player sprite move 20+ pixles forward once.
I don't know how to do that, If I would try to write that my frog would disappear or move slowly.
This would not work:

if up then PlayerY = PlayerY - 20
draw frame
until Something()

I want to make it so that if you hold the up key, you will still only move one step. (until you press up again)
And DONT even mention setting the framerate to 1.
I like 70 fps. =P

02-01-2006 21:15

Posted by:

San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob


int pressedUp=false

if not up then pressedUp=false
if up and not pressedUp : playerY=playerY-20 : pressedUp=true : end if

until something()

That should work, otherwise you could use the <i>Keyboard Raw Key</i> command.

02-01-2006 21:26

Posted by:

hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Not a problem.

The basic idea is that you need to set a flag when the button is pressed, say ' int upButton=true' for example. You'd have something like:

if upButton=false '
up not pressed last time round...

if up '
but it is now...
upButton=true '
so set the flag and make the move.
end if

else '
upButton=true, so up was pressed last time round...

upButton=up '
so we only need to check and see if it's been released!

end if

That's kind of it. The reason you don't use 'while up doNothing() end while' is that everything else would grind to a halt as well, unless you use MOAN of course.
Hope this helps...

Danny (nods)

02-02-2006 21:11

Posted by:
Mark Tully

TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Also, as Jacob mentioned, the 'Keyboard Raw Key' command is a good way of reading one of keypresses which you can ensure don't repeat by calling 'Keyboard Repeat Off'. Using this is probably easiest to start with, but the 'pressed' method can be more flexible as you can exactly control how you handle key repeating.


All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.