Posts: 31
Threads: 7
Joined: Nov 2002
I already posted this in the thread for my project, but I figured I would post it here as well in the hope of getting help from people who aren't reading my thread on the projects board.
Anyway, here's my problem:
For part of my game, I am having the player hit a key that corresponds to a certain sprite. The sprites are of the 4 directional arrows but that is largely irrelevant. Anyway, I have several of the arrows lined up, and after a given delay (~1/5 sec) the next one in the que starts moving across the screen. The player has to hit the key representing that sprite before it reaches a limit.
The problem is, after the key is pressed for one arrow, the keyboard buffer isn't cleared quickly enough and the computer thinks the key is still pressed (even when its not) and registers an incorrect key press.
I'm using RelLib's key handler and I've tried dumping the keyboard buffer by replacing the header with the tail (Poke &H1A, Peek (&H1C)), but it doesn't seem to work, I still get the problem.
Any Suggestions?
Posts: 3,288
Threads: 167
Joined: Nov 2001
Code? I haven't encountered or any Relkey user of that sort of prob. :*(
Posts: 31
Threads: 7
Joined: Nov 2002
Sorry, its long and uncommented; I just started using RelKey with this sub recently, and I'm sure you could suggest better implementation...
Code: DEFINT A-Z
SUB darkonsub
'darkon(x,0) = type of arrow
'darkon(x,1) = x-position of that arrow
'darkon(x,2) = usage of that arrow
' -0 = not in use
' -1 = inuse
' -2 = moving
' -3 = user pressed wrong key
DIM keyp%(5)
darkondata.maxhit = 0
darkondata.hitinarow = 0
'----finds first and last arrows
first% = 0
last% = 0
FOR i% = 0 TO darkondata.numberofarrows - 1
IF darkon(i%, 2) = 0 AND i% > 0 THEN
IF darkon(i% - 1, 2) = 1 THEN last% = i%
ELSE last% = i%
END IF
NEXT i%
IF last% = 0 THEN GOTO quitdarkonsub
darkon(first%, 2) = 2
darkondata.timeoflast = TIMER
DO
'dumb$ = INKEY$
'keyp$ = INKEY$
'IF keyp$ <> "" THEN press% = ASC(keyp$)
'----Gets Input----
DEF SEG = &H40
POKE &H1A, PEEK(&H1C)
POKE &H1A, PEEK(&H1C)
DEF SEG
IF RelKey%(72) THEN keyp%(1) = 1 'up
IF RelKey%(80) THEN keyp%(2) = 1 'down
IF RelKey%(75) THEN keyp%(3) = 1 'left
IF RelKey%(77) THEN keyp%(4) = 1 'right
IF RelKey%(1) THEN GOTO quitdarkonsub 'esc
'DO: LOOP WHILE darkondata.waiter + 250 > CLOCK&
'darkondata.waiter = CLOCK&
'----turns on next moving arrow
IF darkondata.timeoflast + darkondata.rate < TIMER THEN
darkondata.timeoflast = TIMER
FOR i% = 0 TO last%
IF darkon(i%, 2) = 1 THEN
darkon(i%, 2) = 2
darkon(i%, 1) = darkondata.startlimit + 1
FOR j% = i% + 1 TO last%
darkon(j%, 1) = darkondata.startlimit + 13 + (j% - i%) * 12
NEXT j%
i% = last%
END IF
NEXT i%
END IF
'----checks arrows to see if they have been hit or if they have passed the end limit
FOR i% = 0 TO darkondata.numberofarrows - 1
IF darkon(i%, 2) = 2 OR darkon(i%, 2) = 3 THEN
darkon(i%, 1) = darkon(i%, 1) - darkondata.speed
IF darkon(i%, 1) <= darkondata.endlimit AND darkon(i%, 2) = 2 THEN
darkon(i%, 2) = 3
darkondata.endlimit = darkondata.endlimit + 12
IF darkondata.hitinarow > darkondata.maxhit THEN darkondata.maxhit = darkondata.hitinarow
darkondata.hitinarow = 0
first% = first% + 1
GOTO skippage
END IF
IF darkon(i%, 1) <= 0 THEN darkon(i%, 2) = 0
END IF
NEXT i%
FOR j% = 1 TO 4
'IF keyp%(j%) <> 0 AND darkon(first%, 2) = 2 AND darkondata.waiter + 750 < CLOCK& THEN 'see if key has been pressed
IF keyp%(j%) <> 0 AND darkon(first%, 2) = 2 THEN 'see if key has been pressed
darkondata.waiter = CLOCK&
IF j% <> darkon(first%, 0) THEN 'wrong arrow pressed
darkon(first%, 2) = 3
darkondata.endlimit = darkondata.endlimit + 12
IF darkondata.hitinarow > darkondata.maxhit THEN darkondata.maxhit = darkondata.hitinarow
darkondata.hitinarow = 0
first% = first% + 1
GOTO skippage
END IF
IF j% = darkon(first%, 0) THEN 'correct arrow pressed
darkon(first%, 2) = 0
darkondata.hitinarow = darkondata.hitinarow + 1
first% = first% + 1
GOTO skippage
END IF
END IF
NEXT j%
skippage:
FOR j% = 0 TO 4
keyp%(j%) = 0
NEXT j%
FOR i% = 0 TO last%
IF darkon(i%, 2) = 1 OR darkon(i%, 2) = 2 THEN 'moving or waiting arrow
RelSprite pageseg%, darkon(i%, 1), SCY% + 3, VARSEG(arrowgraphics%(0)), VARPTR(arrowgraphics%(arrowcnt(darkon(i%, 0))))
END IF
IF darkon(i%, 2) = 3 THEN 'stuff for x and arrow
RelSprite pageseg%, darkon(i%, 1), SCY% + 3, VARSEG(arrowgraphics%(0)), VARPTR(arrowgraphics%(arrowcnt(darkon(i%, 0))))
RelSprite pageseg%, darkon(i%, 1), SCY% + 3, VARSEG(arrowgraphics%(0)), VARPTR(arrowgraphics%(arrowcnt(0)))
END IF
NEXT i%
LINE (darkondata.startlimit, SCY% + 2)-(darkondata.startlimit, 199), 48
LINE (darkondata.endlimit, SCY% + 2)-(darkondata.endlimit, 199), 4
WAIT &H3DA, 8
WAIT &H3DA, 8, 8
RelPCopy &HA000, pageseg%
LINE (0, SCY% + 2)-(319, 199), 0, BF
IF first% = last% AND darkon(last%, 2) <> 2 THEN GOTO sumpoints
LOOP
sumpoints: 'tally points
LINE (0, SCY% + 2)-(319, 199), 0, BF
LINE (darkondata.startlimit, SCY% + 2)-(darkondata.startlimit, 199), 48
LINE (darkondata.endlimit, SCY% + 2)-(darkondata.endlimit, 199), 4
player1.life = player1.life + 5 * darkondata.maxhit
quitdarkonsub: 'return to main game
FOR i% = 0 TO darkondata.numberofarrows - 1
darkon(i%, 2) = 0
NEXT i%
FOR i% = 0 TO numberofshots% - 1
IF shots(i%).who = 2 THEN shots(i%).inuse = 0
NEXT i%
'DO: LOOP WHILE INKEY$ = ""
END SUB
Posts: 3,288
Threads: 167
Joined: Nov 2001
Try erasing this:
DEF SEG = &H40
POKE &H1A, PEEK(&H1C)
POKE &H1A, PEEK(&H1C)
DEF SEG
Though it does not matter really. :*)
And putting
RelKeyBoardON
Do
'game stuff here including calls to RelKey
Loop
RelKeyBoardOFF
End
Posts: 4,307
Threads: 63
Joined: May 2003
This clears the keyboard buffer =).
DEF SEG = &H40
POKE &H1C, PEEK(&H1A)
DEF SEG
Posts: 2,771
Threads: 96
Joined: Oct 2003
Does this not do the same job?
Posts: 31
Threads: 7
Joined: Nov 2002
dark_prevail-I can't do that because I'm using RelKey
TheBigBasicQ-I'm already doing that
Rel-I have already turned RelKey on outside the sub, should I turn it on a second time? I don't want to turn it off at the end of my sub because then it won't be available for my main game loop.
All that aside, I am probably going to be changing the way this works and incoporating it into the main game engine, so it won't matter too much then.
Edit: No worries, I figured it out; the problem was in the implementation of RelKey, not in RelKey itself.
Posts: 3,288
Threads: 167
Joined: Nov 2001
Posts: 1,688
Threads: 119
Joined: Jun 2003
Aaron: yes, it will work. when you assign a key with inkey$, it will clear the keyboard buffer.
Jumping Jahoolipers!
|