Ok, here's another possible use for it (redefining of keys):
Graphics 640,480,0,2
Type controls
Field kUp
Field kDown
Field kLeft
Field kRight
End Type
Type player
Field x
Field y
Field image
Field controls.controls
End Type
Global player1.player = New player
player1\x=320
player1\y=240
player1\image = CreateImage(32,32)
Player1\controls.controls = New controls
SetBuffer ImageBuffer(player1\image)
Color 255,0,0
Rect 0,0,32,32,1
Color 255,255,255
SetBuffer FrontBuffer()
Text 0,0, "press key for up: "
player1\controls\kUp = AsciiToScancode(WaitKey())
Text 22*FontWidth(),0,Chr(ScancodeToAscii(player1\controls\kUp))
Text 0,12, "press key for down: "
player1\controls\kDown = AsciiToScancode(WaitKey())
Text 22*FontWidth(),12,Chr(ScancodeToAscii(player1\controls\kDown))
Text 0,24, "press key for left: "
player1\controls\kLeft = AsciiToScancode(WaitKey())
Text 22*FontWidth(),24,Chr(ScancodeToAscii(player1\controls\kLeft))
Text 0,36, "press key for right: "
player1\controls\kRight = AsciiToScancode(WaitKey())
Text 22*FontWidth(),36,Chr(ScancodeToAscii(player1\controls\kRight))
Text GraphicsWidth()/2,100,"press any key to continue",True
WaitKey()
Cls
SetBuffer BackBuffer()
While Not KeyDown(1)
If KeyDown(player1\controls\kUp) Then
player1\Y = player1\y-2
If player1\y<0 Then player1\y = 0
EndIf
If KeyDown(player1\controls\kDown) Then
player1\Y = player1\y+2
If player1\y > GraphicsHeight()-32 Then player1\y = GraphicsHeight()-32
EndIf
If KeyDown(player1\controls\kLeft) Then
player1\x = player1\x-2
If player1\x<0 Then player1\x = 0
EndIf
If KeyDown(player1\controls\kRight) Then
player1\x = player1\x+2
If player1\x > GraphicsWidth()-32 Then player1\x = GraphicsWidth()-32
EndIf
DrawImage player1\image, player1\x, player1\y
Flip
Cls
Wend
End
*EDIT*
It does however, only work with keys that return valid ascii values.
|