133 lines
3.1 KiB
Lua
133 lines
3.1 KiB
Lua
g3d = require "g3d"
|
|
|
|
|
|
|
|
function love.load()
|
|
-- GRAPHICS
|
|
-- GOOD PIXEL
|
|
love.graphics.setDefaultFilter("nearest")
|
|
-- FONTS
|
|
DefaultFont = love.graphics.newImageFont("default_font.png",
|
|
" abcdefghijklmnopqrstuvwxyz" ..
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
|
|
"123456789.,!?-+/():;%&`'*#=[]\"")
|
|
love.graphics.setFont(DefaultFont)
|
|
|
|
g3d.camera.position = { (math.random(-1.5,-0.5)-1)*2 , -1, (math.random(-1.5,-0.5)-1)*2 }
|
|
|
|
speed = 0
|
|
require "objects"
|
|
require "levels"
|
|
current_level = levels.main_menu
|
|
|
|
end
|
|
|
|
function love.mousemoved(x,y, dx,dy)
|
|
|
|
if not game_pause then
|
|
g3d.camera.firstPersonLook(dx,dy)
|
|
end
|
|
|
|
end
|
|
|
|
function love.update(dt)
|
|
-- run, walk, slow?
|
|
if love.keyboard.isDown("lshift") then
|
|
speed = 2
|
|
elseif love.keyboard.isDown("lctrl") then
|
|
speed = 6
|
|
else
|
|
speed = 4
|
|
end
|
|
|
|
if not game_pause then
|
|
g3d.camera.firstPersonMovement(dt,speed)
|
|
end
|
|
|
|
end
|
|
|
|
function love.keypressed(key)
|
|
-- pause the game and free the mouse
|
|
if key == "escape" then
|
|
if game_pause then
|
|
game_pause = false
|
|
love.mouse.setRelativeMode(true)
|
|
else
|
|
game_pause = true
|
|
love.mouse.setRelativeMode(false)
|
|
love.mouse.setPosition(game_width/2,game_height/2)
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
function love.draw()
|
|
-- get drawing globals
|
|
game_width = love.graphics.getWidth()
|
|
game_height = love.graphics.getHeight()
|
|
|
|
-- draw everything
|
|
local obj_count = 0
|
|
for _, obj in pairs(current_level.obj_list) do
|
|
obj_count = obj_count + 1
|
|
if obj.model ~= nil then
|
|
|
|
-- do animated models
|
|
if obj.is_animated == true and obj.anim_path ~= nil then
|
|
-- try to animate
|
|
obj.anim_subframe = obj.anim_subframe + 1
|
|
if obj.anim_subframe >= obj.anim_speed then
|
|
obj.anim_frame = obj.anim_frame + 1
|
|
obj.anim_subframe = obj.anim_subframe - obj.anim_speed
|
|
end
|
|
-- cycle
|
|
if obj.anim_frame >= obj.anim_frames+1 then obj.anim_frame = obj.anim_frame - obj.anim_frames end
|
|
-- change
|
|
obj.model.mesh:setTexture(obj.anim_imgs[obj.anim_frame])
|
|
end
|
|
|
|
-- do rotating models
|
|
if obj.rotate_mode ~= nil and obj.rotate_mode ~= "none" then
|
|
local rm = obj.rotate_mode
|
|
|
|
if rm == "cam_xz" then
|
|
|
|
local sin = g3d.camera.position[1]-obj.model.translation[1]
|
|
local cos = g3d.camera.position[3]-obj.model.translation[3]
|
|
|
|
local angle = math.atan2(sin,cos)-math.rad(180)
|
|
|
|
obj.model:setRotation(0,angle,0)
|
|
end
|
|
end
|
|
|
|
obj.model:draw()
|
|
else
|
|
obj:draw()
|
|
end
|
|
end
|
|
-- print coords
|
|
|
|
if game_pause then
|
|
draw_pause_menu(30,30)
|
|
else
|
|
love.graphics.print("x: "..math.floor(g3d.camera.position[1])..", y: "..math.floor(g3d.camera.position[2])..", z: "..math.floor(g3d.camera.position[3]), x, y)
|
|
end
|
|
|
|
for _, obj in pairs(current_level.obj_list) do
|
|
if obj.model ~= nil then
|
|
if obj.is_animated then
|
|
love.graphics.print("["..obj.name.."] frame: "..obj.anim_frame.."/"..obj.anim_frames..", rm: \""..obj.rotate_mode.."\"",20,20)
|
|
love.graphics.print("["..obj.name.."] animation: "..obj.anim_path,20,40)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function draw_pause_menu(x,y)
|
|
love.graphics.setColor(1,1,1,0.3)
|
|
love.graphics.rectangle("fill", x, y, game_width-2*x, game_height-2*y)
|
|
love.graphics.setColor(1,1,1,1)
|
|
end
|
|
|