extra key hit
BlitzPlus Forums/BlitzPlus Beginners Area/extra key hit
| ||
;======================== AppTitle "Satellite Defense" Graphics 320,240,16,2 SetBuffer BackBuffer() ;user stuf gun_x = 0 gun_y = 0 ;gun movement type Const longMvt =1 Const shortMvt = -1 movementType = longMvt ;loop While Not KeyHit(1) ;toggle long and short movements If KeyHit(15) Then ;tab movementType = -movementType End If ;gun motion Select movementType Case longMvt If KeyDown(200) Then ;up If(gun_y < 90) Then gun_y = gun_y +1 EndIf EndIf If KeyDown(208) Then ;down If (gun_y > -90) Then gun_y = gun_y -1 EndIf EndIf Case shortMvt If KeyHit(200) Then ;up If(gun_y < 90) Then gun_y = gun_y +1 EndIf EndIf If KeyHit(208) Then ;down If (gun_y > -90) Then gun_y = gun_y -1 EndIf EndIf End Select Text 1,1,"Gun X =" + gun_x Text 1,15,"Gun Y =" + gun_y Flip Cls Wend End ;======================== It is currently a text based game. There is a bug in my code above. When I toggle from longMvt to shortMvt there seems to be an extra shift happening after pressing the TAB. While shifting from shortMvt to longMvt everything is fine. Can anyone find a solution please? I have omitted the x coordinate code |
| ||
I kinda got it. If I insert FlushKeys the problem goes away for now. I replaced If KeyHit(15) Then ;tab movementType = -movementType End If with If KeyHit(15) Then ;tab movementType = -movementType FlushKeys End If |