Advertisement
Redxone

[RedGame] - Multiplayer Demo

Jul 27th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. os.loadAPI("RedGame")
  2. mod = peripheral.find("modem")
  3. mod.open(1)
  4. RedGame.init()
  5. local w, h = term.getSize()
  6.  
  7. local receive = function(ev)
  8.     packet  = ev[5]
  9.     term.setCursorPos(1,1)
  10.     write(packet.x.."<->"..packet.y)
  11. end
  12. local mytest = function()
  13.     paintutils.drawBox(1,h-5,w,h,colors.gray)
  14.     paintutils.drawFilledBox(2,h-4,w-1,h-1,colors.blue)
  15.     term.setCursorPos(6,h-4)
  16.     term.setTextColor(colors.white)
  17.     textutils.slowPrint("Hello, i am the VERY FIRST npc in redgame!",55)
  18.     term.setCursorPos(5,h-3)
  19.     textutils.slowPrint("Textbox methods have not been setup as of yet.",55)
  20.     os.pullEvent("key")
  21.     RedGame.draw()
  22. end
  23.  
  24. inlevel = 'main_room'
  25. local level = RedGame.getResource("mylevel_image")
  26. local block = RedGame.getResource("mylevel_blocks")
  27. local level2 = RedGame.getResource("mylevel2")
  28. RedGame.setMap("MAP001",level,block)
  29.  
  30. p = RedGame.createPlayer(1,20,8)
  31. p:addEvent("modem_message",receive)
  32. RedGame.editBlock(1,"purple","blue","$",true)
  33. p:put()
  34. p2 = RedGame.createPlayer(3,20,7)
  35. p2:put()
  36. RedGame.draw()
  37. p:addInteraction("MAP001",20,7,mytest)
  38. while true do
  39.     packet = {
  40.         x=p.x,
  41.         y=p.y,
  42.     }
  43.     if(p:getBlockUnder() == 11 and inlevel == 'main_room')then
  44.         RedGame.setMap("MAP001",level2,block)
  45.         p:setPos(19,13)
  46.         inlevel = 'door_1'
  47.         RedGame.draw()
  48.     end
  49.     if(p:getBlockUnder() == 11 and inlevel == 'door_1')then
  50.         RedGame.setMap("MAP002",level,block)
  51.         p:setPos(17,9) 
  52.         RedGame.draw()
  53.         inlevel = 'main_room'
  54.     end
  55.     p:update()
  56.     mod.transmit(1,1,packet)
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement