From 2b3855f2e4933a6965ff8c258429fc6a56a08f5a Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 24 Apr 2023 20:20:49 -0700 Subject: [PATCH] Res: Add a bouncing logo demo script --- res/scripts/logo-bounce.lua | 44 ++++++++++++++++++++++++++++++++++++ res/scripts/logo.png | Bin 0 -> 1217 bytes 2 files changed, 44 insertions(+) create mode 100644 res/scripts/logo-bounce.lua create mode 100644 res/scripts/logo.png diff --git a/res/scripts/logo-bounce.lua b/res/scripts/logo-bounce.lua new file mode 100644 index 000000000..c8192638c --- /dev/null +++ b/res/scripts/logo-bounce.lua @@ -0,0 +1,44 @@ +math.randomseed(os.time()) +local state = {} +state.logo = image.load(script.dir .. "/logo.png") +state.overlay = canvas:newLayer(state.logo.width, state.logo.height) +state.overlay.image:drawImageOpaque(state.logo, 0, 0) +state.x = math.random() * (canvas:screenWidth() - state.logo.width) +state.y = math.random() * (canvas:screenHeight() - state.logo.height) +state.direction = math.floor(math.random() * 3) +state.speed = 0.5 + +state.overlay:setPosition(math.floor(state.x), math.floor(state.y)) +state.overlay:update() + +function state.update() + if state.direction & 1 == 1 then + state.x = state.x + 1 + if state.x > canvas:screenWidth() - state.logo.width then + state.x = (canvas:screenWidth() - state.logo.width) * 2 - state.x + state.direction = state.direction ~ 1 + end + else + state.x = state.x - 1 + if state.x < 0 then + state.x = -state.x + state.direction = state.direction ~ 1 + end + end + if state.direction & 2 == 2 then + state.y = state.y + 1 + if state.y > canvas:screenHeight() - state.logo.height then + state.y = (canvas:screenHeight() - state.logo.height) * 2 - state.y + state.direction = state.direction ~ 2 + end + else + state.y = state.y - 1 + if state.y < 0 then + state.y = -state.y + state.direction = state.direction ~ 2 + end + end + state.overlay:setPosition(math.floor(state.x), math.floor(state.y)) +end + +callbacks:add("frame", state.update) diff --git a/res/scripts/logo.png b/res/scripts/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..b986e7597a288642bed747211651d629aad7cfe2 GIT binary patch literal 1217 zcmV;y1U~zTP)6L+p=2uCI$)5R!OASy_}9q*p!LD&K39h^Pedw1XO^Ld`CKHk61;B$jLLSM*SCqSHj9 zM5dnZfpeJ&x|`%++(V zZ5(V%CZZmq2BLRUqe|n_Rpp*b0^lNr!`3#Hd56N=eG~j14Tsz>8PNf`(1yLgEU^8> zC-q%zSCzH_X0CJILV8d}#w)0=uSZr^7X1DFA(2QR5{a?O*%Rv?4rEaA^0#dQ7#c60 z!_4R++D+uP7(gL(@KI&h`Fz#f!nkL4qoAMwmSbdO1kKIOC@LyKTwEMnU0n%~2-1~q z3~1{{9!a6a^8k3IfM2@@S}eBthlpEv0~cR?;V_$hJ?&GrP_a1^`T6;0z(Zo>FuZ!1|cZLz$8i1~;pH@W(B)~r?1^L|C;(hE1m4Wavi06PcXv(Uo|+6a|nQf zhduGKP3O#rKQQ|5_~dWIyhW6%EIqZ*VDq}|NK8z02!MQ71o~<1hUkf-Mk6sdTFnC# zAT~DEA%K{e7;N!<)-FJeaJqw-{~{uJKGkxf@$+^BtWQ8tP>@3aa=Cmi60#BxvQVV| z-^ncM|gs8p>kw;*13uBK&tiDwU$Ku@RG#lgk2-$z&{hzO|zcG`d>P z^ss%0|Gv%U3v<3;&$X3?3p7EoWS~~-9waX-iOiH*6Iz0mD;{Er#@*eWWkZ9(fT^h| zy8vEZUU+H|Ae|GTfd1C(aytJ4WB`C<`Rcb&( ziDo$pF)I%b4`gO$qN%9~lC?fmW+UZEYV*EDRVq~}@Wilp zwl=Ks+yb#!vIvBV7OLRjV5Fp^uxD%Oc%ja>{C<`I=xo+%+WqhmGy;-XIsQL8T-r4gm>kkU@0*cONPl^SaER!u^q5Nhf#UD$ ft_=)rpI!4G(XC=y#0#gu00000NkvXXu0mjfBR@;6 literal 0 HcmV?d00001