Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function gamemap(ww,hh,cc)
- print("Generating map....")
- buffmap = {}
- for yy = 1, hh do
- buffmap[yy] = {}
- for xx = 1, ww do
- buffmap[yy][xx] = {}
- end
- end
- paintutils.drawFilledBox(0,0,ww,hh,cc)
- term.setCursorPos(1,1)
- local field = {
- screen = buffmap,
- cls = cc,
- w = ww,
- h = hh,
- -- Basic blueprint - {x,y,tcolor,bcolor,chr}
- addpixel = function(self,xx,yy,chr,tcolor,bcolor)
- if(#chr > 1)then
- for i = 1, #chr do
- self.screen[yy][xx+(i-1)] = {tc=tcolor,bc=bcolor,ch=chr:sub(i,i)}
- self:drawpixel(xx+(i-1),yy)
- end
- else
- self.screen[yy][xx] = {tc=tcolor,bc=bcolor,ch=chr}
- self:drawpixel(xx,yy)
- end
- end,
- addtag = function(self,x,y,tname,tdata)
- self.screen[y][x][tname] = tdata
- end,
- removepixel = function(self,x,y)
- self.screen[y][x] = {}
- self:drawpixel(x,y)
- end,
- buff_drawpixel = function(npix)
- if(not npix.tc)then
- term.setBackgroundColor(self.cls)
- write(" ")
- end
- term.setBackgroundColor(npix.bc)
- term.setTextColor(npix.tc)
- term.setCursorPos(npix.x, npix.y)
- write(npix.ch)
- term.setBackgroundColor(self.cls)
- end,
- drawpixel = function(self,xx,yy)
- if(self.screen[yy][xx].ch)then
- term.setBackgroundColor(self.screen[yy][xx].bc)
- term.setTextColor(self.screen[yy][xx].tc)
- term.setCursorPos(xx, yy)
- write(self.screen[yy][xx].ch)
- term.setBackgroundColor(self.cls)
- else
- term.setBackgroundColor(self.cls)
- term.setCursorPos(xx, yy)
- write(" ")
- end
- end,
- movepixel = function(self,x,y,xx,yy)
- if(self.screen[y+yy] ~= nil)then
- if(self.screen[y+yy][x+xx] ~= nil)then
- tmp = self.screen[y][x]
- self.screen[y][x] = {}
- self:drawpixel(x,y)
- self.screen[y+yy][x+xx] = tmp
- self:drawpixel(x+xx,y+yy)
- return true
- end
- end
- return false --]] Spot not available (Most likely it doesnt exist)
- end,
- --]] Useful for moving pixels and changing tags like pixel x and y's
- movepixel_tags = function(self,x,y,xx,yy,tagandvals)
- self:movepixel(x,y,xx,yy)
- local pix = self.screen[y+yy][x+xx]
- for k, v in pairs(tagandvals) do
- if(pix[k])then pix[k] = v end
- end
- self.screen[y+yy][x+xx] = pix
- end,
- checkforpixel = function(self,x,y)
- return (self.screen[y][x].ch ~= nil)
- end,
- getpixel = function(self,x,y)
- return self.screen[y][x]
- end,
- gettag = function(self,x,y,tname)
- return self.screen[y][x][tname]
- end,
- setpixelcolor = function(self,x,y,t,b)
- if(self.screen[y][x])then
- if(self.screen[y][x].ch)then
- self.screen[y][x].tc = t
- self.screen[y][x].bc = b
- self:drawpixel(x,y)
- end
- end
- end,
- setclearcolor = function(self,c)
- self.clear = c
- end,
- drawscreen = function(self)
- term.setBackgroundColor(self.cls)
- for yy = 1, self.h do
- for xx = 1, self.w do
- if(self.screen[yy][xx].ch)then
- term.setBackgroundColor(self.screen[yy][xx].bc)
- term.setTextColor(self.screen[yy][xx].tc)
- term.setCursorPos(xx, yy)
- write(self.screen[yy][xx].ch)
- term.setBackgroundColor(self.cls)
- else
- term.setCursorPos(xx, yy)
- write(" ")
- end
- end
- end
- end,
- shift = function(self,w,h,xo,yo)
- for yy = 1, h do
- for xx = 1, w do
- tmp = self.screen[yy][xx]
- self.screen[yy][xx] = {}
- self:drawpixel(yy,xx)
- self.screen[yy+yo][xx+xo] = tmp
- end
- end
- end,
- }
- field:drawscreen()
- return field
- end
- local mybuff = gamemap(51,19,colors.black)
- mybuff:addpixel(5,5,"HEYEYYY A STRING",colors.white,colors.blue)
- mybuff:addpixel(5,7,"LOLOLOL A LONNNNNNGGGERRR STRING XD",colors.white,colors.blue)
- term.setCursorPos(1,15)
- term.setBackgroundColor(colors.black)
- while true do
- local e = {os.pullEvent()}
- if(e[1] == "mouse_click" or e[1] == "mouse_drag" )then
- if(e[4] <= mybuff.h)then
- mybuff:setpixelcolor(e[3],e[4],colors.blue,colors.white)
- sleep(0.2)
- if(mybuff:checkforpixel(e[3],e[4]))then
- mybuff:setpixelcolor(e[3],e[4],colors.white,colors.blue)
- mybuff:movepixel(e[3],e[4],math.random(20),math.random(19))
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement