2023-08-10 00:10:09 +00:00
|
|
|
package.path = basepath.. "/mods/main/script/?.lua;" ..basepath.. "/mods/main/script/?/main.lua;" ..package.path
|
|
|
|
|
|
|
|
function bp(pth)
|
|
|
|
return basepath .. "/mods/main/" ..pth
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local width = 320
|
|
|
|
local height = 240
|
2023-08-10 00:27:52 +00:00
|
|
|
local framelimit = 60
|
2023-08-11 12:16:54 +00:00
|
|
|
local fovVert = 67
|
|
|
|
local fovHor = fovVert * (width / height)
|
2023-08-10 00:27:52 +00:00
|
|
|
framelimit = math.floor(1000 / framelimit)
|
|
|
|
|
2023-08-10 00:10:09 +00:00
|
|
|
local px = -1
|
|
|
|
local py = -0.4
|
|
|
|
local pz = 0.5
|
|
|
|
local prx = 0
|
|
|
|
local pry = 0
|
|
|
|
|
|
|
|
function main()
|
|
|
|
window = engine_window_create(width,height,"engine")
|
|
|
|
|
2023-08-19 16:54:59 +00:00
|
|
|
-- Load quad tex
|
|
|
|
quaddie = engine_texture_create(8,8)
|
|
|
|
engine_rendertarget_set(quaddie)
|
|
|
|
engine_rendertarget_draw_file(bp("texture/fier.rgba"))
|
|
|
|
|
2023-08-10 00:10:09 +00:00
|
|
|
-- Load chars
|
|
|
|
loadchar("invalid","invalid")
|
2023-08-20 13:58:05 +00:00
|
|
|
local chars="0123456789abcdefghijklmnopqrstuvwxyz"
|
|
|
|
for id=1,string.len(chars),1 do loadchar(string.sub(chars,id,id),string.sub(chars,id,id)) end
|
2023-08-10 00:10:09 +00:00
|
|
|
loadchar("space"," ")
|
|
|
|
loadchar("dot",".")
|
|
|
|
loadchar("minus","-")
|
2023-08-20 13:58:05 +00:00
|
|
|
loadchar("comma",",")
|
|
|
|
loadchar("exclamation","!")
|
|
|
|
loadchar("question","?")
|
2023-08-10 00:10:09 +00:00
|
|
|
engine_rendertarget_set(engine_window_texture_get(window))
|
|
|
|
|
|
|
|
-- Clear window
|
|
|
|
engine_color_set(0,0,0,255)
|
|
|
|
engine_rendertarget_fill(0,0,width - 1,height - 1)
|
|
|
|
|
|
|
|
while true do
|
|
|
|
event = engine_event_get()
|
|
|
|
eventData = {engine_lua_event_get_data(event)}
|
|
|
|
engine_event_free(event)
|
|
|
|
if eventData[1] ~= ENGINE_EVENT_TYPE_NONE then
|
|
|
|
handleEvent(event,eventData)
|
|
|
|
else
|
|
|
|
tick()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function logic()
|
|
|
|
engine_color_set(0,0,20,255)
|
|
|
|
engine_rendertarget_fill(0,0,width - 1,height - 1)
|
|
|
|
|
|
|
|
if pressedKeys[26] then -- w
|
|
|
|
prx = prx + (0.1 * frametime)
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressedKeys[22] then -- s
|
|
|
|
prx = prx - (0.1 * frametime)
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressedKeys[7] then -- d
|
|
|
|
pry = pry + (0.1 * frametime)
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressedKeys[4] then -- a
|
|
|
|
pry = pry - (0.1 * frametime)
|
|
|
|
end
|
|
|
|
|
|
|
|
local fwdX,fwdY,fwdZ = engine_3d_rotate_position(1,0,0,0,-pry,0)
|
|
|
|
local rgtX,rgtY,rgtZ = engine_3d_rotate_position(0,0,1,0,-pry,0)
|
|
|
|
|
|
|
|
if pressedKeys[82] then -- up
|
|
|
|
px = px + (fwdX * (0.01 * frametime))
|
|
|
|
py = py + (fwdY * (0.01 * frametime))
|
|
|
|
pz = pz + (fwdZ * (0.01 * frametime))
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressedKeys[81] then -- down
|
|
|
|
px = px - (fwdX * (0.01 * frametime))
|
|
|
|
py = py - (fwdY * (0.01 * frametime))
|
|
|
|
pz = pz - (fwdZ * (0.01 * frametime))
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressedKeys[80] then -- left
|
|
|
|
px = px - (rgtX * (0.01 * frametime))
|
|
|
|
py = py - (rgtY * (0.01 * frametime))
|
|
|
|
pz = pz - (rgtZ * (0.01 * frametime))
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressedKeys[79] then -- right
|
|
|
|
px = px + (rgtX * (0.01 * frametime))
|
|
|
|
py = py + (rgtY * (0.01 * frametime))
|
|
|
|
pz = pz + (rgtZ * (0.01 * frametime))
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressedKeys[75] then -- pgup
|
|
|
|
py = py - (0.01 * frametime)
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressedKeys[78] then -- pgdown
|
|
|
|
py = py + (0.01 * frametime)
|
|
|
|
end
|
|
|
|
|
2023-08-19 16:54:59 +00:00
|
|
|
engine_3d_rendertarget_draw_quad(quaddie,quaddie,0,0,7,7,
|
|
|
|
0 + px,0 + py,0 + pz,
|
|
|
|
1 + px,0 + py,0 + pz,
|
|
|
|
0 + px,-1 + py,0 + pz,
|
|
|
|
1 + px,-1 + py,0 + pz,
|
|
|
|
prx,pry,0,fovHor,fovVert,1);
|
|
|
|
|
2023-08-10 00:10:09 +00:00
|
|
|
engine_color_set(255,0,255,255)
|
|
|
|
for i=0,1,0.1 do draw3dpoint(i,0,0) end
|
|
|
|
for i=0,1,0.1 do draw3dpoint(i,1,0) end
|
|
|
|
engine_color_set(64,0,64,255)
|
|
|
|
for i=0,1,0.1 do draw3dpoint(i,0,1) end
|
|
|
|
for i=0,1,0.1 do draw3dpoint(i,1,1) end
|
|
|
|
|
|
|
|
engine_color_set(255,0,255,255)
|
|
|
|
for i=0,1,0.1 do draw3dpoint(0,i,0) end
|
|
|
|
for i=0,1,0.1 do draw3dpoint(1,i,0) end
|
|
|
|
engine_color_set(64,0,64,255)
|
|
|
|
for i=0,1,0.1 do draw3dpoint(0,i,1) end
|
|
|
|
for i=0,1,0.1 do draw3dpoint(1,i,1) end
|
|
|
|
|
|
|
|
for i=0,1,0.1 do engine_color_set(255 - math.ceil(192 * i),0,255 - math.ceil(192 * i),255) draw3dpoint(0,0,i) end
|
|
|
|
for i=0,1,0.1 do engine_color_set(255 - math.ceil(192 * i),0,255 - math.ceil(192 * i),255) draw3dpoint(1,0,i) end
|
|
|
|
for i=0,1,0.1 do engine_color_set(255 - math.ceil(192 * i),0,255 - math.ceil(192 * i),255) draw3dpoint(0,1,i) end
|
|
|
|
for i=0,1,0.1 do engine_color_set(255 - math.ceil(192 * i),0,255 - math.ceil(192 * i),255) draw3dpoint(1,1,i) end
|
|
|
|
|
|
|
|
if framerate ~= nil then drawText(framerate,0,0) end
|
|
|
|
|
|
|
|
drawText(prettyNumber(px),0,16)
|
|
|
|
drawText(prettyNumber(py),0,24)
|
|
|
|
drawText(prettyNumber(pz),0,32)
|
|
|
|
|
|
|
|
drawText(prettyNumber(prx),0,48)
|
|
|
|
drawText(prettyNumber(pry),0,56)
|
|
|
|
end
|
|
|
|
|
|
|
|
lastFrame = engine_time_get()
|
2023-08-10 00:27:52 +00:00
|
|
|
frametime = framelimit
|
2023-08-10 00:10:09 +00:00
|
|
|
function tick()
|
|
|
|
logic()
|
|
|
|
|
|
|
|
engine_window_present(window)
|
|
|
|
trackFps()
|
|
|
|
local curFrame = engine_time_get()
|
|
|
|
frametime = (curFrame - lastFrame)
|
2023-08-10 00:27:52 +00:00
|
|
|
local wait = framelimit - frametime
|
2023-08-10 00:10:09 +00:00
|
|
|
if wait > 0 then engine_time_sleep(wait) end
|
|
|
|
lastFrame = engine_time_get()
|
|
|
|
end
|
|
|
|
|
|
|
|
pressedKeys = {}
|
|
|
|
function handleEvent()
|
|
|
|
if eventData[1] == ENGINE_EVENT_TYPE_EXIT then
|
|
|
|
os.exit()
|
|
|
|
end
|
|
|
|
|
|
|
|
if eventData[1] == ENGINE_EVENT_TYPE_INPUT_KB then
|
|
|
|
if eventData[3] == 1 then
|
|
|
|
print(tostring(eventData[2]).. " pressed")
|
|
|
|
pressedKeys[eventData[2]] = true
|
|
|
|
else
|
|
|
|
print(tostring(eventData[2]).. " released")
|
|
|
|
pressedKeys[eventData[2]] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
framerate = 0
|
|
|
|
local frameSec = 0
|
|
|
|
local lastSec = 0
|
|
|
|
function trackFps()
|
|
|
|
frameSec = frameSec + 1
|
2023-08-10 00:28:04 +00:00
|
|
|
local t = engine_time_get()
|
2023-08-10 00:10:09 +00:00
|
|
|
if t - lastSec >= 1000 then
|
|
|
|
framerate = frameSec
|
|
|
|
lastSec = t
|
|
|
|
frameSec = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function draw3dpoint(x,y,z)
|
|
|
|
x = px - x
|
|
|
|
y = py - y
|
|
|
|
z = pz - z
|
2023-08-11 12:16:36 +00:00
|
|
|
local sx,sy = engine_3d_project(x,y,z,prx,pry,0,fovHor,fovVert)
|
2023-08-11 12:17:15 +00:00
|
|
|
sx,sy = engine_position_2d_to_tex(sx,sy,width,height,1)
|
2023-08-10 00:10:09 +00:00
|
|
|
engine_rendertarget_draw_point(sx,sy)
|
|
|
|
end
|
|
|
|
|
|
|
|
chars = {}
|
|
|
|
function loadchar(fi,ch)
|
|
|
|
local tex = engine_texture_create(8,8)
|
|
|
|
engine_rendertarget_set(tex)
|
|
|
|
engine_rendertarget_draw_file(bp("texture/char/" ..fi.. ".rgba"))
|
|
|
|
chars[ch] = tex
|
|
|
|
end
|
|
|
|
|
|
|
|
function drawText(text,x,y)
|
|
|
|
local len = string.len(text)
|
|
|
|
local index = 1
|
|
|
|
while index <= len do
|
|
|
|
local char = string.sub(text,index,index)
|
|
|
|
if chars[char] == nil then char = "invalid" end
|
|
|
|
engine_rendertarget_draw_texture(chars[char],x + (8 * (index - 1)),y)
|
|
|
|
index = index + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function prettyNumber(nr)
|
|
|
|
local out = string.format("%.2f",nr)
|
|
|
|
if string.sub(out,1,1) ~= "-" then out = " " ..out end
|
|
|
|
return out
|
|
|
|
end
|
|
|
|
|
|
|
|
main()
|