- [NEW] 'game' module - [NEW] 'sprites' module - [NEW] more tiles - [NEW] Can choose which tile layer to edit from the editor menu
48 lines
1.4 KiB
Lua
48 lines
1.4 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 },
|
|
animation = "hero_walk",
|
|
current_frame = 1,
|
|
current_wait = 1
|
|
}
|
|
end,
|
|
|
|
update = function()
|
|
sprites.update_sprite(sprites.hero)
|
|
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)
|
|
end
|
|
} |