DEADSOFTWARE

Fix fall beyond of map bound
[cavecraft.git] / src / phy.pas
index 648ca346c76ad438da34143fde58198475dd497b..431f18034826a9fc28e56ff6b1c9cedc39e0a947 100644 (file)
@@ -21,7 +21,7 @@ interface
  function canSeeObj(x1, y1, x2, y2:integer):boolean;\r
 \r
 implementation\r
  function canSeeObj(x1, y1, x2, y2:integer):boolean;\r
 \r
 implementation\r
- uses items_store, maps;\r
+ uses items_store, maps, vars;\r
  const\r
   MAX_VELY=32;\r
   TILE_SIZE=16;\r
  const\r
   MAX_VELY=32;\r
   TILE_SIZE=16;\r
@@ -46,31 +46,46 @@ function CollTwoObj(x1,y1,w1,h1,x2,y2,w2,h2:integer):boolean;
    jmp:=_jmp;\r
   end;\r
 \r
    jmp:=_jmp;\r
   end;\r
 \r
+ function mapBoundCheck(x, y : Integer) : Boolean;\r
+   begin\r
+     mapBoundCheck := (x < 0) or (x > MAP_W * TILE_SIZE);\r
+   end;\r
+\r
+ function onMapObjectCheck(x, y, w, h : Integer) : Boolean;\r
+   begin\r
+     onMapObjectCheck := mapBoundCheck(x, y) or mapBoundCheck(x + w, y + h);\r
+   end;\r
+\r
  function isSolid(x, y, velx, vely:integer):boolean;\r
  function isSolid(x, y, velx, vely:integer):boolean;\r
-  begin\r
-   if getBlockColl(getMap(x, y))<>0 then\r
-    isSolid:=true;\r
-  end;\r
+   begin\r
+     isSolid := getBlockColl(getMap(x, y)) <> 0;\r
+   end;\r
 \r
  function mapColl(x, y, w, h, velx, vely:integer):boolean;\r
 \r
  function mapColl(x, y, w, h, velx, vely:integer):boolean;\r
-  var\r
-   i, j:integer;\r
-   minx, miny, maxx, maxy:integer;\r
-  begin\r
-   minx:=x div TILE_SIZE;\r
-   miny:=y div TILE_SIZE;\r
-   maxx:=(x+w-1) div TILE_SIZE;\r
-   maxy:=(y+h-1) div TILE_SIZE;\r
-   for i:=minx to maxx do\r
-   for j:=miny to maxy do\r
-    begin\r
-     if isSolid(i, j, velx, vely) then\r
-      begin\r
-       mapColl:=true;\r
-       exit;\r
-      end;\r
-    end;\r
- end;\r
+   var\r
+    i, j:integer;\r
+    minx, miny, maxx, maxy:integer;\r
+   begin\r
+     if onMapObjectCheck(x, y, w, h) then\r
+       begin\r
+         mapColl := true;\r
+         exit;\r
+       end;\r
+\r
+     minx:=x div TILE_SIZE;\r
+     miny:=y div TILE_SIZE;\r
+     maxx:=(x+w-1) div TILE_SIZE;\r
+     maxy:=(y+h-1) div TILE_SIZE;\r
+     for i:=minx to maxx do\r
+     for j:=miny to maxy do\r
+       begin\r
+         if isSolid(i, j, velx, vely) then\r
+           begin\r
+             mapColl:=true;\r
+             exit;\r
+           end;\r
+       end;\r
+  end;\r
 \r
  function canSeeObj(x1, y1, x2, y2:integer):boolean;\r
   var\r
 \r
  function canSeeObj(x1, y1, x2, y2:integer):boolean;\r
   var\r