feat(input): add strafe on A/D while preserving arrow key camera rotation

This commit is contained in:
Игорь Федосеев 2026-10-14 00:24:04 +03:00
parent 342eb16e04
commit 4a27ea0f44
4 changed files with 80 additions and 25 deletions

Binary file not shown.

View file

@ -4450,6 +4450,10 @@ HandlePlayerInput PROC uses ebx esi edi
local speed:DWORD local speed:DWORD
local nextX:DWORD local nextX:DWORD
local nextY:DWORD local nextY:DWORD
local fwdDir:DWORD
local strafeDir:DWORD
local deltaMoveX:DWORD
local deltaMoveY:DWORD
local rcClient[16]:BYTE local rcClient[16]:BYTE
local ptCenter:C3D_POINT local ptCenter:C3D_POINT
local ptCursor:C3D_POINT local ptCursor:C3D_POINT
@ -4485,6 +4489,8 @@ HandlePlayerInput PROC uses ebx esi edi
mouse_recenter: mouse_recenter:
invoke SetCursorPos, ptCenter.x, ptCenter.y invoke SetCursorPos, ptCenter.x, ptCenter.y
skip_mouse_look: skip_mouse_look:
; Movement speed with sprint (Shift = 10h)
mov eax, deltaTime3D mov eax, deltaTime3D
imul eax, 200 imul eax, 200
mov speed, eax mov speed, eax
@ -4492,53 +4498,101 @@ skip_mouse_look:
je @F je @F
shl speed, 1 shl speed, 1
@@: @@:
; --- Keyboard Arrow Turning (VK_LEFT = 25h, VK_RIGHT = 27h) ---
mov eax, deltaTime3D mov eax, deltaTime3D
shr eax, 2 shr eax, 2
inc eax inc eax
cmp keys3D[41h], 0
jne input_turn_left
cmp keys3D[25h], 0 cmp keys3D[25h], 0
je input_right je @F
input_turn_left:
sub playerAngle, eax sub playerAngle, eax
input_right: @@:
cmp keys3D[44h], 0
jne input_turn_right
cmp keys3D[27h], 0 cmp keys3D[27h], 0
je input_forward je @F
input_turn_right:
add playerAngle, eax add playerAngle, eax
input_forward: @@:
and playerAngle, 511 and playerAngle, 511
call UpdateCamera3D call UpdateCamera3D
xor edi, edi
; --- Forward / Backward Direction (W / Up / S / Down) ---
mov fwdDir, 0
cmp keys3D[57h], 0 cmp keys3D[57h], 0
jne input_go_forward jne @F
cmp keys3D[26h], 0 cmp keys3D[26h], 0
je input_back je check_back_key
input_go_forward: @@:
inc edi inc fwdDir
input_back: check_back_key:
cmp keys3D[53h], 0 cmp keys3D[53h], 0
jne input_go_back jne @F
cmp keys3D[28h], 0 cmp keys3D[28h], 0
je input_move je check_strafe_keys
input_go_back: @@:
dec edi dec fwdDir
input_move:
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 test edi, edi
jz input_action jz calc_strafe_comp
imul edi, speed imul edi, speed
mov eax, playerDirX mov eax, playerDirX
imul edi imul edi
shrd eax, edx, 16 shrd eax, edx, 16
add eax, playerX add deltaMoveX, eax
mov nextX, eax
mov eax, playerDirY mov eax, playerDirY
imul edi imul edi
shrd eax, edx, 16 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 mov nextY, eax
invoke CanWalk3D, nextX, playerY invoke CanWalk3D, nextX, playerY
test eax, eax test eax, eax
jz @F jz @F
@ -4550,6 +4604,7 @@ input_move:
jz input_action jz input_action
mov eax, nextY mov eax, nextY
mov playerY, eax mov playerY, eax
input_action: input_action:
invoke Pressed3D, 45h invoke Pressed3D, 45h
test eax, eax test eax, eax

BIN
poker.exe

Binary file not shown.

BIN
poker.obj

Binary file not shown.