Key 'Hook' for a game.

  • Thread starter Thread starter mikey
  • Start date Start date
M

mikey

I have the following code:

Private Sub FMain_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.W
Controller.UserTank.Undraw()
Controller.UserTank.MoveUp()
Controller.UserTank.Draw()

Case Keys.S
Controller.UserTank.Undraw()
Controller.UserTank.MoveDown()
Controller.UserTank.Draw()

Case Keys.Space
Controller.UserTank.FireProjectile()
tmrProjectiles.Start()
End Select
End Sub


Obviously, when moving up (or down) and then firing stops you moving.
How do I stop this, I want to be able to move and shoot without
having to repress the key.

Thanks.
 
Appears to me you need a static variable like


enum DirectionsMoving
Up
Down
Left
Right
None
end enum

DMoving as DirectionsMoving

When they click to move set this to remember, then whatever stops movement
would set it to None.

Then when firing check this and shoot then move in the right direction.

Better yet have the class keep up with which way it is moving and just call
MOVE
let it figure out UP,DOWN,LEFT, RIGHT or NONE.

HTH,

Shane

mikey said:
I have the following code:

Private Sub FMain_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.W
Controller.UserTank.Undraw()
Controller.UserTank.MoveUp()
Controller.UserTank.Draw()

Case Keys.S
Controller.UserTank.Undraw()
Controller.UserTank.MoveDown()
Controller.UserTank.Draw()

Case Keys.Space
Controller.UserTank.FireProjectile()
tmrProjectiles.Start()
End Select
End Sub


Obviously, when moving up (or down) and then firing stops you moving.
How do I stop this, I want to be able to move and shoot without
having to repress the key.

Thanks.
 
Back
Top