light_world.lua/examples/animation.lua
2014-12-04 11:42:28 -05:00

66 lines
1.8 KiB
Lua

-- Example: Animation Example
local LightWorld = require "lib"
function love.load()
x, y, scale = 0, 0, 1
-- load images
image = love.graphics.newImage("examples/gfx/scott_pilgrim.png")
image_normal = love.graphics.newImage("examples/gfx/scott_pilgrim_NRM.png")
-- create light world
lightWorld = LightWorld({
ambient = {55,55,55},
refractionStrength = 32.0,
reflectionVisibility = 0.75,
})
-- create light
lightMouse = lightWorld:newLight(0, 0, 255, 127, 63, 300)
lightMouse:setGlowStrength(0.3)
-- create shadow bodys
animation = lightWorld:newAnimationGrid(image, 100, 100)
animation:setNormalMap(image_normal)
grid = animation:newGrid(108, 140)
animation:addAnimation('run right', grid('1-8', 1), 0.1)
end
function love.update(dt)
love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
if love.keyboard.isDown("down") then
y = y - dt * 200
elseif love.keyboard.isDown("up") then
y = y + dt * 200
end
if love.keyboard.isDown("right") then
x = x - dt * 200
elseif love.keyboard.isDown("left") then
x = x + dt * 200
end
if love.keyboard.isDown("-") then
scale = scale - 0.01
elseif love.keyboard.isDown("=") then
scale = scale + 0.01
end
lightWorld:update(dt) --only needed for animation
lightMouse:setPosition((love.mouse.getX() - x)/scale, (love.mouse.getY() - y)/scale)
end
function love.draw()
lightWorld:setTranslation(x, y, scale)
love.graphics.push()
love.graphics.translate(x, y)
love.graphics.scale(scale)
lightWorld:draw(function()
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle("fill", -x/scale, -y/scale, love.graphics.getWidth()/scale, love.graphics.getHeight()/scale)
animation.animation:draw(image, 100, 100)
end)
love.graphics.pop()
end