Advertisement
Redxone

[CC - E3] BuffPixel - Game windows!

Feb 1st, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. os.loadAPI("buffpixel")
  2. local w, h = term.getSize()
  3. term.clear()
  4. game = {}
  5. local win_width, win_height, win_x, win_y = 20,10,5,3
  6. game[1] = buffpixel.new(w*4,h*4,0, 0 , win_width, win_height )
  7. game[2] = buffpixel.new(w*4,h*4,0, 0 , win_width, win_height )
  8. local pix = game[1].newPixel
  9. selection = 2
  10. function swapselect(s)
  11.        selection = s
  12.        game[getother(s)]:drawBorder(colors.lightGray)
  13.        game[s]:drawBorder(colors.blue)
  14.        game[s]:refreshRender()
  15.        game[s]:drawPlayer()
  16. end
  17. function getother(s)
  18.   if(s == 1)then
  19.       return tonumber(2)
  20.   elseif(s == 2)then
  21.       return tonumber(1)
  22.   end
  23. end
  24. game[1]:setRenderOffset(win_x,win_y)
  25. game[2]:setRenderOffset(win_x+10,win_y)
  26. local rw, rh = math.ceil(w/2), math.ceil(h/2)
  27. game[1]:fillMap(pix("5D","*",false))
  28. game[2]:fillMap(pix("5D"," ",false))
  29. game[1]:setPixel(w-1,10,pix("87","@",true))
  30. game[1]:newPlayer("BG","&",win_width/2,win_height/2,keys.w,keys.s,keys.a,keys.d,keys.e,1)
  31. game[2]:newPlayer("BG","@",win_width/2,win_height/2,keys.w,keys.s,keys.a,keys.d,keys.e,1)
  32. game[1]:setBorderText("Game: advanced graphics", colors.white)
  33. game[2]:setBorderText("Game:  Basic graphics", colors.white)
  34. game[getother(selection)]:refreshRender()
  35. game[getother(selection)]:drawBorder(colors.blue)
  36. game[selection]:refreshRender()
  37. game[selection]:drawBorder(colors.lightGray)
  38. local pmx, pmy = 0, 0
  39. term.setBackgroundColor(colors.blue)
  40. term.setTextColor(colors.white)
  41. term.setCursorPos(1,1)
  42. term.clearLine()
  43. write("Click inside a window to focus, Drag to move")
  44. while true do
  45.    local gox, goy = game[selection]:getRenderOffsets()
  46.    local gw, gh = game[selection]:getWidth(), game[selection]:getHeight()
  47.    local e = { os.pullEvent() }
  48.    if(e[1] == "mouse_click")then
  49.          pmx = e[3]
  50.          pmy = e[4]
  51.       if(not game[2]:isOutsideView(e[3],e[4]) and selection == 1 and game[1]:isOutsideView(e[3],e[4]))then
  52.          swapselect(2)
  53.       end
  54.       if(not game[1]:isOutsideView(e[3],e[4]) and selection == 2 and game[2]:isOutsideView(e[3],e[4]))then
  55.           swapselect(1)
  56.       end
  57.    elseif(e[1] == "mouse_drag" and e[4]+gh < h and (e[3] - (gw/2)+gw) < w and e[4] > 1)then
  58.       pmx = e[3]
  59.       if(pmy == game[selection].roffy and pmx >= gox and pmx <= gox+gw)then
  60.           game[selection]:setScreenPos(e[3] - (gw/2),e[4], colors.black)
  61.           game[selection]:drawBorder(colors.blue)
  62.           term.current().setVisible(false)
  63.           game[getother(selection)]:refreshRender(1)
  64.           game[getother(selection)]:drawBorder(colors.lightGray)
  65.           game[selection]:refreshRender(1)
  66.           game[selection]:drawBorder(colors.blue)
  67.           term.current().setVisible(true)
  68.           iscol = false
  69.           pmy = e[4]
  70.       end
  71.    end
  72.    if(selection == 1)then
  73.       game[1]:getMousePlaceBlock(e,pix("87","@",true),pix("5D","*",false))
  74.    else
  75.       game[2]:getMousePlaceBlock(e,pix("87"," ",true),pix("5D"," ",false))
  76.    end
  77.  
  78.    game[selection]:updatePlayer(e,0)
  79.    local px, py = game[selection]:getPlayerPos()
  80.    local pox, poy = game[selection]:getOutsideViews(px,py,1,1)
  81.    game[selection]:lerpView(pox,poy,win_width/2,win_height/2,0)
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement