X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_game.pas;h=110111e6ca492084d47e8488d0a32138a9c66359;hb=c60af5eda7f59dd43a46577bf27497a8e74f04fd;hp=baf0f630cdbe3414543ba7107537817dbd33e31c;hpb=9bd99e6d9059fb7e9baaa55f1e3a9e7b2ff83f9e;p=d2df-sdl.git diff --git a/src/game/g_game.pas b/src/game/g_game.pas index baf0f63..110111e 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -300,6 +300,12 @@ var gEvents: Array of TGameEvent; gDelayedEvents: Array of TDelayedEvent; + // move button values: + // bits 0-1: l/r state: + // 0: neither left, nor right pressed + // 1: left pressed + // 2: right pressed + // bits 4-5: l/r state when strafe was pressed P1MoveButton: Byte = 0; P2MoveButton: Byte = 0; @@ -1229,9 +1235,12 @@ end; procedure processPlayerControls (plr: TPlayer; var ctrl: TPlayerControl; var MoveButton: Byte; p2hack: Boolean=false); var time: Word; + strafeDir: Byte; begin if (plr = nil) then exit; if (p2hack) then time := 1000 else time := 1; + strafeDir := MoveButton shr 4; + MoveButton := MoveButton and $0F; with ctrl do begin if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî" @@ -1242,12 +1251,29 @@ begin if MoveButton = 1 then plr.PressKey(KEY_LEFT, time) else if MoveButton = 2 then plr.PressKey(KEY_RIGHT, time); - // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî: - if (MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then plr.SetDirection(D_LEFT) - // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî: - else if (MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then plr.SetDirection(D_RIGHT) - // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì: - else if MoveButton <> 0 then plr.SetDirection(TDirection(MoveButton-1)); + // if we have "strafe" key, turn off old strafe mechanics + if isKeyPressed(KeyStrafe, KeyStrafe2) then + begin + // new strafe mechanics + if (strafeDir = 0) then strafeDir := MoveButton; // start strafing + // now set direction according to strafe + if (strafeDir = 1) then plr.SetDirection(D_LEFT) + else if (strafeDir = 2) then plr.SetDirection(D_RIGHT) + else plr.SetDirection(TDirection(MoveButton-1)); + end + else + begin + strafeDir := 0; // not strafing anymore + // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî: + if (MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then plr.SetDirection(D_LEFT) + // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî: + else if (MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then plr.SetDirection(D_RIGHT) + // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì: + else if MoveButton <> 0 then plr.SetDirection(TDirection(MoveButton-1)); + end; + + // fix movebutton state + MoveButton := MoveButton or (strafeDir shl 4); // Îñòàëüíûå êëàâèøè: if isKeyPressed(KeyJump, KeyJump2) then plr.PressKey(KEY_JUMP, time);