From 823b3edc30bcde052fbbb969f85e157bab1f3702 Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Sat, 17 Dec 2022 16:57:47 -0800 Subject: [PATCH] Reorient head based on tongue angle --- chameleonic.p8 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/chameleonic.p8 b/chameleonic.p8 index 6dd933c..ea0e066 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -424,6 +424,10 @@ function level:can_move( if self:mcoll(mx0+dmx,my0+dmy) then return false end + + if player.x==mx0+dmx and player.y==my0+dmy then + return false + end -- todo: check tongue collision if player.rope then @@ -588,6 +592,10 @@ function player:update() local rx,ry=self:_rope_pos() self.rope:drag_dst(rx,ry) + local tdx,tdy=self.rope:tug_orientxy() + if (tdx!=0) self.orientx=tdx + if (tdy!=0) self.orienty=tdy + if self.rope:done() then self.rope=nil add(self.todo,{}) @@ -1214,6 +1222,23 @@ end -->8 -- moved here because it's complicated +function rope:tug_orientxy() + local a1=self:_anc(#self.ancs+1) + local a0=self:_anc(#self.ancs) + local dx=a0.x-a1.x + local tdx=0 + if (dx>3) tdx=1 + if (dx<-3) tdx=-1 + + local dy=a0.y-a1.y + local tdy=0 + if abs(dy)>abs(dx)/2 then + if (dy>3) tdy=1 + if (dy<-3) tdy=-1 + end + return tdx,tdy +end + function rope:tug() self:_make_consistent() if (self.under_destruction) return