simple 2d movement ...
Blitz3D Forums/Blitz3D Beginners Area/simple 2d movement ...
| ||
H! Because i'm busy with a internet game I need/want some other player movement. (movement commands) The player only can do this up - right - left down - right - left right - up - down left - up - down and stop when all keys are up. I send the movement options to the server, so I know if the player is going up (uu) or up-left (ul) etc. I changed the code so you can see what I mean. And my question is: "is there a smaller/better code for this?" While Not KeyHit(1) ;up If KeyDown(200) And KeyDown(208)<>1 Then If KeyDown(200) And KeyDown(205)<>1 And KeyDown(203)<>1 Then pldo$="uu" DebugLog pldo$ EndIf If KeyDown(205) Then pldo$="ur" DebugLog pldo$ EndIf If KeyDown(203) Then pldo$="ul" DebugLog pldo$ EndIf EndIf ;down If KeyDown(208) And KeyDown(200)<>1 Then If KeyDown(208) And KeyDown(205)<>1 And KeyDown(203)<>1 Then pldo$="dd" DebugLog pldo$ EndIf If KeyDown(205) Then pldo$="dr" DebugLog pldo$ EndIf If KeyDown(203) Then pldo$="dl" DebugLog pldo$ EndIf EndIf ;left If KeyDown(203) And KeyDown(205)<>1 And KeyDown(208)<>1 And KeyDown(200)<>1 Then If KeyDown(203) Then pldo$="ll" DebugLog pldo$ EndIf EndIf ;right If KeyDown(205) And KeyDown(203)<>1 And KeyDown(208)<>1 And KeyDown(200)<>1 Then If KeyDown(205) Then pldo$="rr" DebugLog pldo$ EndIf EndIf Wend Thanks, |
| ||
Here... best I can do ...While Not KeyHit(1) kx = KeyDown( 205 ) - KeyDown( 203 ) ky = KeyDown( 200 ) - KeyDown( 208 ) If Ky <> 0 If Ky > 0 pldo$ = "u" If ky < 0 pldo$ = "d" If kx = 0 pldo$ = pldo$ + pldo$ If kx > 0 pldo$ = pldo$ + "r" If kx < 0 pldo$ = pldo$ + "l" Else If kx > 0 pldo$ = "rr" If kx < 0 pldo$ = "ll" EndIf DebugLog pldo$ Wend Hope it helps. |
| ||
That's the way I like it ;) Thanks ! |
| ||
If you mean smaller to reduce the data sent then just use values and add them together. up=1 down=2 left=4 right=8 doing it this way means you only need to send 1 byte. |