revise this code function init() appstate = mktitlest() end function update()…
- User
revise this code function _init() app_state = mk_title_st() end
function _update() app_state:update() end
function _draw() cls() app_state:draw() end -->8 --title state
function mk_title_st() local st = {} --state
codefunction st:update() end function st:draw() local t -- title local lp -- line position local lp_tbl local ctp_opt t={ "cabin jam 2024 project", "bingo", "jammo" } ctp_opt = { x=0, y=0, w=128, h=128 }-- lp=cent_txt_pos(t,ctp_opt) lp_tbl=cent_txt_tbl_pos(t,ctp_opt) for i, lp in ipairs(lp_tbl) do print(t[i],lp[1],lp[2]) end end
codereturn stend -->8 --utilities
----- constants ----- const={ letter_width=4, letter_height=6, line_height=8 }
----- text -----
--center text position --(line of text, options) --desc: --provides the x and y --coordinates to print a --line of text in the center --of a given space function cent_txt_pos(txt,opt) --opt { -- x, x position of space -- y, y position of space -- w, width of space -- h height of space --) local x=opt.x local y=opt.y local w=opt.w local h=opt.h
codelocal cent_x local cent_y cent_x=cent_txt_x(txt,x,w) cent_y=cent_txt_y(tst,y,h) return{cent_x,cent_y}end
--center text table position --(table of text lines, options) --desc: --provides the x and y --coordinates to print a set of --lines of text in the center --of a given space function cent_txt_tbl_pos(txt,opt) --opt { -- x, x position of space -- y, y position of space -- w, width of space -- h height of space --) local x=opt.x local y=opt.y local w=opt.w local h=opt.h
codelocal cent_pos --center positions local cent_y local lh = const.line_height cent_y=cent_txt_tbl_y(txt,y,h) cent_pos={} for i, txt_l in ipairs(txt) do local cent_x local ly_off--line y offset cent_x=cent_txt_x(txt_l,x,w) ly_off=(i-1)*lh add( cent_pos, {cent_x,cent_y+ly_off} ) end return cent_pos - Assistant