best score: 17. I love the visuals! like a nice purple quilt
and you’ve nerdsniped me; here have some sizecoding tips:
-
a!=x and b!=y
becomesa-x|b-y!=0
(basically, check thata-x
andb-x
both don’t have any bits set, i.e. both are zero) This can save a few chars in 3 different places -
enemy movement: If you want them to only move in 4 directions, this should do it:
R=rnd(4)\1/4
j.x+=cos(R)
j.y+=sin(R)
(costs 12 chars ish)
-
stop()
can berun()
, saving a char. this makes the game autorestart instead of freezing – might be nicer? hard to see your score tho -
you can save some chars in init with temporary vars:
for i=1,5do repeat A=r(8)\1B=r(8)\1until A-x|B-y!=0e[i]={x=A,y=B}end m()end
-
input code:
::m::
-- TODO delete m() and put the code inside it here
repeat
flip()
v=btnp()
until v>0
x+=v\2%2-v%2 --extract the x bits
y+=v\8%2-v\4%2 --extract the y bits
goto m
Its arcane but it works! it will let the player move diagonally tho. I also have an incredibly cursed snippet for 4-way movement if you prefer
- goto – I agree with Kamencesc, I think you can remove all functions from this cart and use
goto
instead
“Can you explain more about how goto works?” ummm let’s see, basically these two carts are equivalent:
function _draw()
--stuff
end
and
::d::
--stuff
flip()
goto d
searching for “lua goto” might help too.
I don’t know how to explain it succinctly, but here’s an example where I used multiple goto/labels to have an “init” phase and a “draw” phase, sorta like what you have here.