]> gitweb.factorcode.org Git - factor.git/commitdiff
clamp coordinates when doing terrain collision detection past the edge of the segment
authorJoe Groff <arcata@gmail.com>
Sun, 10 May 2009 01:15:55 +0000 (20:15 -0500)
committerJoe Groff <arcata@gmail.com>
Sun, 10 May 2009 01:15:55 +0000 (20:15 -0500)
extra/terrain/terrain.factor

index fe105b2e521392c9be080b7fd5c2fd4363f49bdd..590244ca6a46c29bf549999f3c0568de7281e674 100644 (file)
@@ -138,8 +138,11 @@ M: terrain-world tick-length
 : apply-gravity ( velocity -- velocity' )
     1 over [ GRAVITY - ] change-nth ;
 
+: clamp-coords ( coords dim -- coords' )
+    [ { 0 0 } vmax ] dip { 2 2 } v- vmin ;
+
 :: pixel-indices ( coords dim -- indices )
-    coords vfloor [ >integer ] map :> floor-coords
+    coords vfloor [ >integer ] map dim clamp-coords :> floor-coords
     floor-coords first2 dim first * + :> base-index
     base-index dim first + :> next-row-index