- [NEW] Convertit a mini v1.0 RC2

This commit is contained in:
2025-05-31 14:29:29 +02:00
parent 28f9851f00
commit c2f7b470bf
14 changed files with 241 additions and 244 deletions

View File

@@ -28,35 +28,35 @@ editor={
end,
reload_textures=function()
freesurf(sprites)
freesurf(objectes)
freesurf(tiles)
sprites=loadsurf("sprites.gif")
objectes=loadsurf("objects.gif")
tiles=loadsurf("tiles.gif")
setsource(tiles)
local pal=loadpal("tiles.gif")
setpal(pal)
surf.free(sprites)
surf.free(objectes)
surf.free(tiles)
sprites=surf.load("sprites.gif")
objectes=surf.load("objects.gif")
tiles=surf.load("tiles.gif")
surf.source(tiles)
local p=pal.load("tiles.gif")
pal.set(p)
editor.paused=false
end,
toggle_front_layer=function()
if editor.editing_front_layer then
setmap(mapa.surface)
map.set(mapa.surface)
editor.editing_front_layer=false;
else
if not mapa.front_layer then
mapa.front_layer=newsurf(mapa.w,mapa.h)
mapa.front_layer=surf.new(mapa.w,mapa.h)
editor.editing_front_layer=true
setmap(mapa.front_layer)
map.set(mapa.front_layer)
for y=0,mapa.h-1 do
for x=0,mapa.w-1 do
mset(x,y,0)
map.tile(x,y,0)
end
end
else
editor.editing_front_layer=true
setmap(mapa.front_layer)
map.set(mapa.front_layer)
end
end
editor.paused=false
@@ -76,27 +76,27 @@ editor={
local old_surface= mapa.surface
mapa.w=tonumber(editor.new_w)
mapa.h=tonumber(editor.new_h)
mapa.surface=newsurf(mapa.w,mapa.h)
mapa.surface=surf.new(mapa.w,mapa.h)
for y=0,mapa.h-1 do
for x=0,mapa.w-1 do
setmap(old_surface)
local value=mget(x,y)
setmap(mapa.surface)
mset(x,y,value)
map.set(old_surface)
local value=map.tile(x,y)
map.set(mapa.surface)
map.tile(x,y,value)
end
end
freesurf(old_surface)
setmap(mapa.surface)
surf.free(old_surface)
map.set(mapa.surface)
editor.paused=false
end,
floodfill=function(x,y,tile)
local t=mget(x,y)
mset(x,y,tile)
if x<mapa.w-1 and mget(x+1,y)==t then editor.floodfill(x+1,y,tile) end
if x>0 and mget(x-1,y)==t then editor.floodfill(x-1,y,tile) end
if y<mapa.h-1 and mget(x,y+1)==t then editor.floodfill(x,y+1,tile) end
if y>0 and mget(x,y-1)==t then editor.floodfill(x,y-1,tile) end
local t=map.tile(x,y)
map.tile(x,y,tile)
if x<mapa.w-1 and map.tile(x+1,y)==t then editor.floodfill(x+1,y,tile) end
if x>0 and map.tile(x-1,y)==t then editor.floodfill(x-1,y,tile) end
if y<mapa.h-1 and map.tile(x,y+1)==t then editor.floodfill(x,y+1,tile) end
if y>0 and map.tile(x,y-1)==t then editor.floodfill(x,y-1,tile) end
end,
create_stamp=function()
@@ -109,8 +109,8 @@ editor={
local p=1
for y=1,h do
for x=1,w do
editor.brush.tiles[p]=mget(tx1+x-1,ty1+y-1)
--mset(tx+x-1,ty+y-1,editor.brush.tiles[p])
editor.brush.tiles[p]=map.tile(tx1+x-1,ty1+y-1)
--map.tile(tx+x-1,ty+y-1,editor.brush.tiles[p])
p=p+1
end
end
@@ -122,7 +122,7 @@ editor={
local p=1
for y=1,h do
for x=1,w do
mset(tx+x-1,ty+y-1,editor.brush.tiles[p])
map.tile(tx+x-1,ty+y-1,editor.brush.tiles[p])
p=p+1
end
end
@@ -133,57 +133,57 @@ editor={
if dx>0 then
for y=0,h-1 do
for x=w-1,1,-1 do
mset(x,y,mget(x-1,y))
map.tile(x,y,map.tile(x-1,y))
end
end
elseif dx<0 then
for y=0,h-1 do
for x=0,w-2 do
mset(x,y,mget(x+1,y))
map.tile(x,y,map.tile(x+1,y))
end
end
elseif dy>0 then
for y=h-1,1,-1 do
for x=0,w-1 do
mset(x,y,mget(x,y-1))
map.tile(x,y,map.tile(x,y-1))
end
end
elseif dy<0 then
for y=0,h-2 do
for x=0,w-1 do
mset(x,y,mget(x,y+1))
map.tile(x,y,map.tile(x,y+1))
end
end
end
end,
update=function()
cls()
camera(editor.cam.x, editor.cam.y)
setsource(tiles)
setmap(mapa.surface)
map(0,0,0,0,mapa.w, mapa.h)
surf.cls()
view.origin(editor.cam.x, editor.cam.y)
surf.source(tiles)
map.set(mapa.surface)
map.draw() --map(0,0,0,0,mapa.w, mapa.h)
if mapa.front_layer then
setmap(mapa.front_layer)
map(0,0,0,0,mapa.w, mapa.h)
map.set(mapa.front_layer)
map.draw() --map(0,0,0,0,mapa.w, mapa.h)
end
if editor.editing_front_layer then
setmap(mapa.front_layer)
map.set(mapa.front_layer)
text("EDITING FRONT LAYER",12,2,10)
else
setmap(mapa.surface)
map.set(mapa.surface)
end
local mx,my=mouse()
local mx,my=mouse.pos()
local tx,ty=(mx+editor.cam.x)>>3,(my+editor.cam.y)>>3
local rx,ry=tx<<3,ty<<3
rect(rx-1, ry-1, rx+8, ry+8, 10)
draw.rect(rx-1, ry-1, 10, 10, 10)
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
if rx1>rx2 then rx1,rx2=rx2,rx1 end
if ry1>ry2 then ry1,ry2=ry2,ry1 end
rect(rx1-1, ry1-1, rx2+8, ry2+8, 8)
draw.rect(rx1-1, ry1-1, rx2-rx1+10, ry2-ry1+10, 8)
end
camera(0,0)
view.origin(0,0)
if tx>=0 and
ty>=0 and
tx<mapa.w and
@@ -191,11 +191,11 @@ editor={
text(tx..","..ty,2,2,8)
end
if not editor.paused then
if mbtn(1) then
if mouse.down(mouse.LEFT) then
editor.stamp(tx,ty)
--mset(tx,ty,editor.brush.tiles[1])
--map.tile(tx,ty,editor.brush.tiles[1])
end
if mbtn(3) then
if mouse.down(mouse.RIGHT) then
if editor.selection then
editor.selection.x2=tx
editor.selection.y2=ty
@@ -213,55 +213,55 @@ editor={
end
end
if btn(KEY_LSHIFT) then
if btnp(KEY_RIGHT) then editor.displace(1,0) end
if btnp(KEY_LEFT) then editor.displace(-1,0) end
if btnp(KEY_UP) then editor.displace(0,-1) end
if btnp(KEY_DOWN) then editor.displace(0,1) end
if key.down(key.LSHIFT) then
if key.press(key.RIGHT) then editor.displace(1,0) end
if key.press(key.LEFT) then editor.displace(-1,0) end
if key.press(key.UP) then editor.displace(0,-1) end
if key.press(key.DOWN) then editor.displace(0,1) end
else
if btnp(KEY_RIGHT) then editor.cam.x=editor.cam.x+8 end
if btnp(KEY_LEFT) then editor.cam.x=editor.cam.x-8 end
if btnp(KEY_UP) then editor.cam.y=editor.cam.y-8 end
if btnp(KEY_DOWN) then editor.cam.y=editor.cam.y+8 end
if key.press(key.RIGHT) then editor.cam.x=editor.cam.x+8 end
if key.press(key.LEFT) then editor.cam.x=editor.cam.x-8 end
if key.press(key.UP) then editor.cam.y=editor.cam.y-8 end
if key.press(key.DOWN) then editor.cam.y=editor.cam.y+8 end
end
if btnp(KEY_F) then
if key.press(key.F) then
editor.floodfill(tx,ty,editor.brush.tiles[1])
end
if btnp(KEY_1) then
if key.press(key.N1) then
if editor.editing_front_layer then
editor.editing_front_layer=nil
else
editor.editing_front_layer=true
end
end
if btnp(KEY_RETURN) then
editor.brush.tiles[1]=mget(tx,ty)
if key.press(key.RETURN) then
editor.brush.tiles[1]=map.tile(tx,ty)
end
if btnp(KEY_ESCAPE) then
if key.press(key.ESCAPE) then
editor.paused=true
editor.show_menu()
end
if btnp(KEY_TAB) then
if key.press(key.TAB) then
update=editor.update_tileset
end
end
end,
update_tileset=function()
cls()
blit(0,0,128,128,0,0)
surf.cls()
draw.surf(0,0,128,128,0,0)
local mx,my=mouse()
local mx,my=mouse.pos()
local tx,ty=mx>>3,my>>3
local rx,ry=tx<<3,ty<<3
rect(rx-1, ry-1, rx+8, ry+8, 10)
draw.rect(rx-1, ry-1, 10, 10, 10)
if btnp(KEY_TAB) or btnp(KEY_ESCAPE) then
if key.press(key.TAB) or key.press(key.ESCAPE) then
update=editor.update
end
if mbtnp(1) then
if mouse.press(mouse.LEFT) then
if tx<16 and ty<16 then
editor.brush.w=1
editor.brush.h=1