- [NEW] Es pot pasar quan es vullga del joc al editor i viceversa - [NEW] Els shaders s'activen en el joc i se desactiven en l'editor
69 lines
2.2 KiB
Lua
69 lines
2.2 KiB
Lua
require "animations"
|
|
|
|
sprites = {
|
|
hero = nil,
|
|
list = {},
|
|
|
|
init = function()
|
|
sprites.hero = {
|
|
pos = { x=24, y=15 },
|
|
size= { w=16, h=17 },
|
|
bbo = { left=0, top=0, right=0, bottom=0 },
|
|
flipped = false,
|
|
animation = "hero_stand",
|
|
current_frame = 1,
|
|
current_wait = 1
|
|
}
|
|
end,
|
|
|
|
set_animation=function(sprite, animation)
|
|
if sprite.animation ~= animation then
|
|
sprite.animation = animation
|
|
sprite.current_frame = 1
|
|
sprite.current_wait = 1
|
|
end
|
|
end,
|
|
|
|
update = function()
|
|
sprites.update_sprite(sprites.hero)
|
|
|
|
if key.down(key.LEFT) then
|
|
sprites.hero.flipped = true
|
|
sprites.set_animation(sprites.hero, "hero_walk")
|
|
sprites.hero.pos.x = sprites.hero.pos.x - 1
|
|
elseif key.down(key.RIGHT) then
|
|
sprites.hero.flipped = false
|
|
sprites.set_animation(sprites.hero, "hero_walk")
|
|
sprites.hero.pos.x = sprites.hero.pos.x + 1
|
|
else
|
|
sprites.set_animation(sprites.hero, "hero_stand")
|
|
end
|
|
end,
|
|
|
|
update_sprite = function(sprite)
|
|
if sys.beat() then
|
|
sprite.current_wait = sprite.current_wait - 1
|
|
if sprite.current_wait == 0 then
|
|
if sprite.current_frame < #animations[sprite.animation].cycle then
|
|
sprite.current_frame = sprite.current_frame + 1
|
|
else
|
|
sprite.current_frame = 1
|
|
end
|
|
local cycle = animations[sprite.animation].cycle[sprite.current_frame]
|
|
sprite.current_wait = animations[sprite.animation].frames[cycle].wait
|
|
end
|
|
end
|
|
end,
|
|
|
|
draw = function()
|
|
surf.source(surf_sprites)
|
|
|
|
sprites.draw_sprite(sprites.hero)
|
|
end,
|
|
|
|
draw_sprite = function(sprite)
|
|
local cycle = animations[sprite.animation].cycle[sprite.current_frame]
|
|
local frame = animations[sprite.animation].frames[cycle]
|
|
draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x, sprite.pos.y, sprite.size.w, sprite.size.h, sprite.flipped)
|
|
end
|
|
} |