Advertisement
Redxone

[CC - E3] BuffPixel: Game Example

Jan 28th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. os.loadAPI("buffpixel")
  2. write("Enter Window Width: ")
  3. local win_width = tonumber(read())
  4. write("Enter Window Height: ")
  5. local win_height = tonumber(read())
  6. write("Enter Window X: ")
  7. local win_x = tonumber(read())
  8. write("Enter Window Y: ")
  9. local win_y = tonumber(read())
  10. local w, h = term.getSize()
  11. term.clear()
  12. paintutils.drawBox(win_x, win_y, win_x+win_width+1, win_y+win_height+1, colors.gray)
  13. buff = buffpixel.new(w*4,h*4,0, 0 , win_width, win_height )
  14. buff:setClock(0.8)
  15. local pix = buff.newPixel
  16. buff:setRenderOffset(win_x,win_y)
  17. local collide = true
  18. local rw, rh = math.ceil(w/2), math.ceil(h/2)
  19. buff:fillMap(pix("5D","*",false))
  20. buff:setPixel(w-1,10,pix("87","@",true))
  21. buff:newPlayer("BG","&",1,1,keys.w,keys.s,keys.a,keys.d,keys.e,1)
  22. buff:setTPixel(1,5,"BG@")
  23. buff:addEntityByName("testnpc",
  24. {x = 1, y = 5, getPos = function(self) return self.x, self.y end,
  25. update = function(self, e)
  26.    local ry = 0
  27.    local rx = math.ceil(math.random(0,1))
  28.    if(rx == 0)then ry = math.ceil(math.random(-1,1)) end
  29.    if(not buff:checkCollision(self.x+rx,self.y+ry))then
  30.       buff:moveTPixel(self.x,self.y,rx,ry)
  31.       self.x = self.x + rx
  32.       self.y = self.y + ry
  33.    end
  34. end,
  35. interact = function()
  36.    buff:openDialog(colors.lightGray,colors.blue)
  37.    buff:drawDialog("First dialogbox!",50,colors.white)
  38.    if(buff:getDialogYesNo("Yea","Nope",2) == "yes")then
  39.       buff:clearDialog(colors.lightGray,colors.white)
  40.       buff:drawDialog("First yes and no result!",50,colors.black)
  41.       buff:closeDialog()
  42.    else
  43.       buff:closeDialogRaw()
  44.    end
  45. end})
  46. buff:setTPixelSolid(1,5,1)
  47. buff:render()
  48. buff:newHud("topbar",1,1,w,1,
  49.    function()
  50.       term.setTextColor(colors.white)
  51.       term.setBackgroundColor(colors.gray)
  52.       buff:setHudCursorPos("topbar",0,0)
  53.       term.clearLine()
  54.       write("Left click to place : Right click to break" .. " " .. buff.clock)
  55.    end,
  56.    function(e)
  57.        term.current().setVisible(false)
  58.        buff:drawHud("topbar")
  59.        term.current().setVisible(true)
  60.    end
  61. )
  62. function nocliptoggle(self)
  63.    self.collide = not self.collide
  64.    buff:playerSolidCollision(self.collide)
  65.    if(not self.collide)then
  66.       buff:setPlayerGraphic("0G","^")
  67.    else
  68.       buff:setPlayerGraphic("BG","&")
  69.    end
  70. end
  71. buff:addPlayerEvent("noclip",{"key",keys.n},nocliptoggle)
  72. buff.player.events['noclip'].collide = true
  73. while true do
  74.     local e = { os.pullEvent() }
  75.    buff:getMousePlaceBlock(e,pix("87","@",true),pix("5D","*",false))
  76.    buff:updatePlayer(e)
  77.    buff:updateWithClock(e)
  78.    if(e[1] == "key")then
  79.       local key = e[2]
  80.       if(key == keys.left)then
  81.          buff:updateView(1,0,0,0,true)
  82.       end
  83.       if(key == keys.right)then
  84.          buff:updateView(-1,0,0,0,true)
  85.       end
  86.       if(key == keys.up)then
  87.          buff:updateView(0,1,0,0,true)
  88.       end
  89.       if(key == keys.down)then
  90.          buff:updateView(0,-1,0,0,true)
  91.       end
  92.    end
  93.     local px, py = buff:getPlayerPos()
  94.     local pox, poy = buff:getOutsideViews(px,py,1,1)
  95.    buff:lerpView(pox,poy,win_width/2,win_height/2,0)
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement