feat(input): add strafe on A/D while preserving arrow key camera rotation
This commit is contained in:
parent
342eb16e04
commit
4a27ea0f44
4 changed files with 80 additions and 25 deletions
Binary file not shown.
105
casino3d.inc
105
casino3d.inc
|
|
@ -4450,6 +4450,10 @@ HandlePlayerInput PROC uses ebx esi edi
|
|||
local speed:DWORD
|
||||
local nextX:DWORD
|
||||
local nextY:DWORD
|
||||
local fwdDir:DWORD
|
||||
local strafeDir:DWORD
|
||||
local deltaMoveX:DWORD
|
||||
local deltaMoveY:DWORD
|
||||
local rcClient[16]:BYTE
|
||||
local ptCenter:C3D_POINT
|
||||
local ptCursor:C3D_POINT
|
||||
|
|
@ -4485,6 +4489,8 @@ HandlePlayerInput PROC uses ebx esi edi
|
|||
mouse_recenter:
|
||||
invoke SetCursorPos, ptCenter.x, ptCenter.y
|
||||
skip_mouse_look:
|
||||
|
||||
; Movement speed with sprint (Shift = 10h)
|
||||
mov eax, deltaTime3D
|
||||
imul eax, 200
|
||||
mov speed, eax
|
||||
|
|
@ -4492,53 +4498,101 @@ skip_mouse_look:
|
|||
je @F
|
||||
shl speed, 1
|
||||
@@:
|
||||
|
||||
; --- Keyboard Arrow Turning (VK_LEFT = 25h, VK_RIGHT = 27h) ---
|
||||
mov eax, deltaTime3D
|
||||
shr eax, 2
|
||||
inc eax
|
||||
cmp keys3D[41h], 0
|
||||
jne input_turn_left
|
||||
cmp keys3D[25h], 0
|
||||
je input_right
|
||||
input_turn_left:
|
||||
je @F
|
||||
sub playerAngle, eax
|
||||
input_right:
|
||||
cmp keys3D[44h], 0
|
||||
jne input_turn_right
|
||||
@@:
|
||||
cmp keys3D[27h], 0
|
||||
je input_forward
|
||||
input_turn_right:
|
||||
je @F
|
||||
add playerAngle, eax
|
||||
input_forward:
|
||||
@@:
|
||||
and playerAngle, 511
|
||||
call UpdateCamera3D
|
||||
xor edi, edi
|
||||
|
||||
; --- Forward / Backward Direction (W / Up / S / Down) ---
|
||||
mov fwdDir, 0
|
||||
cmp keys3D[57h], 0
|
||||
jne input_go_forward
|
||||
jne @F
|
||||
cmp keys3D[26h], 0
|
||||
je input_back
|
||||
input_go_forward:
|
||||
inc edi
|
||||
input_back:
|
||||
je check_back_key
|
||||
@@:
|
||||
inc fwdDir
|
||||
check_back_key:
|
||||
cmp keys3D[53h], 0
|
||||
jne input_go_back
|
||||
jne @F
|
||||
cmp keys3D[28h], 0
|
||||
je input_move
|
||||
input_go_back:
|
||||
dec edi
|
||||
input_move:
|
||||
je check_strafe_keys
|
||||
@@:
|
||||
dec fwdDir
|
||||
|
||||
check_strafe_keys:
|
||||
; --- Strafe Direction (A = Left, D = Right) ---
|
||||
mov strafeDir, 0
|
||||
cmp keys3D[44h], 0
|
||||
je @F
|
||||
inc strafeDir
|
||||
@@:
|
||||
cmp keys3D[41h], 0
|
||||
je @F
|
||||
dec strafeDir
|
||||
@@:
|
||||
|
||||
; --- Movement Calculation ---
|
||||
mov deltaMoveX, 0
|
||||
mov deltaMoveY, 0
|
||||
|
||||
; Forward / Backward component
|
||||
mov edi, fwdDir
|
||||
test edi, edi
|
||||
jz input_action
|
||||
jz calc_strafe_comp
|
||||
|
||||
imul edi, speed
|
||||
mov eax, playerDirX
|
||||
imul edi
|
||||
shrd eax, edx, 16
|
||||
add eax, playerX
|
||||
mov nextX, eax
|
||||
add deltaMoveX, eax
|
||||
|
||||
mov eax, playerDirY
|
||||
imul edi
|
||||
shrd eax, edx, 16
|
||||
add eax, playerY
|
||||
add deltaMoveY, eax
|
||||
|
||||
calc_strafe_comp:
|
||||
; Strafe Left / Right component: Right vector is (-playerDirY, playerDirX)
|
||||
mov edi, strafeDir
|
||||
test edi, edi
|
||||
jz check_total_movement
|
||||
|
||||
imul edi, speed
|
||||
mov eax, playerDirY
|
||||
neg eax
|
||||
imul edi
|
||||
shrd eax, edx, 16
|
||||
add deltaMoveX, eax
|
||||
|
||||
mov eax, playerDirX
|
||||
imul edi
|
||||
shrd eax, edx, 16
|
||||
add deltaMoveY, eax
|
||||
|
||||
check_total_movement:
|
||||
mov eax, deltaMoveX
|
||||
or eax, deltaMoveY
|
||||
jz input_action
|
||||
|
||||
mov eax, playerX
|
||||
add eax, deltaMoveX
|
||||
mov nextX, eax
|
||||
|
||||
mov eax, playerY
|
||||
add eax, deltaMoveY
|
||||
mov nextY, eax
|
||||
|
||||
invoke CanWalk3D, nextX, playerY
|
||||
test eax, eax
|
||||
jz @F
|
||||
|
|
@ -4550,6 +4604,7 @@ input_move:
|
|||
jz input_action
|
||||
mov eax, nextY
|
||||
mov playerY, eax
|
||||
|
||||
input_action:
|
||||
invoke Pressed3D, 45h
|
||||
test eax, eax
|
||||
|
|
|
|||
BIN
poker.exe
BIN
poker.exe
Binary file not shown.
BIN
poker.obj
BIN
poker.obj
Binary file not shown.
Loading…
Add table
Reference in a new issue