Skip to content

Instantly share code, notes, and snippets.

@pancelor
Last active May 24, 2024 02:26
Show Gist options
  • Save pancelor/7e43d62bcf4bb757f454eecebbbd897b to your computer and use it in GitHub Desktop.
Save pancelor/7e43d62bcf4bb757f454eecebbbd897b to your computer and use it in GitHub Desktop.

Play here: https://pancelor.itch.io/make-ten

Here are three versions of the code:

  • 10-maketen-min.lua: the <500 character jam entry
  • 20-maketen-commented.lua: a commented version of min.lua
  • 30-maketen-workspace.lua: this is the main file I edited while working on the game. (I ran it through shrinko8 to rename vars and remove comments/spaces to get my final cart)

This is actually a slightly older version of the code -- the version on itch has a pause indicator and a very cursed timer rectangle. (it looks fine, but the code is cursed). It still fits in 500 characters (499!), I just haven't bothered to update these commented versions

z={}c=-8s=0g='⁶!5f58⁵d8"◝'::_::?"⁶1⁶c0⁶!5f2d3"
e=1x=stat(32)y=stat(33)if btn(5)do f=mid(16,96,y)if(btnp(5))p=x q=f?"⁷i6v1c1"
😐=c&min(x,p)⌂=c&min(f,q)♪=c&max(x,p)♥=c&max(f,q)elseif p do p=a if(n==c)e=0?"⁷i7f1a"
end?g,d
n=2for i=32,207do w=z[i]or rnd(9)\1+1u=i%16*8v=c&i\2if(u-😐|♪-u|v-⌂|♥-v>0)w*=e n-=w ⬅️+=➡️&~e
z[i]=w?w,u,v,w
end?"⁶jc1ᶜcscore "..s
if(p)rect(😐,⌂,♪+9,♥+8)
d=128-t()rectfill(-1,107,d,113)if(d==0)➡️=0g="⁶j8rtime up!"?"⁷v3fg"
if(s<⬅️)s+=1?"⁷x5v3c0"
?"⁶.¹³⁷ᶠ³⁴\0\0",x-2,y-2,7
goto _
-- setup board(z) and visible score(s). c: useful for tile-snapping. g: see later
z={}c=-8s=0g='⁶!5f58⁵d8"◝'
-- start of frame: flip(), cls(), enable mouse
::_::?"⁶1⁶c0⁶!5f2d3"
-- e=1 (don't delete nums). get mouse xy
e=1x=stat(32)y=stat(33)
-- on click or hold
if btn(5)do
-- clamp y inside play area. on click start, set coords for click (p/q) and play sfx
f=mid(16,96,y)if(btnp(5))p=x q=f?"⁷i6v1c1"
-- update selection box - between (😐,⌂) and (♪,♥) (see rect() call later)
😐=c&min(x,p)⌂=c&min(f,q)♪=c&max(x,p)♥=c&max(f,q)
elseif p do
-- on release, set p=nil and check if sum(n) has changed by 10 last frame. if so, e=0 (delete nums) and play sfx
p=a if(n==c)e=0?"⁷i7f1a"
end
-- during game: wide font, offset prints by 2,2, and disable button repeat. after game: print "time up!"
-- (why offset by 2,2? to make the selection box top-left corner a multiple of 8, while still being able to prints nums at multiples of 8)
?g,d
-- init sum. note: instead of counting from 0 to 10, count from 2 down to -8
n=2
for i=32,207do
-- get or generate num(w). get pixel coords(u,v)
w=z[i]or rnd(9)\1+1u=i%16*8v=c&i\2
-- if num is inside selection: zero it iff e==0, add it to sum, and add 1 to underlying score(⬅️)
if(u-😐|♪-u|v-⌂|♥-v>0)w*=e n-=w ⬅️+=➡️&~e
-- store num; show num
z[i]=w?w,u,v,w
end
-- print score
?"⁶jc1ᶜcscore "..s
-- show selection rect
if(p)rect(😐,⌂,♪+9,♥+8)
-- 128s timer. when done, disable score gain, overwrite g, and play sfx
d=128-t()rectfill(-1,107,d,113)if(d==0)➡️=0g="⁶j8rtime up!"?"⁷v3fg"
-- tick up visible score to match underlying score, with sfx
if(s<⬅️)s+=1?"⁷x5v3c0"
-- draw mouse
?"⁶.¹³⁷ᶠ³⁴\0\0",x-2,y-2,7
goto _
if false then
--[[rename::⬅️]]sc=0
--[[rename::😐]]cx0=0
--[[rename::⌂]]cy0=0
--[[rename::♪]]cx1=0
--[[rename::♥]]cy1=0
--[[rename::z]]z=nil
--[[rename::s]]vs=nil
--[[rename::n]]sum=nil
--[[rename::d]]tm=nil
--[[rename::e]]rm=nil
--[[rename::x]]mx=nil
--[[rename::y]]my=nil
-- [[rename::f]]my2=nil
--[[rename::p]]x0=nil
--[[rename::q]]y0=nil
--[[rename::w]]av=nil
--[[rename::u]]x=nil
--[[rename::v]]y=nil
--[[rename::c]]_8=nil
--[[rename::g]]prt=nil
--[[rename::a]]nil2=nil
end
-- srand(1284)
z={}_8=-8vs=0
prt="\^!5f58\x05\x64\x38\x22\xff" --no btn repeat + print attrs: default wide, (normal width/heights), offset printing by (2,2), !! no btnp repeat
::--[[rename::_]]_::
?'\^1\^c0\^!5f2d3'
rm=1 --1 dont remove, 0 remove
mx=stat(32) --after flipcls, and after mouse-poke
my=stat(33)
if btn(5) do
my2=mid(16,96,my) -- edit my right before we throw it away (later in this if)
-- if (btn(5) and x0==0)... (note: awkward when you literally click at x=0)
if (btnp(5)) x0=mx y0=my2 ?"\ai6v1c1" --start click
--
-- continue dragging
cx0=_8&min(mx,x0)
cy0=_8&min(my2,y0)
cx1=_8&max(mx,x0)
cy1=_8&max(my2,y0)
elseif x0 do
-- released mouse
x0=nil2
if (sum==_8) rm=0?"\ai7f1a"
-- this comment is required; https://www.lexaloffle.com/bbs/?tid=142148
-- (not required post-shrinko8 b/c the comments/whitespace are removed)
end?prt,tm
-- pqn(cx0,cy0,cx1,cy1,x0,y0)
-- calculate sum / remove numbers
sum=2 -- count down from 2 to -8
for --[[rename::i]]i=32,207do
av=z[i]or rnd(9)\1+1 --randomize map area
x=i%16*8
--y=i\16*8
y=_8 & i\2
-- if x-cx0|cx1-x|y-cy0|cy1-y|av-1>0 do --fruitbox scoring
if x-cx0|cx1-x|y-cy0|cy1-y>0 do
av*=rm
-- sc-=rm-1 --last char free b.c digit (but no good anymore b/c no overtime prevention)
sum-=av
-- ➡️ rm | sc+=
----------------
-- 1 1 | 0
-- 1 0 | 1
-- 0 1 | 0
-- 0 0 | 0
sc+=➡️&~rm
end
z[i]=av
?av,x,y,av
end?'\^jc1\fcscore '..vs
-- selection ants
if(x0) rect(cx0,cy0,cx1+9,cy1+8) --brittle: color from score
--timer
tm=128-t() -- 125
rectfill(-1,107,tm,113) --brittle: color from score
if(tm==0)➡️=0prt="\^j8rtime up!"?"\av3fg"
--
--score
if(vs<sc)vs+=1?"\ax5v3c0"
--
-- \^.ᶠᶠ⁷⁷³³¹¹ -- corner triangle
-- \^.¹¹³³⁷⁷ᶠᶠ -- mouse-ish triangle
-- \^.¹³⁷ᶠ³⁴\0\0 -- og mouse -- nulls costs 2 extra
?'\^.¹³⁷ᶠ³⁴\0\0',mx-2,my-2,7 --mouse
-- pset(mx,my,8)
-- if (btnp(6)) run() --anticheat - pause = reroll
-- nil3=btnp(6)and run()
-- if btnp(4) then sc+=100 end --check that score right before timeout counts
-- do_toast() -- pqn
goto _
--[[ (old?) psuedocode
score = 0
make random map, each cell 1-9
loop:
if from:
if not click:
-- release
sum = 0
elseif click:
from = mouse
for x,y,val in map:
draw val --including 0, but 0 adds 0 to score and is color 0, so it's fine
if x,y inside (from,mouse) and val>0:
if sum:
sum += val
if rm:
mset(x,y,0)
score += 1
if rm:
rm,from = nil
if sum:
rm = sum==10 -- rm 0: remove rm 1: dont remove
sum = nil
draw mouse
draw fence
draw score
]]
--[[ new loop, to fix mobile clicking
need both:
compute sum
move mouse
//flip
delete og area, not new area
move mouse
click immediately (mobile)
//flip
select starting from new mouse, not old mouse
::_::
del=false
if btn then
mx,my = mouse()
my2 = clamp my
if (btnp) x0,y0 = mx,my2
cx0 ... cy1 = min/max(mx/my2/x0/y0)
else
if x0 then
x0=nil
if (sum==10) del=true
end
end
remove nums in bounds iff del is true (rm==0)
sum=...
goto _
--]]
--[[ (old) timeline
frame# event start vars mid loop end vars
----------------------------------------------------------------------
n click cl=1 x0 cxy=old cxy
n+1 release cl=0 x0 cxy sum=0 sum=10 rm
n+2 cl=0 [x0] cxy sum=0 rm (mset)
ahhh need to set x0 nil later b/c it resets sum on the rm loop...
bug: can change selection after rm has been set... (fixed? can't trigger it)
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment