From da44ebb09be137e3066278fb5b1bd1fd0b43fd10 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Wed, 8 Mar 2017 13:47:21 +0300 Subject: [PATCH 1/1] Fix fall beyond of map bound --- src/phy.pas | 61 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/src/phy.pas b/src/phy.pas index 648ca34..431f180 100644 --- a/src/phy.pas +++ b/src/phy.pas @@ -21,7 +21,7 @@ interface function canSeeObj(x1, y1, x2, y2:integer):boolean; implementation - uses items_store, maps; + uses items_store, maps, vars; const MAX_VELY=32; TILE_SIZE=16; @@ -46,31 +46,46 @@ function CollTwoObj(x1,y1,w1,h1,x2,y2,w2,h2:integer):boolean; jmp:=_jmp; end; + function mapBoundCheck(x, y : Integer) : Boolean; + begin + mapBoundCheck := (x < 0) or (x > MAP_W * TILE_SIZE); + end; + + function onMapObjectCheck(x, y, w, h : Integer) : Boolean; + begin + onMapObjectCheck := mapBoundCheck(x, y) or mapBoundCheck(x + w, y + h); + end; + function isSolid(x, y, velx, vely:integer):boolean; - begin - if getBlockColl(getMap(x, y))<>0 then - isSolid:=true; - end; + begin + isSolid := getBlockColl(getMap(x, y)) <> 0; + end; function mapColl(x, y, w, h, velx, vely:integer):boolean; - var - i, j:integer; - minx, miny, maxx, maxy:integer; - begin - minx:=x div TILE_SIZE; - miny:=y div TILE_SIZE; - maxx:=(x+w-1) div TILE_SIZE; - maxy:=(y+h-1) div TILE_SIZE; - for i:=minx to maxx do - for j:=miny to maxy do - begin - if isSolid(i, j, velx, vely) then - begin - mapColl:=true; - exit; - end; - end; - end; + var + i, j:integer; + minx, miny, maxx, maxy:integer; + begin + if onMapObjectCheck(x, y, w, h) then + begin + mapColl := true; + exit; + end; + + minx:=x div TILE_SIZE; + miny:=y div TILE_SIZE; + maxx:=(x+w-1) div TILE_SIZE; + maxy:=(y+h-1) div TILE_SIZE; + for i:=minx to maxx do + for j:=miny to maxy do + begin + if isSolid(i, j, velx, vely) then + begin + mapColl:=true; + exit; + end; + end; + end; function canSeeObj(x1, y1, x2, y2:integer):boolean; var -- 2.29.2