Game and keys

pmu5757

Member
Licensed User
Hello
I intend to make a little game, and I wonder what is the best way to move for example a starship with keyboard keys.

Thank you.
 

Cableguy

Expert
Licensed User
Longtime User
Use tha Sprite dll, wichcan detect colisions with other sprite objects, and wiht edges or specific coordinates....
 

pmu5757

Member
Licensed User
Ok, that's for the device...
And if I want to make such an application for the desktop ?
Thank you.
 

Cableguy

Expert
Licensed User
Longtime User
Them use the keyPress event and use/look for the ASCII key value....
For instance, chr13 is the enter key...
Google a bit and you will find a complete reference to the ASCII key map...
 

pmu5757

Member
Licensed User
Ok for the keypressed event and the ascii table.
But what object must I choose for the keypressed event ?
I tried with the whole form, but with a form, I only have the "special keys" of the device.

Thank you

Pascal.
 

Cableguy

Expert
Licensed User
Longtime User
The only two standart control in B4PPc that suport "keyPress Event" are the Button and the Textbox.
Other controls have similar events...

You can change the default event triggered by adding an event...

For instance you want the same code to de used in more than one event, but That would cause too much code lines...
so just add an extra event that will overRide the default event of the control:

AddEvent("Button1",KeyPress,"MySub")
AddEvent("TextBox1",KeyPress,"MySub")

This will cause that both keypress events will be "linking" to the same Sub...
 

pmu5757

Member
Licensed User
Thank you Cableguy, but I still have a question : what are ascii codes for the arrows of the desktop keyboard ?

Thank you.
 

pmu5757

Member
Licensed User
Thank you Erel, but I don't succeed in coding that.
Here is my code (in fact too attempts in the same code but neither the one nor the other works).
Could you tell me what's wrong : I just want to make the button move by typing on the arrows.
Thank you.

B4X:
Sub Globals
   'Declare the global variables here.

End Sub

Sub App_Start
   Form1.Show
   Button1.Focus
   End Sub


Sub Button1_KeyPress (key)
   If Key=cUpKey Then
      Button1.Top=Button1.Top+5
   End If
End Sub

Sub Form1_KeyPress (specialKey)
   Select SpecialKey
 Case cUpKey
  Button1.Top=Button1.Top+5
 Case cDownKey
 Button1.Top=Button1.Top-5
End Select
End Sub
 
Top