- [NEW] 'animations' module
- [NEW] 'game' module - [NEW] 'sprites' module - [NEW] more tiles - [NEW] Can choose which tile layer to edit from the editor menu
This commit is contained in:
11
data/animations.lua
Normal file
11
data/animations.lua
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
animations = {
|
||||||
|
["hero_walk"] = {
|
||||||
|
cycle = {1,2,1,3},
|
||||||
|
frames = {
|
||||||
|
{ frame={x=0,y=0,w=16,h=17}, wait=4 },
|
||||||
|
{ frame={x=16,y=0,w=16,h=17}, wait=4 },
|
||||||
|
{ frame={x=32,y=0,w=16,h=17}, wait=4 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,6 @@ editor = {
|
|||||||
modified = false,
|
modified = false,
|
||||||
|
|
||||||
enable = function()
|
enable = function()
|
||||||
menu.show()
|
|
||||||
app.update = editor.update
|
app.update = editor.update
|
||||||
sys.beat(2)
|
sys.beat(2)
|
||||||
end,
|
end,
|
||||||
@@ -109,6 +108,12 @@ editor = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
stamp=function(tx,ty)
|
stamp=function(tx,ty)
|
||||||
|
if editor.layer == LAYER_FOREGROUND then
|
||||||
|
map.surf(rooms.surf_foreground)
|
||||||
|
elseif editor.layer == LAYER_BACKGROUND then
|
||||||
|
map.surf(rooms.surf_background)
|
||||||
|
end
|
||||||
|
|
||||||
local w,h=editor.brush.w,editor.brush.h
|
local w,h=editor.brush.w,editor.brush.h
|
||||||
local p=1
|
local p=1
|
||||||
for y=1,h do
|
for y=1,h do
|
||||||
@@ -145,7 +150,7 @@ editor = {
|
|||||||
update_tiles = function()
|
update_tiles = function()
|
||||||
view.origin(0,0)
|
view.origin(0,0)
|
||||||
view.clip()
|
view.clip()
|
||||||
surf.source(tiles)
|
surf.source(surf_tiles)
|
||||||
surf.cls(1)
|
surf.cls(1)
|
||||||
draw.surf(0,0,128,128,0,0)
|
draw.surf(0,0,128,128,0,0)
|
||||||
|
|
||||||
|
|||||||
18
data/game.lua
Normal file
18
data/game.lua
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
game = {
|
||||||
|
|
||||||
|
enable = function()
|
||||||
|
app.update = game.update
|
||||||
|
sys.beat(20)
|
||||||
|
end,
|
||||||
|
|
||||||
|
update = function()
|
||||||
|
view.origin(0,0)
|
||||||
|
surf.target(0)
|
||||||
|
|
||||||
|
score.draw()
|
||||||
|
|
||||||
|
-- Pintar el mapa i sprites
|
||||||
|
rooms.draw()
|
||||||
|
|
||||||
|
end
|
||||||
|
}
|
||||||
@@ -4,8 +4,8 @@ require "rooms"
|
|||||||
require "editor"
|
require "editor"
|
||||||
|
|
||||||
function mini.init()
|
function mini.init()
|
||||||
sprites = surf.load("sprites.gif")
|
surf_sprites = surf.load("sprites.gif")
|
||||||
tiles = surf.load("tiles.gif")
|
surf_tiles = surf.load("tiles.gif")
|
||||||
pal.set(pal.load("tiles.gif"))
|
pal.set(pal.load("tiles.gif"))
|
||||||
pal.trans(0)
|
pal.trans(0)
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,11 @@
|
|||||||
require "popup"
|
require "popup"
|
||||||
|
|
||||||
menu = {
|
menu = {
|
||||||
visible = false,
|
|
||||||
current_x = 0,
|
current_x = 0,
|
||||||
|
|
||||||
init = function()
|
init = function()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
show = function()
|
|
||||||
menu.visible = true
|
|
||||||
end,
|
|
||||||
|
|
||||||
hide = function()
|
|
||||||
menu.visible = false
|
|
||||||
end,
|
|
||||||
|
|
||||||
draw = function()
|
draw = function()
|
||||||
view.origin(0,0)
|
view.origin(0,0)
|
||||||
view.clip()
|
view.clip()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
require "sprites"
|
||||||
|
|
||||||
LAYER_FOREGROUND = 1
|
LAYER_FOREGROUND = 1
|
||||||
LAYER_BACKGROUND = 2
|
LAYER_BACKGROUND = 2
|
||||||
LAYER_ITEMS = 4
|
LAYER_ITEMS = 4
|
||||||
@@ -32,6 +34,7 @@ rooms = {
|
|||||||
surf.target(rooms.surf_original_items)
|
surf.target(rooms.surf_original_items)
|
||||||
draw.surf(0,0,160,96,0,0)
|
draw.surf(0,0,160,96,0,0)
|
||||||
|
|
||||||
|
sprites.init()
|
||||||
--map.surf(rooms.surf_background)
|
--map.surf(rooms.surf_background)
|
||||||
--for y=0,12*8 do
|
--for y=0,12*8 do
|
||||||
-- for x=0,20*8 do
|
-- for x=0,20*8 do
|
||||||
@@ -64,7 +67,7 @@ rooms = {
|
|||||||
view.origin(-rooms.pos.x*8,-rooms.pos.y*8+8)
|
view.origin(-rooms.pos.x*8,-rooms.pos.y*8+8)
|
||||||
|
|
||||||
-- Pintem el background
|
-- Pintem el background
|
||||||
surf.source(tiles)
|
surf.source(surf_tiles)
|
||||||
map.surf(rooms.surf_background)
|
map.surf(rooms.surf_background)
|
||||||
if rooms.is_visible(LAYER_BACKGROUND) then
|
if rooms.is_visible(LAYER_BACKGROUND) then
|
||||||
map.draw()
|
map.draw()
|
||||||
@@ -81,10 +84,9 @@ rooms = {
|
|||||||
if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end
|
if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end
|
||||||
|
|
||||||
-- Pintem els sprites de negre
|
-- Pintem els sprites de negre
|
||||||
-- [TODO]
|
|
||||||
surf.source(sprites)
|
|
||||||
if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then
|
if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then
|
||||||
draw.surf(0, 0, 16, 17, 10, 10, 16, 17)
|
sprites.draw()
|
||||||
|
--draw.surf(0, 0, 16, 17, 20, 15, 16, 17)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Movem la càmara al lloc que toca de nou, i tornem la paleta normal
|
-- Movem la càmara al lloc que toca de nou, i tornem la paleta normal
|
||||||
@@ -92,17 +94,17 @@ rooms = {
|
|||||||
pal.subpal()
|
pal.subpal()
|
||||||
|
|
||||||
-- Pintem el foreground
|
-- Pintem el foreground
|
||||||
surf.source(tiles)
|
surf.source(surf_tiles)
|
||||||
map.surf(rooms.surf_foreground)
|
map.surf(rooms.surf_foreground)
|
||||||
if rooms.is_visible(LAYER_FOREGROUND) then map.draw() end
|
if rooms.is_visible(LAYER_FOREGROUND) then map.draw() end
|
||||||
|
|
||||||
-- Pintem els sprites
|
-- Pintem els sprites
|
||||||
-- [TODO]
|
|
||||||
surf.source(sprites)
|
|
||||||
if rooms.is_visible(LAYER_SPRITES) then
|
if rooms.is_visible(LAYER_SPRITES) then
|
||||||
draw.surf(0, 0, 16, 17, 10, 10, 16, 17)
|
sprites.draw()
|
||||||
|
--draw.surf(0, 0, 16, 17, 20, 15, 16, 17)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sprites.update()
|
||||||
-- Pintem la rejilla
|
-- Pintem la rejilla
|
||||||
--for y=0,12 do draw.line(0,y*8, 160, y*8, 27) end
|
--for y=0,12 do draw.line(0,y*8, 160, y*8, 27) end
|
||||||
--for x=0,20 do draw.line(x*8, 0, x*8, 104, 27) end
|
--for x=0,20 do draw.line(x*8, 0, x*8, 104, 27) end
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 263 B After Width: | Height: | Size: 272 B |
48
data/sprites.lua
Normal file
48
data/sprites.lua
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
BIN
data/tiles.gif
BIN
data/tiles.gif
Binary file not shown.
|
Before Width: | Height: | Size: 897 B After Width: | Height: | Size: 952 B |
Reference in New Issue
Block a user