- [NEW] (EDITOR) selector de items
- [WIP] borrat i creació de items segons s'eix o entra de les habitacions - [FIX] Items indexats per número, per a poder-se guardar en un mapa - [NEW] room.current() - [NEW] resaltat del item seleccionat
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
require "menu"
|
require "menu"
|
||||||
require "msgbox"
|
require "msgbox"
|
||||||
|
require "items"
|
||||||
|
|
||||||
editor = {
|
editor = {
|
||||||
|
|
||||||
@@ -8,6 +9,7 @@ editor = {
|
|||||||
selection=nil,
|
selection=nil,
|
||||||
ants=0xc936,
|
ants=0xc936,
|
||||||
modified = false,
|
modified = false,
|
||||||
|
item_selected=nil,
|
||||||
|
|
||||||
enable = function()
|
enable = function()
|
||||||
app.update = editor.update
|
app.update = editor.update
|
||||||
@@ -32,6 +34,7 @@ editor = {
|
|||||||
mx, my = tx<<3, ty<<3
|
mx, my = tx<<3, ty<<3
|
||||||
|
|
||||||
if my>=0 then
|
if my>=0 then
|
||||||
|
if editor.layer==LAYER_BACKGROUND or editor.layer==LAYER_FOREGROUND then
|
||||||
if editor.selection then
|
if editor.selection then
|
||||||
local rx1,ry1,rx2,ry2=editor.selection.x1<<3,editor.selection.y1<<3,editor.selection.x2<<3,editor.selection.y2<<3
|
local rx1,ry1,rx2,ry2=editor.selection.x1<<3,editor.selection.y1<<3,editor.selection.x2<<3,editor.selection.y2<<3
|
||||||
if rx1>rx2 then rx1,rx2=rx2,rx1 end
|
if rx1>rx2 then rx1,rx2=rx2,rx1 end
|
||||||
@@ -68,6 +71,23 @@ editor = {
|
|||||||
editor.selection=nil
|
editor.selection=nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
if mouse.press(mouse.LEFT) then
|
||||||
|
if editor.item_selected then
|
||||||
|
surf.target(rooms.surf_items)
|
||||||
|
surf.pixel(tx,ty,editor.item_selected)
|
||||||
|
editor.modified = true
|
||||||
|
surf.target(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if mouse.press(mouse.RIGHT) then
|
||||||
|
editor.item_selected = nil
|
||||||
|
end
|
||||||
|
if editor.item_selected then
|
||||||
|
local k = items[editor.item_selected]
|
||||||
|
draw.surf(k.visual.x, k.visual.y, k.visual.w, k.visual.h, mx, my)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
view.origin(0,0)
|
view.origin(0,0)
|
||||||
@@ -85,7 +105,11 @@ editor = {
|
|||||||
elseif key.press(key.UP) and rooms.pos.y > 0 then
|
elseif key.press(key.UP) and rooms.pos.y > 0 then
|
||||||
rooms.pos.y = rooms.pos.y - 12
|
rooms.pos.y = rooms.pos.y - 12
|
||||||
elseif key.press(key.TAB) or key.press(key.ESCAPE) then
|
elseif key.press(key.TAB) or key.press(key.ESCAPE) then
|
||||||
editor.picker.show()
|
if editor.layer==LAYER_BACKGROUND or editor.layer==LAYER_FOREGROUND then
|
||||||
|
editor.tilepicker.show()
|
||||||
|
else
|
||||||
|
editor.itempicker.show()
|
||||||
|
end
|
||||||
elseif key.press(key.P) then
|
elseif key.press(key.P) then
|
||||||
sprites.hero.pos.x = tx*8-4
|
sprites.hero.pos.x = tx*8-4
|
||||||
sprites.hero.pos.y = ty*8-9
|
sprites.hero.pos.y = ty*8-9
|
||||||
@@ -166,10 +190,10 @@ editor = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
picker = {
|
tilepicker = {
|
||||||
|
|
||||||
show = function()
|
show = function()
|
||||||
app.push(editor.picker.update_tiles)
|
app.push(editor.tilepicker.update_tiles)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
update_tiles = function()
|
update_tiles = function()
|
||||||
@@ -201,5 +225,39 @@ editor = {
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
},
|
||||||
|
|
||||||
|
itempicker = {
|
||||||
|
|
||||||
|
show = function()
|
||||||
|
app.push(editor.itempicker.update_items)
|
||||||
|
end,
|
||||||
|
|
||||||
|
update_items = function()
|
||||||
|
view.origin(0,0)
|
||||||
|
view.clip()
|
||||||
|
surf.source(surf_sprites)
|
||||||
|
surf.cls(1)
|
||||||
|
local mx, my = mouse.pos()
|
||||||
|
local x,y = 0,0
|
||||||
|
for i,k in pairs(items) do
|
||||||
|
local w = math.max(k.visual.w, #k.name*4)
|
||||||
|
local ox = (w-k.visual.w)/2
|
||||||
|
draw.text(k.name, x, y, 15)
|
||||||
|
draw.surf(k.visual.x, k.visual.y, k.visual.w, k.visual.h, x+ox, y+7)
|
||||||
|
if mx>x and mx<x+w and my>y and my<y+7+k.visual.h then
|
||||||
|
draw.rect(x+ox, y+7, k.visual.w, k.visual.h, 28)
|
||||||
|
if mouse.press(mouse.LEFT) then
|
||||||
|
editor.item_selected = i
|
||||||
|
app.pop()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
x=x+w+4
|
||||||
|
end
|
||||||
|
|
||||||
|
if key.press(key.TAB) or key.press(key.ESCAPE) then
|
||||||
|
app.pop()
|
||||||
|
end
|
||||||
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,7 @@ game = {
|
|||||||
game.chg_adv.y = y
|
game.chg_adv.y = y
|
||||||
game.chg_step = 8
|
game.chg_step = 8
|
||||||
sprites.pause_ia = true
|
sprites.pause_ia = true
|
||||||
|
-- [TODO] Crear els sprites per als items de l'habitació a la que entrem
|
||||||
app.push(game.update_change_room)
|
app.push(game.update_change_room)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ game = {
|
|||||||
sprites.update()
|
sprites.update()
|
||||||
game.chg_step = game.chg_step - 1
|
game.chg_step = game.chg_step - 1
|
||||||
if game.chg_step == 0 then
|
if game.chg_step == 0 then
|
||||||
|
sprites.remove_out_of_room()
|
||||||
sprites.pause_ia = false
|
sprites.pause_ia = false
|
||||||
app.pop()
|
app.pop()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
items = {
|
items = {
|
||||||
["mummy"] = {
|
[1] = {
|
||||||
|
name="mummy",
|
||||||
visual = {x=0,y=24,w=16,h=16}
|
visual = {x=0,y=24,w=16,h=16}
|
||||||
|
},
|
||||||
|
[2] = {
|
||||||
|
name="mummy2",
|
||||||
|
visual = {x=16,y=24,w=16,h=16}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,10 @@ rooms = {
|
|||||||
visibility = LAYER_ALL,
|
visibility = LAYER_ALL,
|
||||||
pos = {x=0, y=4*12},
|
pos = {x=0, y=4*12},
|
||||||
|
|
||||||
|
current = function()
|
||||||
|
return (rooms.pos.x//20) + (rooms.pos.y//12) * 8
|
||||||
|
end,
|
||||||
|
|
||||||
init = function()
|
init = function()
|
||||||
rooms.pos.x, rooms.pos.y = 0,4*12
|
rooms.pos.x, rooms.pos.y = 0,4*12
|
||||||
if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end
|
if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end
|
||||||
@@ -87,7 +91,7 @@ rooms = {
|
|||||||
|
|
||||||
-- Pintem els sprites de negre
|
-- Pintem els sprites de negre
|
||||||
if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then
|
if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then
|
||||||
sprites.draw()
|
sprites.draw(true)
|
||||||
--draw.surf(0, 0, 16, 17, 20, 15, 16, 17)
|
--draw.surf(0, 0, 16, 17, 20, 15, 16, 17)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,19 @@ sprites = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
remove_out_of_room = function()
|
||||||
|
for i,v in ipairs(sprites.list) do
|
||||||
|
if v.room ~= rooms.current() then
|
||||||
|
table.remove(sprites.list, i)
|
||||||
|
print("Sprite removed: "..v.type)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
add_from_room = function()
|
||||||
|
|
||||||
|
end,
|
||||||
|
|
||||||
init = function()
|
init = function()
|
||||||
sprites.hero = {
|
sprites.hero = {
|
||||||
type = "hero",
|
type = "hero",
|
||||||
@@ -287,11 +300,17 @@ sprites = {
|
|||||||
sprites.set_animation(sprites.hero, anim)
|
sprites.set_animation(sprites.hero, anim)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
draw = function()
|
draw = function(ignore_selected)
|
||||||
|
local mx,my = mouse.pos()
|
||||||
surf.source(surf_sprites)
|
surf.source(surf_sprites)
|
||||||
|
if editor.item_selected or editor.layer~=LAYER_ITEMS then ignore_selected = true end
|
||||||
for i,v in ipairs(sprites.list) do
|
for i,v in ipairs(sprites.list) do
|
||||||
|
if not ignore_selected and app.update == editor.update and mx>=v.pos.x and mx<=v.pos.x+v.size.w and my>=v.pos.y and my<=v.pos.y+v.size.h then
|
||||||
|
sprites.draw_sprite_selected(v)
|
||||||
|
else
|
||||||
sprites.draw_sprite(v)
|
sprites.draw_sprite(v)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
sprites.draw_sprite(sprites.hero)
|
sprites.draw_sprite(sprites.hero)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -305,5 +324,24 @@ sprites = {
|
|||||||
draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x, sprite.pos.y, frame.frame.w, frame.frame.h, (not reversed) ~= (not sprite.flipped))
|
draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x, sprite.pos.y, frame.frame.w, frame.frame.h, (not reversed) ~= (not sprite.flipped))
|
||||||
local x,y,w,h = util.aabb(sprite)
|
local x,y,w,h = util.aabb(sprite)
|
||||||
--draw.rect(x,y,w,h,8)
|
--draw.rect(x,y,w,h,8)
|
||||||
|
end,
|
||||||
|
|
||||||
|
draw_sprite_selected = function(sprite)
|
||||||
|
pal.subpal(0,32,28)
|
||||||
|
|
||||||
|
local cycle = animations[sprite.animation].cycle[sprite.current_frame]
|
||||||
|
local frame = animations[sprite.animation].frames[cycle]
|
||||||
|
local reversed = frame.reversed or false
|
||||||
|
local x, y, w, h, sx, sy, f = sprite.pos.x, sprite.pos.y, frame.frame.w, frame.frame.h, frame.frame.x, frame.frame.y, (not reversed) ~= (not sprite.flipped)
|
||||||
|
draw.surf(sx, sy, w, h, x-1, y-1, w, h, f)
|
||||||
|
draw.surf(sx, sy, w, h, x, y-1, w, h, f)
|
||||||
|
draw.surf(sx, sy, w, h, x+1, y-1, w, h, f)
|
||||||
|
draw.surf(sx, sy, w, h, x-1, y, w, h, f)
|
||||||
|
draw.surf(sx, sy, w, h, x+1, y, w, h, f)
|
||||||
|
draw.surf(sx, sy, w, h, x-1, y+1, w, h, f)
|
||||||
|
draw.surf(sx, sy, w, h, x, y, w, h, f)
|
||||||
|
draw.surf(sx, sy, w, h, x+1, y+1, w, h, f)
|
||||||
|
pal.subpal()
|
||||||
|
draw.surf(sx, sy, w, h, x, y, w, h, f)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,7 @@ templates = {
|
|||||||
else
|
else
|
||||||
error("Template not recognized")
|
error("Template not recognized")
|
||||||
end
|
end
|
||||||
|
sprite.room = rooms.current()
|
||||||
print("creat sprite de tipus "..type)
|
print("creat sprite de tipus "..type)
|
||||||
return sprite
|
return sprite
|
||||||
end,
|
end,
|
||||||
|
|||||||
Reference in New Issue
Block a user