64 lines
1.5 KiB
Lua
64 lines
1.5 KiB
Lua
function main()
|
|
math.randomseed(os.time())
|
|
window = engine_window_create(96,64,"Game")
|
|
texture = engine_texture_create(8,8)
|
|
engine_rendertarget_set(texture)
|
|
engine_rendertarget_draw_file(bp("texture/fier.rgba"))
|
|
engine_rendertarget_set(engine_window_texture_get(window))
|
|
|
|
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()
|
|
engine_rendertarget_draw_texture(texture,math.random(-8,104),math.random(-8,72))
|
|
engine_window_present(window)
|
|
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()
|