From: DeaDDooMER Date: Wed, 8 Mar 2017 10:47:21 +0000 (+0300) Subject: Fix fall beyond of map bound X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=da44ebb09be137e3066278fb5b1bd1fd0b43fd10;p=cavecraft.git Fix fall beyond of map bound --- 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