me.fier.engine/mods/main/script/main.lua

64 lines
1.5 KiB
Lua
Raw Normal View History

2023-05-16 10:29:12 +00:00
function main()
math.randomseed(os.time())
2023-06-12 14:05:07 +00:00
window = engine_window_create(96,64,"Game")
2023-05-16 10:29:12 +00:00
texture = engine_texture_create(8,8)
2023-06-12 14:05:07 +00:00
engine_rendertarget_set(texture)
engine_rendertarget_draw_file(bp("texture/fier.rgba"))
2023-06-13 05:33:55 +00:00
engine_rendertarget_set(engine_window_texture_get(window))
2023-05-16 10:29:12 +00:00
while true do
event = engine_event_get()
eventData = {engine_lua_event_get_data(event)}
if eventData[1] ~= ENGINE_EVENT_TYPE_NONE then
handleEvent(event,eventData)
else
tick()
end
engine_event_free(event)
end
end
lastFrame = 0
function tick()
2023-06-13 05:33:55 +00:00
engine_rendertarget_draw_texture(texture,math.random(-8,104),math.random(-8,72))
2023-06-12 14:05:07 +00:00
engine_window_present(window)
2023-05-16 10:29:12 +00:00
trackFps()
local curFrame = engine_time_get()
local wait = 16 - (curFrame - lastFrame)
if wait > 0 then engine_time_sleep(wait) end
lastFrame = engine_time_get()
end
function handleEvent(event,eventData)
if eventData[1] == ENGINE_EVENT_TYPE_EXIT then
os.exit()
end
if eventData[1] == ENGINE_EVENT_TYPE_INPUT_KB then
for _,val in pairs(eventData) do
print(tostring(val))
end
end
end
local frameSec = 0
local lastSec = 0
function trackFps()
frameSec = frameSec + 1
t = engine_time_get()
if t - lastSec >= 1000 then
print("FPS: " ..tostring(frameSec))
lastSec = t
frameSec = 0
end
end
function bp(pth)
return basepath .. "/mods/main/" ..pth
end
basepath = (debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])") or "./"):sub(1,-2) .. "/../../.." -- Lazy, fix
package.path = basepath.. "/mods/main/script/?.lua;" ..basepath.. "/mods/main/script/?/main.lua;" ..package.path
main()