a'ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ ÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀÀ`t-- title: Pong -- author: RodrigoDornelles -- desc: made with gly engine 0.0.21 -- script: lua local tic80game = function() local function init(std, game) game.highscore = game.highscore or 0 game.player_pos = game.height/2 game.ball_pos_x = game.width/2 game.ball_pos_y = game.height/2 game.ball_spd_x = 50 game.ball_spd_y = 30 game.score = 0 end local function loop(std, game) -- moves game.ball_size = std.math.max(game.width, game.height) / 160 game.player_size = (std.math.min(game.width, game.height) / 8) + 2 game.ball_pos_x = std.math.clamp(game.ball_pos_x + (game.width * game.ball_spd_x * std.delta)/100000, 0, game.width) game.ball_pos_y = std.math.clamp(game.ball_pos_y + (game.height * game.ball_spd_y * std.delta)/100000, 0, game.height) game.player_pos = std.math.clamp(game.player_pos + (std.key.axis.y * game.ball_size), 0, game.height - game.player_size) -- colisions if game.ball_pos_x >= (game.width - game.ball_size) then game.ball_spd_x = -std.math.abs(game.ball_spd_x) end if game.ball_pos_y >= (game.height - game.ball_size) then game.ball_spd_y = -std.math.abs(game.ball_spd_y) end if game.ball_pos_y <= 0 then game.ball_spd_y = std.math.abs(game.ball_spd_y) end if game.ball_pos_x <= 0 then if std.math.clamp(game.ball_pos_y, game.player_pos, game.player_pos + game.player_size) == game.ball_pos_y then game.ball_spd_y = game.ball_spd_y + game.ball_spd_x - (std.milis % (game.ball_spd_x*2)) game.ball_spd_x = std.math.abs(game.ball_spd_x + (game.ball_spd_x/10)) game.score = game.score + 1 else std.app.reset() end end end local function draw(std, game) std.draw.clear(std.color.black) std.draw.color(std.color.white) std.draw.rect(0, game.ball_size, game.player_pos, game.ball_size, game.player_size) std.draw.rect(0, game.ball_pos_x, game.ball_pos_y, game.ball_size, game.ball_size) std.text.put(20, 1, game.score) std.text.put(60, 1, game.highscore) end local function exit(std, game) game.highscore = std.math.max(game.highscore, game.score) end local P = { meta={ title='Ping Pong', author='RodrigoDornelles', description='simple pong', version='1.0.0' }, callbacks={ init=init, loop=loop, draw=draw, exit=exit } } return P; end local tic80engine = function() local math = ((function() local x, y = pcall(require, 'math'); return x and y end)()) or _G.math local src_version_5630bfb01410 = nil local src_lib_engine_api_app_5630bfb08c80 = nil local src_lib_engine_api_key_5630bfb14660 = nil local src_lib_engine_api_math_5630bfb12d50 = nil local src_lib_engine_api_array_5630bfb125c0 = nil local src_lib_engine_draw_text_5630bfaedb60 = nil local src_lib_engine_draw_poly_5630bfb09000 = nil local src_lib_engine_raw_memory_5630bfb08090 = nil local src_lib_object_color_5630bfaff810 = nil local src_lib_object_std_5630bfafeb40 = nil local src_lib_util_lua_5630bfafb150 = nil local src_lib_util_decorator_5630bfb153d0 = nil local function main_5630bfacf130() local version = src_version_5630bfb01410() local engine_game = src_lib_engine_api_app_5630bfb08c80() local engine_key = src_lib_engine_api_key_5630bfb14660() local engine_math = src_lib_engine_api_math_5630bfb12d50() local engine_array = src_lib_engine_api_array_5630bfb125c0() local engine_draw_text = src_lib_engine_draw_text_5630bfaedb60() local engine_draw_poly = src_lib_engine_draw_poly_5630bfb09000() local engine_raw_memory = src_lib_engine_raw_memory_5630bfb08090() local color = src_lib_object_color_5630bfaff810() local std = src_lib_object_std_5630bfafeb40() local util_lua = src_lib_util_lua_5630bfafb150() local f=function(a,b)end local engine={keyboard=f} local application={ meta={title='', version=''}, data={width=1280,height=720}, config={offset_x=0,offset_y=0}, callbacks={loop=f,draw=f,exit=f,init=f} } std.log={fatal=f,error=f,warn=f,info=f,debug=f} std.bus={emit=f,emit_next=f,listen=f,listen_std_engine=f} std.i18n={next=f,back=f,get_language=function()return'en-US'end} local cfg_system={ exit=native_system_exit, reset=native_system_reset, title=native_system_title, get_fps=native_system_get_fps, get_secret=native_system_get_secret, get_language=native_system_get_language } local cfg_poly={ repeats={ native_cfg_poly_repeat_0 or false, native_cfg_poly_repeat_1 or false, native_cfg_poly_repeat_2 or false }, triangle=native_draw_triangle, poly2=native_draw_poly2, poly=native_draw_poly, line=native_draw_line } local cfg_text={ font_previous=native_text_font_previous } function native_callback_loop(dt) std.milis, std.delta=std.milis + dt, dt application.callbacks.loop(std, application.data) end function native_callback_draw() native_draw_start() application.callbacks.draw(std, application.data) native_draw_flush() end function native_callback_resize(width, height) application.data.width=width application.data.height=height std.app.width=width std.app.height=height end function native_callback_keyboard(key, value) engine.keyboard(std, engine, key, value) end function native_callback_init(width, height, game_lua) local ok, script=true, game_lua if type(script) == 'string' then ok, script=util_lua.eval(script) end if not script then ok, script=pcall(loadfile, 'game.lua') end if not ok or not script then error(script, 0) end std.app.width=width std.app.height=height script.data={width=width,height=height} script.config=application.config application=script std.draw.color=native_draw_color std.draw.font=native_draw_font std.draw.rect=native_draw_rect std.draw.line=native_draw_line std.draw.image=native_image_draw std.image.load=native_image_load std.image.draw=native_image_draw std.text.print=native_text_print std.text.mensure=native_text_mensure std.text.font_size=native_text_font_size std.text.font_name=native_text_font_name std.text.font_default=native_text_font_default std.draw.clear=function(tint) native_draw_clear(tint, 0, 0, application.data.width, application.data.height) end engine.root=application engine_raw_memory.install(std, engine) engine_game.install(std, engine, cfg_system) engine_key.install(std, engine, {}) engine_math.install(std, engine) engine_math.wave.install(std, engine) engine_math.clib.install(std, engine) engine_math.clib_random.install(std, engine) engine_array.install(std, engine, nil, 'array') engine_draw_text.install(std, engine, cfg_text) engine_draw_poly.install(std, engine, cfg_poly) color.install(std, engine) std.app.title(application.meta.title..' - '..application.meta.version) engine.current=application application.callbacks.init(std, application.data) end local P={ meta={ title='gly-engine-micro', author='RodrigoDornelles', description='shh!', version=version } } return P end src_version_5630bfb01410 = function() return '0.0.20' end -- src_lib_engine_api_app_5630bfb08c80 = function() local util_decorator = src_lib_util_decorator_5630bfb153d0() local function reset(std, engine) if std.node then std.bus.emit('exit') std.bus.emit('init') else engine.root.callbacks.exit(std, engine.root.data) engine.root.callbacks.init(std, engine.root.data) end end local function exit(std) std.bus.emit('exit') std.bus.emit('quit') end local function title(func, window_name) if func then func(window_name) end end local function install(std, engine, config) std = std or {} config = config or {} std.app = std.app or {} std.bus.listen('post_quit', function() if config.quit then config.quit() end end) std.app.title = util_decorator.prefix1(config.set_title, title) std.app.exit = util_decorator.prefix1(std, exit) std.app.reset = util_decorator.prefix2(std, engine, reset) std.app.get_fps = config.get_fps return std.app end local P = { install=install } return P end -- src_lib_engine_api_key_5630bfb14660 = function() local function real_key(std, engine, rkey, rvalue) local value = rvalue == 1 or rvalue == true local key = engine.key_bindings[rkey] or (std.key.axis[rkey] and rkey) if key then std.key.axis[key] = value and 1 or 0 std.key.press[key] = value if key == 'right' or key == 'left' then std.key.axis.x = std.key.axis.right - std.key.axis.left end if key == 'down' or key == 'up' then std.key.axis.y = std.key.axis.down - std.key.axis.up end std.bus.emit('key') end local a = std.key.axis std.key.press.any = (a.left + a.right + a.down + a.up + a.a + a.b + a.c + a.d + a.menu) > 0 end local function real_keydown(std, engine, key) real_key(std, engine, key, 1) end local function real_keyup(std, engine, key) real_key(std, engine, key, 0) end local function event_bus(std, engine) std.bus.listen_std_engine('rkey', real_key) std.bus.listen_std_engine('rkey1', real_keydown) std.bus.listen_std_engine('rkey0', real_keyup) end local function install(std, engine, key_bindings) engine.key_bindings = key_bindings or {} engine.keyboard = real_key end local P = { event_bus = event_bus, install = install } return P end -- src_lib_engine_api_math_5630bfb12d50 = function() local function abs(value) if value < 0 then return -value end return value end local function clamp(value, value_min, value_max) if value < value_min then return value_min elseif value > value_max then return value_max else return value end end local function clamp2(value, value_min, value_max) return (value - value_min) % (value_max - value_min + 1) + value_min end local function dir(value, alpha) alpha = alpha or 0 if value < -alpha then return -1 elseif value > alpha then return 1 else return 0 end end local function dis(x1,y1,x2,y2) local sqr = 1/2 return ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ (sqr ~= 0 and sqr or 1) end local function dis2(x1,y1,x2,y2) return (x2 - x1) ^ 2 + (y2 - y1) ^ 2 end local function dis3(x1,y1,x2,y2) return abs(x1 - x2) + abs(x2 - y2) end local function lerp(a, b, alpha) return a + alpha * ( b - a ) end local function map(value, in_min, in_max, out_min, out_max) return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min end local function max(...) local args = {...} local index = 1 local value = nil local max_value = nil if #args == 1 then args = args[1] end while index <= #args do value = args[index] if max_value == nil or value > max_value then max_value = value end index = index + 1 end return max_value end local function min(...) local args = {...} local index = 1 local value = nil local min_value = nil if #args == 1 then args = args[1] end while index <= #args do value = args[index] if min_value == nil or value < min_value then min_value = value end index = index + 1 end return min_value end local function sine(t, freq) return math.pi and math.sin(2 * math.pi * freq * t) or 1 end local function ramp(t, freq, ratio) t = (t / 2) % (1 / freq) * freq if t < ratio then return 2 * t / ratio - 1 else return (2 * t - ratio - 1) / (ratio - 1) end end local function saw(t, freq) return ramp(t, freq, 1) end local function triangle(t, freq) return ramp(t, freq, 1/2) end local function rect(t, freq, duty) duty = 1 - duty * 2 return saw(t, freq) > duty and 1 or -1 end local function square(t, freq) return rect(t, freq, 1/2) end local function install(std) std.math = std.math or {} std.math.abs=abs std.math.clamp=clamp std.math.clamp2=clamp2 std.math.dir=dir std.math.dis=dis std.math.dis2=dis2 std.math.dis3=dis3 std.math.lerp=lerp std.math.map=map std.math.max=max std.math.min=min end local function install_wave(std) std.math = std.math or {} std.math.sine=sine std.math.saw=saw std.math.square=square std.math.triangle=triangle end local function install_clib(std) std.math = std.math or {} std.math.acos=math.acos std.math.asin=math.asin std.math.atan=math.atan std.math.atan2=math.atan2 std.math.ceil=math.ceil std.math.cos=math.cos std.math.cosh=math.cosh std.math.deg=math.deg std.math.exp=math.exp std.math.floor=math.floor std.math.fmod=math.fmod std.math.frexp=math.frexp std.math.huge=math.huge std.math.ldexp=math.ldexp std.math.log=math.log std.math.log10=math.log10 std.math.modf=math.modf std.math.pi=math.pi std.math.pow=math.pow std.math.rad=math.rad std.math.sin=math.sin std.math.sinh=math.sinh std.math.sqrt=math.sqrt std.math.tan=math.tan std.math.tanh=math.tanh end local function install_clib_random(std) std.math = std.math or {} std.math.random = function(a, b) a = a and math.floor(a) b = b and math.floor(b) return math.random(a, b) end end local P = { install = install, wave = { install = install_wave }, clib = { install = install_clib }, clib_random = { install = install_clib_random } } return P; end -- src_lib_engine_api_array_5630bfb125c0 = function() local util_decorator = src_lib_util_decorator_5630bfb153d0() local function array_map(array, func) local res = {} local index = 1 local length = #array while index <= length do res[#res + 1] = func(array[index], index) index = index + 1 end return res end local function array_filter(array, func) func = func or (function(v) return v and v ~= 0 end) local res = {} local index = 1 local length = #array while index <= length do local value = array[index] if func(value, index) then res[#res + 1] = value end index = index + 1 end return res end local function array_unique(array) local res = {} local index = 1 local length = #array local setmap = {} while index <= length do local value = array[index] if not setmap[value] then res[#res + 1] = value end setmap[value] = true index = index + 1 end return res end local function array_foreach(array, func) local index = 1 local length = #array while index <= length do func(array[index], index) index = index + 1 end end local function array_reducer(array, func, value) local index = value and 1 or 2 local length = #array value = value or array[1] while index <= length do value = func(value, array[index], index) index = index + 1 end return value end local function array_index(array, func, reverse) func = func or function() return true end local index, inc, final = 1, 1, #array if reverse then index, inc, final = #array, -1, 1 end repeat if func(array[index], index) then return index end index = index + inc until (reverse and index < final) or (not reverse and index > final) return nil end local function array_first(array, func) local index = array_index(array, func) if index then return array[index] end return nil end local function array_last(array, func) local index = array_index(array, func, true) if index then return array[index] end return nil end local function array_some(array, func, reverse) local index, inc, final = 1, 1, #array if reverse then index, inc, final = #array, -1, 1 end repeat if func(array[index], index) then return true end index = index + inc until (reverse and index < final) or (not reverse and index > final) return false end local function array_every(array, func) local index = 1 local length = #array while index <= length do if not func(array[index], index) then return false end index = index + 1 end return true end local function array_pipeline(std, array) local decorator_iterator = function(func) return function(self, func2, extra) self.array = func(self.array, func2, extra) return self end end local decorator_reduce = function(func, return_self) return function(self, func2, extra) local res = func(self.array, func2, extra) return (return_self and self) or res end end local self = { array = array, map = decorator_iterator(array_map), filter = decorator_iterator(array_filter), unique = decorator_iterator(array_unique), each = decorator_reduce(array_foreach, true), reducer = decorator_reduce(array_reducer), index = decorator_reduce(array_index), first = decorator_reduce(array_first), last = decorator_reduce(array_last), some = decorator_reduce(array_some), every = decorator_reduce(array_every), table = function(self) return self.array end, json = function(self) return std.json.encode(self.array) end } return self end local function install(std, engine, library, name) local lib = std[name] or {} lib.map = array_map lib.filter = array_filter lib.unique = array_unique lib.each = array_foreach lib.reducer = array_reducer lib.index = array_index lib.first = array_first lib.last = array_last lib.some = array_some lib.every = array_every lib.from = util_decorator.prefix1(std, array_pipeline) std[name] = lib end local P = { install = install } return P end -- src_lib_engine_draw_text_5630bfaedb60 = function() local util_decorator = src_lib_util_decorator_5630bfb153d0() local function text_put(std, engine, font_previous, pos_x, pos_y, text, size) size = size or 2 local hem = engine.current.data.width / 80 local vem = engine.current.data.height / 24 local font_size = hem * size std.text.font_default(0) std.text.font_size(font_size) std.text.print(pos_x * hem, pos_y * vem, text) font_previous() end local function text_print_ex(std, engine, x, y, text, align) local w, h = std.text.mensure(text) local aligns = {w, w/2, 0} std.text.print(x - aligns[(align or 1) + 2], y, text) return w, h end local function install(std, engine, config) std.text.print_ex = util_decorator.prefix2(std, engine, text_print_ex) std.text.put = util_decorator.prefix3(std, engine, config.font_previous, text_put) end local P = { install=install } return P end -- src_lib_engine_draw_poly_5630bfb09000 = function() local function decorator_poo(object, func) if not object or not func then return func end return function(a, b, c, d) return func(object, a, b, c, d) end end local function decorator_line(func_draw_line) return function(mode, verts) local index = 4 while index <= #verts do func_draw_line(verts[index - 3], verts[index - 2], verts[index - 1], verts[index]) index = index + 2 end end end local function decorator_triangle(func_draw_poly, std, func_draw_triangle) if not func_draw_triangle then return func_draw_poly end local point = function(x, y, px, py, scale, angle, ox, oy) local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle)) local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle)) return xx, yy end return function(engine_mode, verts, x, y, scale, angle, ox, oy) if #verts ~= 6 then return func_draw_poly(engine_mode, verts, x, y, scale, angle, ox, oy) end ox = ox or 0 oy = oy or ox or 0 local x1, y1 = point(x, y, verts[1], verts[2], scale, angle, ox, oy) local x2, y2 = point(x, y, verts[3], verts[4], scale, angle, ox, oy) local x3, y3 = point(x, y, verts[5], verts[6], scale, angle, ox, oy) return func_draw_triangle(engine_mode, x1, y1, x2, y2, x3, y3) end end local function decorator_poly(func_draw_poly, std, modes, repeats) local func_repeat = function(verts, mode) if repeats and repeats[mode + 1] then verts[#verts + 1] = verts[1] verts[#verts + 1] = verts[2] end end return function (engine_mode, verts, x, y, scale, angle, ox, oy) if #verts < 6 or #verts % 2 ~= 0 then return end local mode = modes and modes[engine_mode + 1] or engine_mode local rotated = std.math.cos and angle and angle ~= 0 ox = ox or 0 oy = oy or ox or 0 if x and y and not rotated then local index = 1 local verts2 = {} scale = scale or 1 while index <= #verts do if index % 2 ~= 0 then verts2[index] = x + (verts[index] * scale) else verts2[index] = y + (verts[index] * scale) end index = index + 1 end func_repeat(verts2, engine_mode) func_draw_poly(mode, verts2) elseif x and y then local index = 1 local verts2 = {} while index < #verts do local px = verts[index] local py = verts[index + 1] local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle)) local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle)) verts2[index] = xx verts2[index + 1] = yy index = index + 2 end func_repeat(verts2, engine_mode) func_draw_poly(mode, verts2) else func_draw_poly(mode, verts) end end end local function decorator_position(engine, func) return function(mode, verts, pos_x, pos_y, scale, angle, ox, oy) local x = engine.current.config.offset_x + (pos_x or 0) local y = engine.current.config.offset_y + (pos_y or 0) ox = ox or 0 oy = ox or oy or 0 scale = scale or 1 angle = angle or 0 return func(mode, verts, x, y, scale, angle, ox, oy) end end local function install(std, engine, config) local draw_line = decorator_poo(config.object, config.line) local draw_poly = decorator_poo(config.object, config.poly) or decorator_line(draw_line) local draw_poly2 = config.poly2 or decorator_poly(draw_poly, std, config.modes, config.repeats) local draw_verts = decorator_triangle(draw_poly2, std, config.triangle) std.draw.poly = decorator_position(engine, draw_verts) end local P = { install=install } return P end -- src_lib_engine_raw_memory_5630bfb08090 = function() local memory_dict_unload = {} local memory_dict = {} local memory_list = {} local function cache_get(key) return memory_dict[key] end local function cache_set(key, load_func, unload_func) local value = load_func() memory_list[#memory_list + 1] = key memory_dict_unload[key] = unload_func memory_dict[key] = value end local function cache(key, load_func, unload_func) local value = cache_get(key) if value == nil then cache_set(key, load_func, unload_func) value = cache_get(key) end return value end local function unset(key) if memory_dict_unload[key] then memory_dict_unload[key](memory_dict[key]) end memory_dict[key] = nil end local function gc_clear_all() local index = 1 local items = #memory_list while index <= items do unset(memory_list[index]) index = index + 1 end memory_list = {} return items end local function install(std) std = std or {} std.mem = std.mem or {} std.mem.cache = cache std.mem.cache_get = cache_get std.mem.cache_set = cache_set std.mem.unset = unset std.mem.gc_clear_all = gc_clear_all return { mem=std.mem } end local P = { install=install } return P end -- src_lib_object_color_5630bfaff810 = function() local function install(std) std.color = std.color or {} std.color.white = 0xFFFFFFFF std.color.lightgray = 0xC8CCCCFF std.color.gray = 0x828282FF std.color.darkgray = 0x505050FF std.color.yellow = 0xFDF900FF std.color.gold = 0xFFCB00FF std.color.orange = 0xFFA100FF std.color.pink = 0xFF6DC2FF std.color.red = 0xE62937FF std.color.maroon = 0xBE2137FF std.color.green = 0x00E430FF std.color.lime = 0x009E2FFF std.color.darkgreen = 0x00752CFF std.color.skyblue = 0x66BFFFFF std.color.blue = 0x0079F1FF std.color.darkblue = 0x0052ACFF std.color.purple = 0xC87AFFFF std.color.violet = 0x873CBEFF std.color.darkpurple = 0x701F7EFF std.color.beige = 0xD3B083FF std.color.brown = 0x7F6A4FFF std.color.darkbrown = 0x4C3F2FFF std.color.black = 0x000000FF std.color.blank = 0x00000000 std.color.magenta = 0xFF00FFFF end local P = { install = install } return P end -- src_lib_object_std_5630bfafeb40 = function() local P = { milis = 0, delta = 0, math = { }, draw = { image = function() end, clear = function () end, color = function () end, rect = function () end, line = function () end, poly = function () end, tui_text = function() end }, text = { put = function() end, print = function() end, mensure = function() end, font_size = function() end, font_name = function() end, font_default = function() end }, image = { load = function() end, draw = function() end }, app = { width = 1280, height = 720, title = function() end, reset = function () end, load = function() end, exit = function () end }, key = { axis = { x = 0, y = 0, menu=0, up=0, down=0, left=0, right=0, a = 0, b = 0, c = 0, d = 0 }, press = { menu=false, up=false, down=false, left=false, right=false, a=false, b=false, c=false, d=false, any=false } } } return P; end -- src_lib_util_lua_5630bfafb150 = function() local function has_support_utf8() if jit then return true end if tonumber(_VERSION:match('Lua 5.(%d+)')) >= 3 then return true end return false end local function eval(script) local loader = loadstring or load if not loader then error('eval not allowed') end local ok, chunk = pcall(loader, script) if not ok then return false, chunk end if type(chunk) ~= 'function' then return false, 'failed to eval' end return pcall(chunk) end local P = { eval = eval, has_support_utf8=has_support_utf8 } return P end -- src_lib_util_decorator_5630bfb153d0 = function() local function decorator_prefix3(zig, zag, zom, func) return function (a, b, c, d, e, f) return func(zig, zag, zom, a, b, c, d, e, f) end end local function decorator_prefix2(zig, zag, func) return function (a, b, c, d, e, f) return func(zig, zag, a, b, c, d, e, f) end end local function decorator_prefix1(zig, func) return function (a, b, c, d, e, f) return func(zig, a, b, c, d, e, f) end end local function decorator_offset_xy2(object, func) return function(a, b, c, d, e, f) local x = object.offset_x + (b or 0) local y = object.offset_y + (c or 0) return func(a, x, y, d, e, f) end end local function decorator_offset_xyxy1(object, func) return function(a, b, c, d, e, f) local x1 = object.offset_x + a local y1 = object.offset_y + b local x2 = object.offset_x + c local y2 = object.offset_y + d return func(x1, y1, x2, y2, e, f) end end local function decorator_offset_xy1(object, func) return function(a, b, c, d, e, f) local x = object.offset_x + a local y = object.offset_y + b return func(x, y, c, d, e, f) end end local function table_prefix1(prefix, fn_table) local new_table = {} for name, fn in pairs(fn_table) do new_table[name] = decorator_prefix1(prefix, fn) end return new_table end local P = { offset_xy1 = decorator_offset_xy1, offset_xy2 = decorator_offset_xy2, offset_xyxy1 = decorator_offset_xyxy1, prefix3 = decorator_prefix3, prefix2 = decorator_prefix2, prefix1 = decorator_prefix1, prefix1_t = table_prefix1 } return P end -- return main_5630bfacf130() end local started = false local current_color = 12 local font_size, font_previous = 5, 5 local delta, last = 0, time() local keypress = {} local keymap = { 'up', 'down', 'left', 'right', 'a', 'b', 'c', 'd' } local colormap = { [0x000000] = 0, [0x1A1C2C] = 0, [0xFF00FF] = 1, [0xFF6DC2] = 1, [0xC87AFF] = 1, [0x701F7E] = 1, [0x873CBE] = 1, [0x5D275D] = 1, [0xFF0000] = 2, [0xE62937] = 2, [0xBE2137] = 2, [0xB13E53] = 2, [0xFFA100] = 3, [0xFFCB00] = 3, [0xEF7D57] = 3, [0xFDF900] = 4, [0xFFCD75] = 4, [0x00E430] = 5, [0xA7F070] = 5, [0x009E2F] = 6, [0x38B764] = 6, [0x00752C] = 7, [0x38B764] = 7, [0x0052AC] = 8, [0x29366F] = 8, [0x0000FF] = 9, [0x3B5DC9] = 9, [0x0079F1] = 10, [0x41A6F6] = 10, [0x66BFFF] = 11, [0x73EFF7] = 11, [0xFFFFFF] = 12, [0xF4F4F4] = 12, [0xC8CCCC] = 13, [0x94B0C2] = 13, [0xD3B083] = 13, [0x828282] = 14, [0x566C86] = 14, [0x7F6A4F] = 14, [0x505050] = 15, [0x333C57] = 15, [0x4C3F2F] = 15 } local function colorid(c) local colornew = colormap[c>>8] if not colornew then local r,g,b = (c>>24) & 255, (c>>16) & 255, (c>>8) & 255 local best,d = nil, math.huge for k,v in pairs(colormap) do local kr,kg,kb = (k>>16)&255, (k>>8)&255, k&255 local dist = ((r-kr)^2 + (g-kg)^2 + (b-kb)^2) if dist < d then d,best = dist,v end end colornew = best end return colornew end function native_draw_start() end function native_draw_flush() end function native_draw_clear(c) cls(colorid(c)) end function native_draw_color(c) current_color = colorid(c) end function native_draw_line(x1, y1, x2, y2) line(x1, y1, x2, y2, current_color) end function native_draw_rect(mode, x, y, w, h) if mode == 0 then rect(x, y, w, h, current_color) else local x2, y2 = x + w, y + h line(x, y, x2, y, current_color) line(x2 , y, x2, y2, current_color) line(x , y2, x2, y2, current_color) line(x , y, x, y2, current_color) end end function native_text_font_previous() font_size, font_previous = font_previous, font_size end function native_text_font_default() end function native_text_font_name() end function native_text_font_size(n) font_size = math.ceil(n/5) if font_size < 1 then font_size = 1 end end function native_text_mensure(text) local s = font_size * 5 local t = tostring(text) local a = #t > 1 and 1 or 0 return #t * (a + s), s end function native_text_print(x, y, t) print(tostring(t), x, y, current_color, true, font_size) end native_cfg_poly_repeat_0 = true native_cfg_poly_repeat_1 = true tic80engine = tic80engine() tic80game = tic80game() function TIC() if not started then started = true if tic80engine and type(tic80engine) == 'table' and tic80engine.meta and tic80engine.meta.title then trace('engine: '..tic80engine.meta.title..' '..tostring(tic80engine.meta.version)) end if tic80game and type(tic80game) == 'table' and tic80game.meta and tic80game.meta.title then trace('game: '..tic80game.meta.title..' '..tostring(tic80game.meta.version)) end native_callback_init(240, 136, tic80game) else do local now = time() delta = now - last last = now end do local index = 1 while index <= #keymap do local keyname = keymap[index] local pressed = btn(index - 1) if not keypress[index] and pressed then keypress[index] = true native_callback_keyboard(keyname, pressed) elseif keypress[index] and not pressed then keypress[index] = false native_callback_keyboard(keyname, pressed) end index = index + 1 end end native_callback_loop(delta) native_callback_draw() end end