- [CHG] Mòdul "level" renomenat a "rooms"
- [NEW] Mòdul "menu" - [NEW] Mòdul "popup"
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
level = {
|
||||
surf_background = nil,
|
||||
surf_foreground = nil,
|
||||
surf_items = nil,
|
||||
surf_original_items = nil,
|
||||
|
||||
pos = {x=0, y=0},
|
||||
|
||||
init = function()
|
||||
level.pos.x, level.pos.y = 0,0
|
||||
if level.surf_background ~= nil then surf.free(level.surf_background) end
|
||||
--level.surf_background = surf.load("rooms_background.bin")
|
||||
level.surf_background = surf.new(20*8,12*8)
|
||||
|
||||
if level.surf_foreground ~= nil then surf.free(level.surf_foreground) end
|
||||
--level.surf_foreground = surf.load("rooms_foreground.bin")
|
||||
level.surf_foreground = surf.new(20*8,12*8)
|
||||
|
||||
if level.surf_items ~= nil then surf.free(level.surf_items) end
|
||||
--level.surf_items = surf.load("rooms_items.bin")
|
||||
level.surf_items = surf.new(20*8,12*8)
|
||||
|
||||
level.surf_original_items = surf.new(20*8,12*8)
|
||||
surf.source(level.surf_items)
|
||||
surf.target(level.surf_original_items)
|
||||
draw.surf(0,0,160,96,0,0)
|
||||
|
||||
map.surf(level.surf_background)
|
||||
for y=0,12*8 do
|
||||
for x=0,20*8 do
|
||||
map.tile(x,y,1)
|
||||
end
|
||||
end
|
||||
map.surf(level.surf_foreground)
|
||||
map.tile(10,10,16)
|
||||
|
||||
surf.save(level.surf_background, "data/rooms_background.bin")
|
||||
surf.save(level.surf_foreground, "data/rooms_foreground.bin")
|
||||
surf.save(level.surf_items, "data/rooms_items.bin")
|
||||
|
||||
shader.init("lynx.glsl")
|
||||
shader.enable();
|
||||
end,
|
||||
|
||||
|
||||
draw = function()
|
||||
-- Retallem la pantalla a la zona de joc
|
||||
view.clip(0,8,160,96)
|
||||
|
||||
-- Movem la càmara a l'habitació on estem
|
||||
view.origin(level.pos.x*8,level.pos.y*8+8)
|
||||
|
||||
-- Pintem el background
|
||||
surf.source(tiles)
|
||||
map.surf(level.surf_background)
|
||||
map.draw()
|
||||
|
||||
-- Movem 4x4 pixels la càmara per a pintar les sombres dels sprites i el foreground
|
||||
view.origin(level.pos.x*8+4,level.pos.y*8+12)
|
||||
|
||||
-- Pintem el foreground de negre
|
||||
map.surf(level.surf_foreground)
|
||||
pal.subpal(0,32,1)
|
||||
map.draw()
|
||||
|
||||
-- Pintem els sprites de negre
|
||||
-- [TODO]
|
||||
surf.source(sprites)
|
||||
draw.surf(0, 0, 16, 17, 10, 10, 16, 17)
|
||||
|
||||
-- Movem la càmara al lloc que toca de nou, i tornem la paleta normal
|
||||
view.origin(level.pos.x*8,level.pos.y*8+8)
|
||||
pal.subpal()
|
||||
|
||||
-- Pintem el foreground
|
||||
surf.source(tiles)
|
||||
map.surf(level.surf_foreground)
|
||||
map.draw()
|
||||
|
||||
-- Pintem els sprites
|
||||
-- [TODO]
|
||||
surf.source(sprites)
|
||||
draw.surf(0, 0, 16, 17, 10, 10, 16, 17)
|
||||
|
||||
-- Pintem la rejilla
|
||||
--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
|
||||
end,
|
||||
|
||||
peiv = function()
|
||||
pal.color(1, 1, 1, 1)
|
||||
return "HOLA OTHER UNIT"
|
||||
end
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
require "level"
|
||||
|
||||
require "rooms"
|
||||
require "menu"
|
||||
x=0
|
||||
|
||||
function mini.init()
|
||||
@@ -8,7 +8,8 @@ function mini.init()
|
||||
surf.source(tiles)
|
||||
pal.set(pal.load("tiles.gif"))
|
||||
pal.trans(0)
|
||||
level.init()
|
||||
rooms.init()
|
||||
menu.show()
|
||||
end
|
||||
|
||||
function mini.update()
|
||||
@@ -16,19 +17,23 @@ function mini.update()
|
||||
surf.cls(1)
|
||||
surf.target(0)
|
||||
|
||||
menu.draw()
|
||||
|
||||
-- Pintar el marcador
|
||||
-- [TODO]
|
||||
|
||||
-- Pintar el mapa i sprites
|
||||
level.draw()
|
||||
rooms.draw()
|
||||
|
||||
view.origin(0,0)
|
||||
local mx, my = mouse.pos()
|
||||
mx, my = math.floor(mx/8)*8, math.floor(my/8)*8
|
||||
|
||||
if my>=8 then
|
||||
draw.rect(mx-1, my-1, 10, 10, 28)
|
||||
draw.rect(mx, my, 8, 8, 1)
|
||||
if (key.down(key.ESCAPE)) then
|
||||
end
|
||||
if key.press(key.ESCAPE) then
|
||||
sys.quit()
|
||||
end
|
||||
end
|
||||
|
||||
46
data/menu.lua
Normal file
46
data/menu.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
require "popup"
|
||||
|
||||
menu = {
|
||||
visible = false,
|
||||
current_x = 0,
|
||||
|
||||
init = function()
|
||||
end,
|
||||
|
||||
show = function()
|
||||
menu.visible = true
|
||||
end,
|
||||
|
||||
hide = function()
|
||||
menu.visible = false
|
||||
end,
|
||||
|
||||
draw = function()
|
||||
view.origin(0,0)
|
||||
view.clip()
|
||||
draw.rectf(0,0,160,7,23)
|
||||
draw.hline(0,7,160,16)
|
||||
menu.current_x = 1
|
||||
menu.option("FILE")
|
||||
popup.create("FILE", 1, 8)
|
||||
popup.addOption("FILE", "New", function() sys.quit() end)
|
||||
popup.addOption("FILE", "Load", function() sys.quit() end)
|
||||
popup.addOption("FILE", "Save", function() sys.quit() end)
|
||||
popup.addOption("FILE", "Save As...", function() sys.quit() end)
|
||||
menu.option("EDIT")
|
||||
menu.option("TOOLS")
|
||||
end,
|
||||
|
||||
option = function(label)
|
||||
local next_x = menu.current_x + (#label + 2)*4
|
||||
local mx, my = mouse.pos()
|
||||
if my < 8 and mx >= menu.current_x and mx < next_x then
|
||||
draw.rectf(menu.current_x, 0, next_x-menu.current_x, 8, 21)
|
||||
if mouse.down(mouse.LEFT) then
|
||||
popup.show(label)
|
||||
end
|
||||
end
|
||||
draw.text(label,menu.current_x+4,1,28)
|
||||
menu.current_x = next_x
|
||||
end
|
||||
}
|
||||
39
data/popup.lua
Normal file
39
data/popup.lua
Normal file
@@ -0,0 +1,39 @@
|
||||
popup={
|
||||
list = {},
|
||||
old_update = nil,
|
||||
current = nil,
|
||||
|
||||
create = function(label,x,y)
|
||||
popup.list[label] = {x=x, y=y, width=0, options={}}
|
||||
end,
|
||||
|
||||
addOption = function(parent, label, action)
|
||||
popup.list[parent].options[#popup.list[parent].options+1] = { label=label, action=action }
|
||||
local option_width = #label*4+4
|
||||
if option_width > popup.list[parent].width then
|
||||
popup.list[parent].width = option_width
|
||||
end
|
||||
end,
|
||||
|
||||
show = function(label)
|
||||
popup.old_update = mini.update
|
||||
popup.current = label
|
||||
mini.update = popup.update
|
||||
end,
|
||||
|
||||
update = function()
|
||||
local p = popup.list[popup.current]
|
||||
draw.rectf(p.x, p.y, p.width, #p.options*7+2, 23)
|
||||
draw.rect(p.x, p.y, p.width, #p.options*7+2, 16)
|
||||
local y = p.y+2
|
||||
for k,v in ipairs(p.options) do
|
||||
draw.text(v.label, p.x+2, y, 28)
|
||||
y = y + 7
|
||||
end
|
||||
|
||||
if key.press(key.ESCAPE) then
|
||||
mini.update = popup.old_update
|
||||
end
|
||||
end
|
||||
|
||||
}
|
||||
94
data/rooms.lua
Normal file
94
data/rooms.lua
Normal file
@@ -0,0 +1,94 @@
|
||||
rooms = {
|
||||
surf_background = nil,
|
||||
surf_foreground = nil,
|
||||
surf_items = nil,
|
||||
surf_original_items = nil,
|
||||
|
||||
pos = {x=10*8, y=0},
|
||||
|
||||
init = function()
|
||||
rooms.pos.x, rooms.pos.y = 0,0
|
||||
if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end
|
||||
rooms.surf_background = surf.load("rooms_background.bin")
|
||||
--rooms.surf_background = surf.new(20*8,12*8)
|
||||
|
||||
if rooms.surf_foreground ~= nil then surf.free(rooms.surf_foreground) end
|
||||
rooms.surf_foreground = surf.load("rooms_foreground.bin")
|
||||
--rooms.surf_foreground = surf.new(20*8,12*8)
|
||||
|
||||
if rooms.surf_items ~= nil then surf.free(rooms.surf_items) end
|
||||
rooms.surf_items = surf.load("rooms_items.bin")
|
||||
--rooms.surf_items = surf.new(20*8,12*8)
|
||||
|
||||
rooms.surf_original_items = surf.new(20*8,12*8)
|
||||
surf.source(rooms.surf_items)
|
||||
surf.target(rooms.surf_original_items)
|
||||
draw.surf(0,0,160,96,0,0)
|
||||
|
||||
--map.surf(rooms.surf_background)
|
||||
--for y=0,12*8 do
|
||||
-- for x=0,20*8 do
|
||||
-- map.tile(x,y,1)
|
||||
-- end
|
||||
--end
|
||||
--map.surf(rooms.surf_foreground)
|
||||
--map.tile(10,10,16)
|
||||
|
||||
--surf.save(rooms.surf_background, "data/rooms_background.bin")
|
||||
--surf.save(rooms.surf_foreground, "data/rooms_foreground.bin")
|
||||
--surf.save(rooms.surf_items, "data/rooms_items.bin")
|
||||
|
||||
--shader.init("lynx.glsl")
|
||||
--shader.enable();
|
||||
end,
|
||||
|
||||
|
||||
draw = function()
|
||||
-- Retallem la pantalla a la zona de joc
|
||||
view.clip(0,8,160,96)
|
||||
|
||||
-- Movem la càmara a l'habitació on estem
|
||||
view.origin(rooms.pos.x*8,rooms.pos.y*8+8)
|
||||
|
||||
-- Pintem el background
|
||||
surf.source(tiles)
|
||||
map.surf(rooms.surf_background)
|
||||
map.draw()
|
||||
|
||||
-- Movem 4x4 pixels la càmara per a pintar les sombres dels sprites i el foreground
|
||||
view.origin(rooms.pos.x*8+4,rooms.pos.y*8+12)
|
||||
|
||||
-- Pintem el foreground de negre
|
||||
map.surf(rooms.surf_foreground)
|
||||
pal.subpal(0,32,1)
|
||||
map.draw()
|
||||
|
||||
-- Pintem els sprites de negre
|
||||
-- [TODO]
|
||||
surf.source(sprites)
|
||||
draw.surf(0, 0, 16, 17, 10, 10, 16, 17)
|
||||
|
||||
-- Movem la càmara al lloc que toca de nou, i tornem la paleta normal
|
||||
view.origin(rooms.pos.x*8,rooms.pos.y*8+8)
|
||||
pal.subpal()
|
||||
|
||||
-- Pintem el foreground
|
||||
surf.source(tiles)
|
||||
map.surf(rooms.surf_foreground)
|
||||
map.draw()
|
||||
|
||||
-- Pintem els sprites
|
||||
-- [TODO]
|
||||
surf.source(sprites)
|
||||
draw.surf(0, 0, 16, 17, 10, 10, 16, 17)
|
||||
|
||||
-- Pintem la rejilla
|
||||
--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
|
||||
end,
|
||||
|
||||
peiv = function()
|
||||
pal.color(1, 1, 1, 1)
|
||||
return "HOLA OTHER UNIT"
|
||||
end
|
||||
}
|
||||
BIN
data/rooms_background.bin
Normal file
BIN
data/rooms_background.bin
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 227 B |
BIN
data/rooms_foreground.bin
Normal file
BIN
data/rooms_foreground.bin
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 229 B |
BIN
data/rooms_items.bin
Normal file
BIN
data/rooms_items.bin
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 227 B |
Reference in New Issue
Block a user