mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
finish up implementing the animation setup, through anim8proxy
This commit is contained in:
parent
5a60d1f1ca
commit
8e30cacae0
@ -3,7 +3,7 @@ local LightWorld = require "lib"
|
|||||||
local anim8 = require 'lib.anim8'
|
local anim8 = require 'lib.anim8'
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
x, y, scale = 0, 0, 1
|
x, y, z, scale = 0, 0, 1, 1
|
||||||
-- load images
|
-- load images
|
||||||
image = love.graphics.newImage("examples/gfx/scott_pilgrim.png")
|
image = love.graphics.newImage("examples/gfx/scott_pilgrim.png")
|
||||||
image_normal = love.graphics.newImage("examples/gfx/scott_pilgrim_NRM.png")
|
image_normal = love.graphics.newImage("examples/gfx/scott_pilgrim_NRM.png")
|
||||||
@ -18,12 +18,14 @@ function love.load()
|
|||||||
-- create light
|
-- create light
|
||||||
lightMouse = lightWorld:newLight(0, 0, 255, 127, 63, 300)
|
lightMouse = lightWorld:newLight(0, 0, 255, 127, 63, 300)
|
||||||
lightMouse:setGlowStrength(0.3)
|
lightMouse:setGlowStrength(0.3)
|
||||||
|
lightMouse.normalInvert = true
|
||||||
|
|
||||||
-- create shadow bodys
|
-- create shadow bodys
|
||||||
animation = lightWorld:newAnimationGrid(image, 100, 100)
|
animation = lightWorld:newAnimationGrid(image, 100, 100)
|
||||||
animation:setNormalMap(image_normal)
|
animation:setNormalMap(image_normal)
|
||||||
grid = animation:newGrid(108, 140)
|
grid = animation:newGrid(108, 140)
|
||||||
animation:addAnimation('run right', grid('1-8', 1), 0.1)
|
animation:addAnimation('run right', grid('1-8', 1), 0.1)
|
||||||
|
animation:addAnimation('run left', grid('8-1', 2), 0.1)
|
||||||
|
|
||||||
local g = anim8.newGrid(108, 140, image:getWidth(), image:getHeight())
|
local g = anim8.newGrid(108, 140, image:getWidth(), image:getHeight())
|
||||||
animation2 = anim8.newAnimation(g('1-8', 1), 0.1)
|
animation2 = anim8.newAnimation(g('1-8', 1), 0.1)
|
||||||
@ -50,9 +52,23 @@ function love.update(dt)
|
|||||||
scale = scale + 0.01
|
scale = scale + 0.01
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if love.keyboard.isDown("a") then
|
||||||
|
animation:setAnimation('run left')
|
||||||
|
elseif love.keyboard.isDown("d") then
|
||||||
|
animation:setAnimation('run right')
|
||||||
|
end
|
||||||
|
|
||||||
animation2:update(dt)
|
animation2:update(dt)
|
||||||
lightWorld:update(dt) --only needed for animation
|
lightWorld:update(dt) --only needed for animation
|
||||||
lightMouse:setPosition((love.mouse.getX() - x)/scale, (love.mouse.getY() - y)/scale)
|
lightMouse:setPosition((love.mouse.getX() - x)/scale, (love.mouse.getY() - y)/scale, z)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.mousepressed(x, y, c)
|
||||||
|
if c == "wu" then
|
||||||
|
z = z + 1
|
||||||
|
elseif c == "wd" then
|
||||||
|
z = z - 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
@ -63,7 +79,7 @@ function love.draw()
|
|||||||
lightWorld:draw(function()
|
lightWorld:draw(function()
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
love.graphics.rectangle("fill", -x/scale, -y/scale, love.graphics.getWidth()/scale, love.graphics.getHeight()/scale)
|
love.graphics.rectangle("fill", -x/scale, -y/scale, love.graphics.getWidth()/scale, love.graphics.getHeight()/scale)
|
||||||
animation.animation:draw(image, 100, 100)
|
animation:drawAnimation()
|
||||||
|
|
||||||
animation2:draw(image, 200, 100)
|
animation2:draw(image, 200, 100)
|
||||||
end)
|
end)
|
||||||
|
19
lib/body.lua
19
lib/body.lua
@ -153,11 +153,24 @@ function body:newGrid(frameWidth, frameHeight, imageWidth, imageHeight, left, to
|
|||||||
end
|
end
|
||||||
-- frameWidth, frameHeight, imageWidth, imageHeight, left, top, border
|
-- frameWidth, frameHeight, imageWidth, imageHeight, left, top, border
|
||||||
function body:addAnimation(name, frames, durations, onLoop)
|
function body:addAnimation(name, frames, durations, onLoop)
|
||||||
self.current_animation_name = self.current_animation or name
|
self.current_animation_name = self.current_animation_name or name
|
||||||
self.animations[name] = anim8.newAnimation(frames, durations, onLoop)
|
self.animations[name] = anim8.newAnimation(frames, durations, onLoop)
|
||||||
self.animation = self.animations[self.current_animation_name]
|
self.animation = self.animations[self.current_animation_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function body:setAnimation(name)
|
||||||
|
self.current_animation_name = name
|
||||||
|
self.animation = self.animations[self.current_animation_name]
|
||||||
|
end
|
||||||
|
|
||||||
|
function body:gotoFrame(frame) self.animation:gotoFrame(frame) end
|
||||||
|
function body:pause() self.animation:pause() end
|
||||||
|
function body:resume() self.animation:resume() end
|
||||||
|
function body:flipH() self.animation:flipH() end
|
||||||
|
function body:flipV() self.animation:flipV() end
|
||||||
|
function body:pauseAtEnd() self.animation:pauseAtEnd() end
|
||||||
|
function body:pauseAtStart() self.animation:pauseAtStart() end
|
||||||
|
|
||||||
function body:update(dt)
|
function body:update(dt)
|
||||||
local frame = self.animation.frames[self.animation.position]
|
local frame = self.animation.frames[self.animation.position]
|
||||||
_,_,self.width, self.height = frame:getViewport()
|
_,_,self.width, self.height = frame:getViewport()
|
||||||
@ -493,6 +506,10 @@ function body:isInRange(l, t, w, h, s)
|
|||||||
return self.visible and (bx+bw) > (-l/s) and bx < (-l+w)/s and (by+bh) > (-t/s) and by < (-t+h)/s
|
return self.visible and (bx+bw) > (-l/s) and bx < (-l+w)/s and (by+bh) > (-t/s) and by < (-t+h)/s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function body:drawAnimation()
|
||||||
|
self.animation:draw(self.img, self.x, self.y)
|
||||||
|
end
|
||||||
|
|
||||||
function body:drawNormal()
|
function body:drawNormal()
|
||||||
if not self.refraction and not self.reflection and self.normalMesh then
|
if not self.refraction and not self.reflection and self.normalMesh then
|
||||||
love.graphics.setColor(255, 255, 255)
|
love.graphics.setColor(255, 255, 255)
|
||||||
|
Loading…
Reference in New Issue
Block a user