From 812d619cc74a5c2148af5c8025dc5ce999430c93 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Wed, 28 Dec 2022 21:12:23 +0000 Subject: [PATCH] can_move golf, redux (#14) previous attempt tried to use shifts to get 0.4 to 0.2 or 0.8 and multiplication to get -0.8, forgetting that the multiplication would also turn 0.4 into 0 along the way. oops. I got ratholed on the mathematical approach, but a very straightforward lookup table can get more done. Reviewed-on: https://git.chromaticdragon.app/pyrex/chameleonic/pulls/14 Co-authored-by: Kistaro Windrider Co-committed-by: Kistaro Windrider --- chameleonic.p8 | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/chameleonic.p8 b/chameleonic.p8 index 32ed5e6..aab6cb4 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -531,6 +531,8 @@ function level:get_latch(dx,dy,px,py) end end +ropecheck=split"-0.8,0.4,0.2" + function level:can_move( is_player, mx0,my0,dmx,dmy,exclude_src,exclude_dst @@ -542,17 +544,9 @@ function level:can_move( if (self:mcoll(mx1,my1) or player.x==mx1 and player.y==my1) return false if player.rope then - local chk=false local w,h=1.6,0.2 if (dmx==0) w,h=0.2,1.6 - - local rectx,recty - if (dmy==-1) rectx,recty=0.4,-0.8 - if (dmy==1) rectx,recty=0.4,0.2 - if (dmx==-1) rectx,recty=-0.8,0.4 - if (dmx==1) rectx,recty=0.2,0.4 - - if (player.rope:collide_mrect(mx0+rectx,my0+recty,w,h,exclude_src,exclude_dst)) return false + if (player.rope:collide_mrect(mx0+ropecheck[dmx+2],my0+ropecheck[dmy+2],w,h,exclude_src,exclude_dst)) return false end return true