Advertisement
Redxone

[CC-LWLGL] Dynamic backgrounds DEMO

May 25th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. os.loadAPI("LWLGL")
  2. bgs = LWLGL.initBackgrounds()
  3. w, h = LWLGL.w, LWLGL.h
  4. timer = os.startTimer(0.1)
  5. bgs:add({name="t1",file="testimg",bc="blue",x=1,y=1,update=function(self)
  6.     bgs:draw("t1",self.x,self.y)
  7. end})
  8. bgs:add({name="t2",file="clouds",bc="blue",x=1,y=1,update=function(self)
  9.     bgs:draw("t2",self.x,self.y)
  10.     if(self.x >= w+2)then
  11.         self.x = -w
  12.         change = math.max(math.random(1,2))
  13.         if(change == 1)then
  14.             self.file = "sky2"
  15.         else
  16.             self.file = "clouds"
  17.         end
  18.     end
  19.  
  20.     self.x = self.x + 2
  21. end})
  22. bgs:add({name="t3",file="grass",bc="green",x=1,y=5,xdir=1,update=function(self)
  23.     bgs:draw("t3",self.x,self.y)
  24.     if(self.xdir == 1)then
  25.         self.x=self.x+1
  26.         if(self.x >= 5)then self.xdir = 2 end
  27.         elseif(self.xdir == 2)then self.x=self.x-1
  28.             if(self.x <= 0)then
  29.                 self.xdir = 1
  30.             end
  31.         end
  32. end})
  33. bgs:add({name="t4",file="clouds",bc="blue",x=-w,y=1,update=function(self)
  34.     bgs:draw("t4",self.x,self.y)
  35.     if(self.x >= w+2)then
  36.         self.x = -w
  37.         change = math.max(math.random(1,2))
  38.         if(change == 1)then
  39.             self.file = "sky2"
  40.         else
  41.             self.file = "clouds"
  42.         end
  43.     end
  44.  
  45.     self.x = self.x + 1
  46. end})
  47. bgs:add({name="t5",file="clouds",bc="blue",x=w,y=1,update=function(self)
  48.     bgs:draw("t5",self.x,self.y)
  49.     if(self.x >= w+2)then
  50.         self.x = -w
  51.         change = math.max(math.random(1,2))
  52.         if(change == 1)then
  53.             self.file = "sky2"
  54.         else
  55.             self.file = "clouds"
  56.         end
  57.     end
  58.  
  59.     self.x = self.x + 4
  60. end})
  61. map = LWLGL.createGame()
  62. map = LWLGL.createPlayer(map,5,5)
  63. bgs:update()
  64. LWLGL.sbc(colors.black)
  65. term.clear()
  66. while true do
  67.     term.current().setVisible(false)
  68.     LWLGL.sbc(colors.lightBlue)
  69.     local evs = LWLGL.catchEvents()
  70.     if(evs[1] == "timer")then
  71.         term.clear()
  72.         bgs:update()
  73.         map.player:draw()
  74.         timer = os.startTimer(0.1)
  75.     end
  76.     term.current().setVisible(true)
  77.     map:update(evs)
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement