Skip to content

Commit 7207ae0

Browse files
committed
doom lua: fix centering and follow mode
1 parent b1a0ef7 commit 7207ae0

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Assets/Lua/Doom/doom.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,17 @@ local function iterate()
562562
"SECTOR %d spec: %d\nflo: %.2f ceil: %.2f",
563563
selected_sector.iSectorID,
564564
selected_sector.special,
565-
selected_sector.floorheight / FRACUNIT,
565+
selected_sector.floorheight / FRACUNIT,
566566
selected_sector.ceilingheight / FRACUNIT)
567567
end
568568
end
569569

570570
if closest_line then
571571
local x1, y1, x2, y2 = cached_line_coords(closest_line)
572572
local distance = distance_from_line(
573-
{ x = player.x / FRACUNIT, y = player.y / FRACUNIT },
574-
{ x = x1 / FRACUNIT, y = y1 / FRACUNIT },
575-
{ x = x2 / FRACUNIT, y = y2 / FRACUNIT }
573+
{ x = player.x, y = player.y },
574+
{ x = x1 / FRACUNIT, y = y1 / FRACUNIT },
575+
{ x = x2 / FRACUNIT, y = y2 / FRACUNIT }
576576
)
577577

578578
x1, y1, x2, y2 = game_to_screen(x1, y1, x2, y2)
@@ -711,14 +711,14 @@ local function update_zoom()
711711
if Follow and Globals.gamestate == 0 then
712712
local player = select(2, next(Players))
713713
local screenCenter = screen_to_game({
714-
x = ScreenWidth /2,
714+
x = (ScreenWidth+PADDING_WIDTH)/2,
715715
y = ScreenHeight/2
716716
})
717717

718-
screenCenter.x = screenCenter.x - player.x
719-
screenCenter.y = screenCenter.y - player.y
720-
Pan.x = Pan.x + screenCenter.x / FRACUNIT
721-
Pan.y = Pan.y - screenCenter.y / FRACUNIT
718+
screenCenter.x = screenCenter.x / FRACUNIT - player.x
719+
screenCenter.y = screenCenter.y / FRACUNIT - player.y
720+
Pan.x = Pan.x + screenCenter.x
721+
Pan.y = Pan.y - screenCenter.y
722722
end
723723

724724
if not Init
@@ -734,11 +734,11 @@ local function update_zoom()
734734
then
735735
OB.left, OB.right = maybe_swap(OB.left, OB.right)
736736
OB.top, OB.bottom = maybe_swap(OB.top, OB.bottom)
737-
local span = { x = OB.right-OB.left, y = OB.bottom-OB.top }
738-
local scale = { x = ScreenWidth/span.x, y = ScreenHeight/span.y }
737+
local span = { x = OB.right-OB.left, y = OB.bottom-OB.top }
738+
local scale = { x = (ScreenWidth-PADDING_WIDTH)/span.x, y = ScreenHeight/span.y }
739739
Zoom = math.min(scale.x, scale.y)
740-
local spanCenter = { x = OB.left+span.x/2, y = OB.top+span.y/2 }
741-
local sreenCenter = { x = ScreenWidth/Zoom/2, y = ScreenHeight/Zoom/2 }
740+
local spanCenter = { x = OB.left+span.x/2, y = OB.top+span.y/2 }
741+
local sreenCenter = { x = (ScreenWidth+PADDING_WIDTH)/Zoom/2, y = ScreenHeight/Zoom/2 }
742742

743743
if not Follow then
744744
Pan.x = -math.floor(spanCenter.x - sreenCenter.x)

0 commit comments

Comments
 (0)