From e4059d8393c81efe4ff7ebdb01e630d492ffbe19 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sat, 9 May 2009 20:15:55 -0500 Subject: [PATCH] clamp coordinates when doing terrain collision detection past the edge of the segment --- extra/terrain/terrain.factor | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extra/terrain/terrain.factor b/extra/terrain/terrain.factor index fe105b2e52..590244ca6a 100644 --- a/extra/terrain/terrain.factor +++ b/extra/terrain/terrain.factor @@ -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