new and improve

This commit is contained in:
Kimapr 2023-03-29 14:31:42 +05:00
parent 20b30e0731
commit 3d47fae141
2 changed files with 100 additions and 31 deletions

4
conf.lua Normal file
View file

@ -0,0 +1,4 @@
function love.conf(t)
t.width=400
t.height=400
end

101
main.lua
View file

@ -67,9 +67,21 @@ local tt=0
local bat=1
local batd=bat
local score=0
local tochar=0
local scored=score
local function znoise(...)
return love.math.noise(...)*2-1
end
local function eudist(x,y)
return (x*x+y*y)^0.5
end
local function norm(x1,y1)
local d=eudist(x,y)
if d==0 then return 0,0 end
return x/d,y/d
end
local function dlbolt(x,y,x1,y1)
end
local function drawfig(n,a)
g.push("all")
@ -133,7 +145,12 @@ end
local gemrng
local function randgem()
local objl=gemrng:random()>0.99 and cgobjs or gobjs
tochar=tochar-1
local objl=gobjs
if tochar<=0 then
tochar=gemrng:random((bw*bh)*0.5,(bw*bh)*1.5)
objl=cgobjs
end
return objl[gemrng:random(math.floor(cc))]
end
local function nextgem(o)
@ -163,11 +180,11 @@ local function badboigemcheck(c,am,ac,rm)
local rc=ac==5 and mgobjs[c] or lgobjs[c]
rm[e][3]=rc
end
local function megascan(c,rm)
local function megascan(x,y,c,rm)
local ogc=c
if not isgem(ogc) then return end
rm=rm or {}
if ogc.super~="color" then return end
if not isgem(ogc) then return next(rm) and rm end
if ogc.super~="color" then return next(rm) and rm end
for x=1,bw do
for y=1,bh do
local i=pti(x,y)
@ -180,7 +197,7 @@ local function megascan(c,rm)
end
local function check(x,y,rm,oam,obm)
local c=board[x][y]
if not c then return end
if not c then return rm,oam,obm end
local ac,bc=1,1
local am,bm={},{}
oam,obm=oam or {}, obm or {}
@ -413,27 +430,45 @@ killall=function(kills,b,...)
return killall(kills,...)
end
local tt={}
local kills,ko={},kills
local seen={}
local news=true
while news do
news=false
local ko
kills,ko={},kills
for k,v in pairs(ko) do
kills[k]=v
if not seen[k] then
local x,y=unpack(v)
local c=board[v[1]][v[2]]
seen[k]=true
if isgem(c) and c.super=="lines" then
for x=1,bw do
local i=pti(x,y)
if board[x][y] then
kills[i]=kills[i] or {x,y}
if board[x][y] and not kills[i] then
news=true
kills[i]={x,y}
end
end
for y=1,bh do
local i=pti(x,y)
if board[x][y] then
kills[i]=kills[i] or {x,y}
if board[x][y] and not kills[i] then
news=true
kills[i]={x,y}
end
end
end
if isgem(c) then
megascan(c,kills)
local mks={}
megascan(x,y,c,mks)
for k,v in pairs(mks) do
if not kills[k] then
kills[k]=v
news=true
end
end
end
end
end
end
for k,v in pairs(kills) do
@ -488,6 +523,7 @@ local function fillboard()
score=0
bat=1
gemrng=love.math.newRandomGenerator(991)
tochar=bw*bh+gemrng:random(bw)
for x=1,bw do
board[x]={}
for y=1,bh do
@ -513,6 +549,7 @@ local function fillboard()
dropall(-bh)
end
local dbg=false
local playdbg=false
function love.load()
fillboard()
@ -557,8 +594,9 @@ function love.mousereleased(x,y,b)
if ix and px and (ix~=px or iy~=py) then
board[ix][iy],board[px][py]=
board[px][py],board[ix][iy]
local kills=check(ix,iy,check(px,py,megascan(board[ix][iy],megascan(board[px][py]))))
if kills then
local kills=check(ix,iy,check(px,py))
if kills and board[ix][iy] and board[px][py] then
megascan(ix,iy,board[ix][iy],megascan(px,py,board[px][py],kills))
local ii,pi=pti(ix,iy),pti(px,py)
local ania,anib=anims[ii],anims[pi]
anims[ii],anims[pi]=anib,ania
@ -613,19 +651,41 @@ end
local animc=0
local entc=0
local boomc=0
local slow=false
local slow=1
local accumdt=0
local tps=120
local speeds={1,0.05,10}
function love.update(dt)
dt=math.min(dt,0.2)*(slow and 0.05 or 1)
accumdt=accumdt+dt
dt=math.min(dt,0.2)*(speeds[slow])
accumdt=math.min(1,accumdt+dt)
local fcc=0
while accumdt>1/tps do
fcc=fcc+1
local dt=1/tps
accumdt=accumdt-dt
if fcc>10 then return end
if running and playdbg then
for _=1,10 do
local ix,iy=math.random(1,bw),math.random(1,bh)
local px,py=0,0
while px<1 or py<1 or px>bw or py>bh do
local ox,oy=unpack(({{1,0},{-1,0},{0,1},{0,-1}})[math.random(1,4)])
px,py=ix+ox,iy+oy
end
board[ix][iy],board[px][py]=
board[px][py],board[ix][iy]
local kills=check(ix,iy,check(px,py))
if kills and board[ix][iy] and board[px][py] then
megascan(ix,iy,board[ix][iy],megascan(px,py,board[px][py],kills))
killall(kills)
break
else
board[ix][iy],board[px][py]=
board[px][py],board[ix][iy]
end
end
end
if running then
bat=math.max(0,bat-dt*0.015*(math.max(bat,0.0625)^0.5))
end
@ -806,11 +866,15 @@ function love.keypressed(k)
yls[x]=yl
end
elseif k=="f5" then
slow=not slow
slow=slow%3+1
elseif k=="f7" then
falltest=not falltest
elseif k=="f8" then
bat=bat*0.25
elseif k=="f9" then
bat=bat*2
elseif k=="f10" then
playdbg=not playdbg
end
end
@ -818,9 +882,10 @@ function love.draw()
if dbg then
g.push("all")
g.scale(2,2)
love.graphics.print(("FPS: %i; dt: %.2f; anims: %i; fallings: %i; booms: %i"):format(
love.graphics.print(("FPS: %i; dt: %.2f; speed: %f; anims: %i; fallings: %i; booms: %i"):format(
love.timer.getFPS(),
math.floor(love.timer.getDelta()*100000)/100,
speeds[slow],
animc, entc, boomc
))
g.pop()