From d9d8ce17fd6238c18e897f5fe959f13e23ca38ae Mon Sep 17 00:00:00 2001 From: annabunches Date: Thu, 5 Oct 2023 16:53:23 -0400 Subject: [PATCH] Refactor targeting code into a utility function, add reverse images until we add code to do that programmatically. --- src/enemy/ika.lua | 6 ++++-- src/images/kani/defend_reverse-table-1.png | Bin 0 -> 285 bytes src/images/kani/defend_reverse-table-2.png | Bin 0 -> 314 bytes src/images/kani/defend_reverse-table-3.png | Bin 0 -> 322 bytes src/images/kani/defend_reverse-table-4.png | Bin 0 -> 365 bytes src/images/kani/defend_reverse-table-5.png | Bin 0 -> 442 bytes src/images/kani/defend_reverse-table-6.png | Bin 0 -> 499 bytes src/images/kani/defend_reverse-table-7.png | Bin 0 -> 525 bytes src/images/kani/defend_reverse-table-8.png | Bin 0 -> 562 bytes src/util.lua | 20 ++++++++++++-------- 10 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 src/images/kani/defend_reverse-table-1.png create mode 100644 src/images/kani/defend_reverse-table-2.png create mode 100644 src/images/kani/defend_reverse-table-3.png create mode 100644 src/images/kani/defend_reverse-table-4.png create mode 100644 src/images/kani/defend_reverse-table-5.png create mode 100644 src/images/kani/defend_reverse-table-6.png create mode 100644 src/images/kani/defend_reverse-table-7.png create mode 100644 src/images/kani/defend_reverse-table-8.png diff --git a/src/enemy/ika.lua b/src/enemy/ika.lua index dc506d2..1c1562c 100644 --- a/src/enemy/ika.lua +++ b/src/enemy/ika.lua @@ -19,7 +19,7 @@ function Ika:init(target) end function Ika:onReady() - self.weaponTimer = playdate.timer.new(7000, + self.weaponTimer = playdate.timer.new(5000, function() local b = Bullet(10, 20, self:calculateVector(self.target)) b:moveTo(self.x - (self.width/2) - 1, self.y) @@ -30,7 +30,9 @@ function Ika:onReady() end function Ika:calculateVector(target) - return util.unitPointer(self:getPosition(), target:getPosition()) * 5 + local x1,y1 = self:getPosition() + local x2,y2 = target:getPosition() + return util.unitPointer(x1,y1,x2,y2) * 5 end function Ika:remove() diff --git a/src/images/kani/defend_reverse-table-1.png b/src/images/kani/defend_reverse-table-1.png new file mode 100644 index 0000000000000000000000000000000000000000..a81b4cdded9cd4d5126997f7e7060a9687b5bdfa GIT binary patch literal 285 zcmV+&0pk9NP)Px#*GWV{R9Hvtmq8AIFbD+k|Bu#qXu?75x-142&n-*`XyamqzojsnH5^-=HrM7@ z1MI%;xi)8JtFw^a5=a6MbX6fF)~yQ90-|6(=`1D;I19wU?a60xA;7aBEYwI^8ct&G z=!8*gGJBbDVSBHFQmkmbs-xF~3o%ee<`rdoRK#bF63`V%;{KzW- zX|S{L{smmf+SSFVuvZo?42C=@tiiHy5-`Nvz6P}?gJPeQazEA3Z(PPAc`1~T4aeGS jb8U__!0zjw`=q%IPoWwyT=7N^00000NkvXXu0mjfR=jq5 literal 0 HcmV?d00001 diff --git a/src/images/kani/defend_reverse-table-2.png b/src/images/kani/defend_reverse-table-2.png new file mode 100644 index 0000000000000000000000000000000000000000..178aa32688af811273e253e98947559518131e21 GIT binary patch literal 314 zcmV-A0mc4_P)Px#^hrcPR9HvtnA;A8FbD+o|36w|Vv{D?0=uASIIqXjVYV0Jx+MOsiP@HdL(?g9 zWezofj;l47$=r6r(5YApw26=T@5W01n00CSgfoyH+#}?pjsP~hp2cz1?LrMFB7)c4~zh#ARAmX7_@tzfTLrLG?y9< zKKDMcAzF74@zSyOTiz282GhLF{`UH!tj!Kak7(1v(O{Y@1vQu&PSd!!*)$!#W={h* zIs>H_Rcq~wNxHyIHm`k-5Z8(40}Px#{7FPXR9Hvtmq8B0FbD*b|3A7_50Q`)hxIPBq@vdtJPg>C_pR`6FU+8!31K+i+kPPs@I0&fD02|4>U~g9MKot{6q~PxE=f3Rt>17S1agvOi10 zLLHlyhLc-5OQ2c{vv;LG3Qo57D7Z*#a(k`03^03TET7;bARCODzi+@T8yn{#(_Cpd z`d~cbKpfR&v{!DcJ@S!&G+6e3D|LN%7h{w;$=Y3I5rAdkWH4kVSc9eE=!@4o5aZ*6 zwTE=(_Mx+?zuco5dd8VWUIB2vRdYz?(UW`Ir9ZT(AgZ&-dL UF{x!E8UO$Q07*qoM6N<$f|aX-IsgCw literal 0 HcmV?d00001 diff --git a/src/images/kani/defend_reverse-table-4.png b/src/images/kani/defend_reverse-table-4.png new file mode 100644 index 0000000000000000000000000000000000000000..ea970b38d56f86e55b45d354dabd023e2816b874 GIT binary patch literal 365 zcmV-z0h0cSP)Px$CrLy>R9Hvtn9&ZyAP7a<|NrPUK9~^-7A|6F>Ylbl=HYU&mh&k5ISaEL8xE~b zrgA?51?>X`8I>ptN5NVykO)xFgK`{f!!-pgKI&^)Rp@u4RsYK@WtBGTrIKLF!g1JT z%6ZE&y{ua1UNByEi+yf;@Ss_65Dcdq!69n(n9^|Y!Alj%QZ5CKAGDFuh5;pSNY6$T zGUUC?vWA<3!p&4nQrfLz56A|C{I>$mtr+)1rgEj>;Kq1GL-g!2${Q{#ZT*>mFqqcf zW#P(zNy>c!F61@s?0L;KoxVLGSElK2UlIiB!=-RsNzZS{gO;Gu;|T5Pp(VC-R^n}j zJ)iR`Ho81my!|*Ui2(6f%b;<%AC!?XgVJ!u9Q0+G%5Au?0_Y!H`nE(dz@rP{00000 LNkvXXu0mjf{4k-5 literal 0 HcmV?d00001 diff --git a/src/images/kani/defend_reverse-table-5.png b/src/images/kani/defend_reverse-table-5.png new file mode 100644 index 0000000000000000000000000000000000000000..b5fc32fe01fde88b75618acacdff31b910903916 GIT binary patch literal 442 zcmV;r0Y(0aP)Px$bV)=(R9HvdnBfk?AP9ul_kZXuW^o}D+rPD_pLdAbS?&d{D3=B|N_73)%O}rfs+?G}(`s7v3R!KkZ&^}2w@$Vq${|29M#J^O zd^?;3XcM&0g27+^IL}_)fVy7Nw3Gh*HnX1v- z)lBvZFstsl3qjAS8jRYuu7nFOict}Ur3V7Hh6^tYy$1q9ghOZrD|d*nVzY*sE0Px$tw}^dR9Hvlm{|_PAPhvC`yaYhsvq$+s#%a zfLSmr6s)8P>#TN#7hf!#Rw}!N^hgS)t9Jvm8aE0#6%K`nB!q0nP_Pn0!!fs_Lkt&TYeFH6bP_FXUzLebHkDLDS=srU!=|=c zMR`F6OUs(4Ve>W@9IGbv#-le}M#g|G=ehe5m+I`9!n@%weU6A;kfuN6cpboVU)F|@ z1cUnRUpyXK_f%^%_u>({eML<^dW-Ww&==3I!bM%kH3$@#pVe^j6!O*u3f2h=b_{h^ pXQA{_!h?XcE_wk8$cDmU`xm}Ao-wtvR1g3F002ovPDHLkV1g{<-ckSn literal 0 HcmV?d00001 diff --git a/src/images/kani/defend_reverse-table-7.png b/src/images/kani/defend_reverse-table-7.png new file mode 100644 index 0000000000000000000000000000000000000000..4627733b5843597d61f13c34fb2f4851506e697a GIT binary patch literal 525 zcmV+o0`mQdP)Px$$4Nv%R9HvdSX&Zyufn6jK-vivMk^o)@WIAz#)L@-_yXc ztU~dKz{cj073K6IjzU!7RaeUlqOeG7Zmim@Bq%WPoPo2lTeXyttd$IPLGRjE9Z$W$ zSX*3lvckVP8|g;Zt?vXED|~AbDE2b9!j7WSeKfeNZNVOUX3W_WFJgcVfk#i!_9G}xSyo!(6ap97%G#XzmvsiF ze={;YdXd8(-fYXnvNn55?5ct58dYkn^+K=?d#akT&?YIefefe$U^AB$*H&vp#iit_)&+E6S5R&>Gnj{D!NwN7zD@-4QTEQ73Zok=pPx$>`6pHR9HvdSkV%LAPk%T|IypI8(yhRlPWs4J?#`rNYhYQ9@_6|hArkldXA#n z@okKa*L??HxacFmMZnf+z77rnOW8xHTd?;240BoPQ(24x$Ks&$c}BZ9EU3y{6h|!< zIBpFZy{ta-;8b8ub6!U8=M`}4ct2?rv|!v2UwZC4uvFTY#vNy*{hJ zcD91jYCX6LCe%-|5y6U8z0!RB%&8+ za0MU()})e|_kzsRYq0_>?KD1t)|6%oc&9vb_9`Gho=wi!ea;FlWX^9<-(YXED%MS0 z2`(y%&O@(EYue?SRomj|3T1?CsO+)=*u{xVSe>joZc1=vP+kv5_fLhrsllm*0W~+; z-y%lK4E~IjwAGH(A7jfm0I3O&PVbS;A8ucFvG%_$({#-yJH0E0Tk$lM+MVXmk?xEJ zl}h#9c!y*9qoHyTj_yaIg(*BDWDsyOZ z#$ak=Y>SCjh|aod>f{#wE^t{B3o+aY4grK1ULzsAE12WTP5=M^07*qoM6N<$f_WwT AO8@`> literal 0 HcmV?d00001 diff --git a/src/util.lua b/src/util.lua index cb0facd..315c7f3 100644 --- a/src/util.lua +++ b/src/util.lua @@ -6,14 +6,18 @@ local geom = playdate.geometry util = {} --- creates a unit vector that "points" from point A to point B -function util.unitPointer(a, b) - return (b - a):normalized() -end - -- create a unit vector that points from x1, y1 to x2, y2 +-- alternately you can pass 2 playdate.geometry.point() objects instead function util.unitPointer(x1, y1, x2, y2) - local a = geom.point.new(x1, y1) - local b = geom.point.new(x2, y2) - return unitPointer(a,b) + local a = nil + local b = nil + if type(x1) == "number" then + a = geom.point.new(x1, y1) + b = geom.point.new(x2, y2) + else + a = x1 + b = y1 + end + + return (b-a):normalized() end