first commit

This commit is contained in:
2022-10-22 07:53:12 +02:00
commit e1f1e0e95c
10 changed files with 1476 additions and 0 deletions

127
main.lua Normal file
View File

@@ -0,0 +1,127 @@
--hab=0
modes={playing=0,editing=1}
mode=modes.editing
seltile = 0
actors={}
function _init()
tiles=loadsurf("tiles.gif")
setsource(tiles)
local pal=loadpal("tiles.gif")
setpal(pal)
--mapa_new()
abad_init()
table.insert(actors,abad)
z = zombie.new()
table.insert(actors,z)
c=caco.new(10,24,16)
table.insert(actors,c)
score.create()
end
function text(str,x,y,col)
color(16)
prnt(str,x-1,y-1)
prnt(str,x,y-1)
prnt(str,x+1,y-1)
prnt(str,x-1,y)
prnt(str,x+1,y)
prnt(str,x-1,y+1)
prnt(str,x,y+1)
prnt(str,x+1,y+1)
prnt(str,x,y,col)
end
function draw_hab(hab,x,y,editing)
camera(-x,-y)
mapa_draw(hab)
if not editing then
for key,actor in pairs(actors) do
if actor.hab==hab then
actor:draw()
end
end
if cacau.hab==hab then cacau:draw() end
end
camera(0,0)
end
function _update()
cls(16)
if mode==modes.editing then
draw_hab(abad.hab,0,0,true)
text(abad.hab,100,10,2)
sspr(0,64,128,48,0,48)
color(3)
local xx=(seltile&15)*8
local yy=48+(seltile>>4)*8
rect(xx,yy,xx+8,yy+8)
text("EDIT",100,1,3)
local hx = abad.hab%10
local hy = flr(abad.hab/10)
if btnp(KEY_RIGHT) and hx<9 then
abad.hab=abad.hab+1
elseif btnp(KEY_LEFT) and hx>0 then
abad.hab=abad.hab-1
elseif btnp(KEY_DOWN) and hy<7 then
abad.hab=abad.hab+10
elseif btnp(KEY_UP) and hy>0 then
abad.hab=abad.hab-10
elseif btnp(KEY_RETURN) then
mode=modes.playing
elseif btnp(KEY_S) then
mapa_save()
elseif btnp(KEY_C) then
mapa_cycle_colors(abad.hab)
end
local mx,my=mousex(),mousey()
if mbtn(1) then
if my>=48 then
seltile=(mx>>3)+((my-48)>>3)*16
elseif mx<96 then
mapa_set_tile(abad.hab,mx>>3,my>>3,seltile)
end
elseif mbtn(3) then
if my<48 and mx<96 then
mapa_set_tile(abad.hab,mx>>3,my>>3,255)
end
end
else
draw_hab(abad.hab,0,0)
text(abad.hab,1,1,2)
draw_hab(10,0,48)
score.draw()
setsource(tiles)
prnt("x"..abad.vides,114,13,2)
rectfill(102+(abad.energia>>1),30,122,37,16)
for key,actor in pairs(actors) do
actor:update()
if actor.hab==cacau.hab and actor~=abad then
if aabb(actor,cacau) then
actor:hit()
cacau.hab=-1
end
end
end
cacau.update()
if btnp(KEY_RETURN) then
mode=modes.editing
end
end
end
function aabb(a, b)
return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x) and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) and (a.y+a.bb.y+a.bb.h >= b.y+b.bb.y) and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h)
end