Author |
Message |
RsX
|
Posted: Sat Apr 01, 2006 7:21 pm Post subject: Ignoring input? |
|
|
I made a pong game for school.
I have a problem that when the game ends, you naturally end up with your finger still on the key. The program stores the input and then it gets used when the program goes back to the main menu, causing chaos
Is there any command I can use to get the program to ignore keyboard inputs between certain points? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
do_pete
![](http://i38.photobucket.com/albums/e112/do_pete/1943.gif)
|
Posted: Sat Apr 01, 2006 7:29 pm Post subject: (No subject) |
|
|
You could stick a delay in to let the user take his fingers of the buttons |
|
|
|
|
![](images/spacer.gif) |
TokenHerbz
![](http://compsci.ca/v3/uploads/user_avatars/717170395558e628d9452b.jpg)
|
Posted: Sat Apr 01, 2006 7:29 pm Post subject: (No subject) |
|
|
Are you using keydown? or getch..
Try adding a "Input.Pause" or perhaps a delay for a second... |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Sat Apr 01, 2006 7:33 pm Post subject: (No subject) |
|
|
if you're using getch, you could flash the buffer by reading all of it.
code: |
loop
exit when hasch = false
getch(c)
end loop
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
do_pete
![](http://i38.photobucket.com/albums/e112/do_pete/1943.gif)
|
Posted: Sat Apr 01, 2006 7:34 pm Post subject: (No subject) |
|
|
Input.Pause wouldn't work because it would only pause until the user presses something |
|
|
|
|
![](images/spacer.gif) |
RsX
|
Posted: Sat Apr 01, 2006 7:43 pm Post subject: (No subject) |
|
|
The thing is, I tried delaying, but even that doesnt pause the input. I tried adding a delay of 2 seconds after the game is over, but then the user still has his finger on s for like 20 miliseconds. |
|
|
|
|
![](images/spacer.gif) |
RsX
|
Posted: Sat Apr 01, 2006 7:45 pm Post subject: (No subject) |
|
|
this is the users code:
code: |
if multi="y" then % multi if
if hasch then
getch (multimove)
if multimove="w" then
if P2Pad + 50 <= 380 then
P2Pad := P2Pad + 30
end if
elsif multimove="s" then
if P2Pad >= 20 then
P2Pad := P2Pad - 30
end if
end if
end if
else % multi if
|
Theres an option to either play 2 players or 1 against the computer, hence the if multi
[/code] |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Sat Apr 01, 2006 7:52 pm Post subject: (No subject) |
|
|
Tony has already posted the answer, it should be good enough for you to create some working code. If you have a more specific question, ask it, but try to solve the problem on your own first. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TokenHerbz
![](http://compsci.ca/v3/uploads/user_avatars/717170395558e628d9452b.jpg)
|
Posted: Sat Apr 01, 2006 7:56 pm Post subject: (No subject) |
|
|
you should have a nice code, what i mean is like...
code: |
for i: 1 .. 20
if i < 10 then
put "AHA"
else
put "FOO"
end if
end for
|
and i don't get the resons you posted that bit... |
|
|
|
|
![](images/spacer.gif) |
RsX
|
Posted: Sat Apr 01, 2006 8:17 pm Post subject: (No subject) |
|
|
I updated it to what you suggested but it still doesnt work:
code: | if multi="y" then % multi if
if hasch then
loop
exit when hasch = false
getch (multimove)
end loop
if multimove="w" then
if P2Pad + 50 <= 380 then
P2Pad := P2Pad + 30
end if
elsif multimove="s" then
if P2Pad >= 20 then
P2Pad := P2Pad - 30
end if
end if
end if
else % multi if |
Ill tell you how it works... The whole program, including the getch, is within a loop... Once the game is over, you exit the loop and enter the loop that was wrapping the games loop. Then it asks if you want to play again, so automatically you dont even see that message because your finger was still pressing the key as you exited the loop. Plus, you would most likely enter a sub-menu which forces you to retype all the settings. |
|
|
|
|
![](images/spacer.gif) |
RsX
|
Posted: Sat Apr 01, 2006 8:19 pm Post subject: (No subject) |
|
|
Thats why I need an input pauser, to pause inputting in the parent loop (the one wrapping the games loop).
P.S. isnt there a way to edit posts lol |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
RsX
|
Posted: Sat Apr 01, 2006 8:39 pm Post subject: (No subject) |
|
|
Great!
That helped Thanks!
If I can ask one more question regarding the code above...
How would I make it move smother?
Using the keys W and S the 2nd player is supposed to move his pong up and down, but it doesnt move smoothly at all... Once the user presses he has to wait about 1 second before seeing a movement, and it cuts off a lot. Is there any way to fix that? |
|
|
|
|
![](images/spacer.gif) |
RsX
|
Posted: Sat Apr 01, 2006 8:40 pm Post subject: (No subject) |
|
|
This is the code that needs re-writing (sorry about the double posting)
code: |
% Opponent
if multi="y" then % multi if
if hasch then
loop
exit when hasch = false
getch (multimove)
end loop
if multimove="w" then
if P2Pad + 50 <= 380 then
P2Pad := P2Pad + 30
end if
elsif multimove="s" then
if P2Pad >= 20 then
P2Pad := P2Pad - 30
end if
end if
end if
else % multi if
|
|
|
|
|
|
![](images/spacer.gif) |
do_pete
![](http://i38.photobucket.com/albums/e112/do_pete/1943.gif)
|
Posted: Sat Apr 01, 2006 8:51 pm Post subject: (No subject) |
|
|
Look up how to use View.Update to get rid of the flicker and use reals instead of ints for your coordinates and speed variables, this will allow you to shorten your delays |
|
|
|
|
![](images/spacer.gif) |
|