2014-12-04 16:42:28 +00:00
|
|
|
-- Example: Animation Example
|
|
|
|
local LightWorld = require "lib"
|
2014-12-04 21:56:48 +00:00
|
|
|
local anim8 = require 'lib.anim8'
|
2014-12-04 16:42:28 +00:00
|
|
|
|
|
|
|
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)
|
2014-12-04 21:56:48 +00:00
|
|
|
|
|
|
|
local g = anim8.newGrid(108, 140, image:getWidth(), image:getHeight())
|
|
|
|
animation2 = anim8.newAnimation(g('1-8', 1), 0.1)
|
2014-12-04 16:42:28 +00:00
|
|
|
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
|
|
|
|
|
2014-12-04 21:56:48 +00:00
|
|
|
animation2:update(dt)
|
2014-12-04 16:42:28 +00:00
|
|
|
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)
|
2014-12-04 21:56:48 +00:00
|
|
|
|
|
|
|
animation2:draw(image, 200, 100)
|
2014-12-04 16:42:28 +00:00
|
|
|
end)
|
|
|
|
love.graphics.pop()
|
|
|
|
end
|
|
|
|
|