Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tiles = {{0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0}
- }
- timer = 1
- speed = 0
- r={}
- fps={}
- fps.old=os.time()
- fps.enable=true
- c={1} --таблица цветов. просто для упрощения жизни.
- for i=1,15 do
- c[#c+1]=2^i
- end
- mouse={}
- mouse.x=0
- mouse.y=0
- r.s={} -- таблица для рендера.
- r.sx,r.sy=term.getSize() -- размер экрана
- r.d={} -- таблица для сравнения рендеров.
- r.se={} -- таблица несовпадений рендеров.
- r.to=os.time()
- r.renderspeed=0 -- чем больше число тем больше сошибок делает рендер но fps будет выше. если поставить 0 то fps упадет до 10 до не будет глюков рендера.
- gh={}
- angle=0
- defbackcolor=16 -- цвет заднего фона.
- keypress=0
- lcolor=1
- function limit(n,n1) -- 1<n<n1
- local x=math.min(n,n1)
- local nx=math.max(1,x)
- return nx
- end
- function fps.update()
- local delta=(os.time()-fps.old)*1000*0.05
- fps.old=os.time()
- return math.floor(1/delta)
- end
- for y=1,r.sy do
- r.s[y]={}
- for x=1,r.sx do
- r.s[y][x]={16,16," "}
- end end
- for y=1,r.sy do
- r.d[y]={}
- for x=1,r.sx do
- r.d[y][x]={16,16,"X"}
- end end
- function all(t,v)
- local a = true
- for i,b in ipairs(t) do
- if b~=v then
- a = false
- end
- end
- return a
- end
- function update()
- -- code from https://www.love2d.org/forums/viewtopic.php?f=3&t=77616&start=10
- local falling = false
- for j=#tiles,1,-1 do
- for i,v in ipairs(tiles[j]) do
- if v > 0 then
- if j~=#tiles then
- if tiles[j+1][i]~=1 then
- tiles[j+1][i] = tiles[j][i]
- tiles[j][i] = 0
- falling = true
- else
- tiles[j][i] = 1
- end
- else
- tiles[j][i] = 1
- end
- end
- end
- if all(tiles[j],1) then
- tiles[j] = {0,0,0,0,0,0,0,0,0,0,0}
- end
- end
- if falling == false then
- tiles[1] = {0,0,0,0,0,0,0,0,0,0,0}
- tiles[1][math.random(#tiles[1])] = 2
- end
- end
- function gh.rectangle(x,y,x2,y2,mode,color,altcolor,text)
- local func={}
- func["line"]= function(x,y,x2,y2,color,altcolor,text)
- for nx=1,x2 do
- for ny=1,y2 do
- if nx==1 or nx==x2 or ny==1 or ny==y2 then
- gh.point(x+nx,y+ny,color,altcolor,text) end
- end end
- end
- func["fill"]= function(x,y,x2,y2,color,altcolor,text)
- for nx=1,x2 do
- for ny=1,y2 do
- gh.point(x+nx,y+ny,color,altcolor,text)
- end end
- end
- func[mode](x,y,x2,y2,color,altcolor,text)
- end
- function gh.point(x,y,color,altcolor,text)
- r.s[y][x]={color,altcolor,text}
- end
- function gh.text(x,y,color,altcolor,text)
- text2= text..""
- local i=0
- for w in string.gmatch(text2, ".") do
- gh.point(x+i,y,color,altcolor,w)
- i=i+1
- end
- end
- function gh.line(x2,y2,x3,y3,color,altcolor,text)
- local x=x3-x2
- local y=y3-y2
- local nx=x2
- local ny=y2
- local h=math.sqrt(x^2+y^2)
- local sina= y/h
- local cosa= x/h
- for i=1,h do
- gh.point(math.floor(nx),math.floor(ny),color,altcolor,text)
- nx=nx+cosa
- ny=ny+sina
- end
- end
- function draw()
- for j,v in ipairs(tiles) do
- for i,t in ipairs(v) do
- if t > 0 then gh.point(math.floor((r.sx-#tiles)/2+i) ,math.floor((r.sy-#tiles[1])/2+j),1,16,"#") end
- end end
- gh.rectangle((r.sx-#tiles)/2-1,(r.sy-#tiles[1])/2-1,#tiles[1]+2,#tiles+2,"line",1,16,"O")
- gh.text(2,2,1,16,"fps:"..fps.update())
- -- пререндер
- for y=1,r.sy do
- for x=1,r.sx do
- for i=1,3 do
- if r.s[y][x][i]==r.d[y][x][i] then else
- r.se[#r.se+1]={y,x,r.s[y][x][1],r.s[y][x][2],r.s[y][x][3]}
- r.d[y][x][i]=r.s[y][x][i]
- r.s[y][x]={16,16," "}
- end
- end
- end
- -- рендер
- if #r.se>0 then
- for i=#r.se,1,-1 do
- term.setCursorPos(r.se[i][2],r.se[i][1])
- term.setTextColor(c[r.se[i][3] ])
- term.setBackgroundColor(c[r.se[i][4] ])
- write(r.se[i][5])
- r.se[i]=nil
- end
- end
- end
- for y=1,r.sy do
- for x=1,r.sx do
- r.s[y][x]={16,16," "}
- end end
- end
- while true do
- update()
- draw()
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement