183 lines
6.5 KiB
Lua
183 lines
6.5 KiB
Lua
g3d = require "g3d"
|
|
require "suppfunc"
|
|
|
|
function love.load()
|
|
-- Personal seed generation
|
|
personalseed = love.data.encode("string", "hex", love.data.hash("sha256", os.getenv("PATH")))
|
|
notsorandomseed = personalseed
|
|
math.randomseed(tonumber(personalseed, 16))
|
|
|
|
-- Reset variables
|
|
fps_second = 0
|
|
fps_count = 0
|
|
fps_draw = 0
|
|
|
|
-- GRAPHICS
|
|
-- GOOD PIXEL
|
|
love.graphics.setDefaultFilter("nearest")
|
|
-- meshe stuff
|
|
love.graphics.setMeshCullMode("back")
|
|
-- FONTS
|
|
DefaultFont = love.graphics.newImageFont("default_font.png",
|
|
" abcdefghijklmnopqrstuvwxyz" ..
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
|
|
"123456789.,!?-+/():;%&`'*#=[]\"")
|
|
love.graphics.setFont(DefaultFont)
|
|
g3d.camera.down = {0,-1,0}
|
|
obj_list = {}
|
|
|
|
-- obj_flower_pot = g3d.newModel("objects/flower_pot.obj","objects/flower_pot/texture.png",{0,0,0},{0,0,0},{1,-1,1}),
|
|
--
|
|
generate_museum(0,0,0)
|
|
end
|
|
|
|
function love.mousemoved(x,y, dx,dy)
|
|
if not pause then
|
|
g3d.camera.firstPersonLook(dx,dy)
|
|
end
|
|
end
|
|
|
|
function love.update(dt)
|
|
if not pause then
|
|
g3d.camera.firstPersonMovement(dt,5)
|
|
end
|
|
-- count frames per seconds
|
|
if fps_second >= 1 then
|
|
fps_second = fps_second - 1
|
|
fps_draw = fps_count
|
|
fps_count = 0
|
|
end
|
|
fps_second = fps_second + dt
|
|
fps_dt = dt
|
|
fps_count = fps_count + 1
|
|
end
|
|
|
|
function love.keypressed(key)
|
|
if key == "z" then
|
|
obj_list = {}
|
|
notsorandomseed = os.time()
|
|
math.randomseed(notsorandomseed)
|
|
notsorandomseed = love.data.encode("string", "hex", love.data.hash("sha256", notsorandomseed))
|
|
generate_museum(0,0,0)
|
|
end
|
|
if key == "escape" then
|
|
if pause then
|
|
pause = false
|
|
love.mouse.setRelativeMode(true)
|
|
else
|
|
pause = true
|
|
love.mouse.setRelativeMode(false)
|
|
end
|
|
end
|
|
end
|
|
|
|
function love.draw()
|
|
-- draw everything
|
|
for _, obj in pairs(obj_list) do
|
|
obj:draw()
|
|
end
|
|
|
|
-- Print FPS
|
|
love.graphics.print("FPS: "..fps_draw.." Frametime: "..fps_dt)
|
|
|
|
-- print "Press [z] to generate a new museum"
|
|
love.graphics.print("Press [z] to generate a new museum", 20, 20)
|
|
|
|
-- print coords
|
|
love.graphics.print("x: "..math.floor(g3d.camera.position[1])..", y: "..math.floor(g3d.camera.position[2])..", z: "..math.floor(g3d.camera.position[3]), 20, 40)
|
|
|
|
-- print seed
|
|
if notsorandomseed == personalseed then
|
|
love.graphics.setColor(hexrgb("#FFD700"))
|
|
love.graphics.print("Seed: "..personalseed, 20, 60)
|
|
love.graphics.setColor(hexrgb("#ffffff"))
|
|
else
|
|
love.graphics.print("Seed: "..notsorandomseed, 20, 60)
|
|
end
|
|
|
|
|
|
if pause then
|
|
love.graphics.rectangle("fill", 20, 20, love.graphics.getWidth()-40, love.graphics.getHeight()-40)
|
|
end
|
|
end
|
|
|
|
function generate_museum(x,y,z)
|
|
local width = math.random(10,20)
|
|
local height = 4
|
|
local depth = math.random(10,20)
|
|
|
|
-- make the ground
|
|
for w = 0, width, 1 do for d = 0, depth, 1 do
|
|
table.insert(obj_list,g3d.newModel("objects/ground.obj","objects/ground/texture.png",{x+w,y,z+d},{0,0,0},{-1,1,-1}))
|
|
end end
|
|
|
|
-- make the walls
|
|
for w = 0, width, 1 do for h = 0, height, 1 do
|
|
table.insert(obj_list,g3d.newModel("objects/wall.obj","objects/wall/texture.png",{x+w,y-h-1,z},{0,math.pi/2,0},{-1,1,-1}))
|
|
table.insert(obj_list,g3d.newModel("objects/wall.obj","objects/wall/texture.png",{x+w,y-h-1,z+depth},{0,math.pi/2,0},{-1,1,-1}))
|
|
end end
|
|
|
|
for d = 0, depth, 1 do for h = 0, height, 1 do
|
|
table.insert(obj_list,g3d.newModel("objects/wall.obj","objects/wall/texture.png",{x,y-h-1,z+d},{0,0,0},{-1,1,-1}))
|
|
table.insert(obj_list,g3d.newModel("objects/wall.obj","objects/wall/texture.png",{x+width,y-h-1,z+d},{0,0,0},{-1,1,-1}))
|
|
end end
|
|
|
|
-- decorate with paintings
|
|
local art_height = 2.5
|
|
|
|
for w = 2, width-2, 4 do
|
|
random_art(x+w,y-art_height,z+1/16,0,-math.pi/2,0)
|
|
random_art(x+w,y-art_height,z-1/16+depth,0,math.pi/2,0)
|
|
end
|
|
for d = 2, depth-2, 4 do
|
|
random_art(x+1/16,y-art_height,z+d,0,0,0)
|
|
random_art(x-1/16+width,y-art_height,z+d,0,-math.pi,0)
|
|
end
|
|
|
|
-- place pillars to support the room in the middle of the room
|
|
pillars = math.random(0,1)
|
|
|
|
if pillars == 0 then
|
|
-- no pillars
|
|
elseif pillars == 1 then
|
|
table.insert(obj_list,g3d.newModel("objects/pillar.obj","objects/pillar/texture.png",{x+width/4, y-5*(76/80), z+depth/4},{0,0,0},{1,1,1}))
|
|
table.insert(obj_list,g3d.newModel("objects/pillar.obj","objects/pillar/texture.png",{x+width*3/4, y-5*(76/80), z+depth*3/4},{0,0,0},{1,1,1}))
|
|
table.insert(obj_list,g3d.newModel("objects/pillar.obj","objects/pillar/texture.png",{x+width*3/4, y-5*(76/80), z+depth/4},{0,0,0},{1,1,1}))
|
|
table.insert(obj_list,g3d.newModel("objects/pillar.obj","objects/pillar/texture.png",{x+width/4, y-5*(76/80), z+depth*3/4},{0,0,0},{1,1,1}))
|
|
end
|
|
|
|
-- place carpet in the middle of the room
|
|
table.insert(obj_list,g3d.newModel("objects/carpet.obj","objects/carpet/texture.png",{x+width/2, y-(1/16) , z+depth/2},{0,math.random(),0},{1,-1,1}))
|
|
|
|
-- place camera in the middle of the room
|
|
g3d.camera.position = {x+width/2, y-2, z+depth/2}
|
|
end
|
|
|
|
|
|
function random_art(x,y,z,rotx,roty,rotz)
|
|
local art = math.random(0,10)
|
|
if art == 0 then
|
|
-- no art :S
|
|
elseif art == 1 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_9_12.obj","objects/art_9_12/eri_sueños.png",{x,y-(12/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
elseif art == 2 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_1_1.obj","objects/art_1_1/yari_walk.png",{x,y-(10/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
elseif art == 3 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_16_9.obj","objects/art_16_9/clareta_tira.png",{x,y-(9/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
elseif art == 4 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_16_12.obj","objects/art_16_12/clareta_garden_throne.png",{x,y-(12/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
elseif art == 5 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_24_16.obj","objects/art_24_16/eri_dungeon.png",{x,y-(16/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
elseif art == 6 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_12_9.obj","objects/art_12_9/noe_nerielle.png",{x,y-(9/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
elseif art == 7 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_1_1.obj","objects/art_1_1/yari_pumpum.png",{x,y-(10/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
elseif art == 8 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_12_6.obj","objects/art_12_6/eri_sigils.png",{x,y-(6/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
elseif art == 9 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_16_24.obj","objects/art_16_24/eri_ariel_with_overalls.png",{x,y-(24/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
elseif art == 10 then
|
|
table.insert(obj_list,g3d.newModel("objects/art_4_3.obj","objects/art_4_3/eri_window.png",{x,y-(16/16),z},{rotx,roty,rotz},{1,1,1}))
|
|
end
|
|
end
|