Hendrix000007

ConstructionMan

Jan 15th, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.80 KB | None | 0 0
  1. ------------
  2. MAIN
  3. -------------
  4. display.setStatusBar( display.HiddenStatusBar )
  5.  
  6. local WehicleClass = require("classes.Dumpster")
  7. local LevelClass = require("classes.Level1")
  8. local HudClass = require("classes.Hud")
  9.  
  10. local level = LevelClass:new()
  11. local wehicle = WehicleClass:new()
  12. local hud = HudClass:new()
  13.  
  14. --level:startListeners()
  15. --wehicle:startEngine()
  16. --wehicle:startDriving()
  17. hud:startListeners()
  18.  
  19. ------------------
  20. HUD
  21. -----------------
  22. local _M = {}
  23. _M.filePath= "assets/hud/"
  24. local _W, _H = display.contentWidth, display.contentHeight
  25. local _VW, _VH = display.viewableContentWidth, display.viewableContentHeight
  26. _M.prototype = {
  27.                 hudBg        = display.newRect( 0, 0, _W, 290 ),
  28.                 hudPanel     = display.newImage(_M.filePath .. "hudPanel.png"),
  29.  
  30.                 hudTrottle   = display.newImage(_M.filePath .. "trottleUp.png"),
  31.                 hudBrake     = display.newImage(_M.filePath .. "brakeUp.png"),
  32.  
  33.                 light        = display.newImage(_M.filePath .. "lightButton.png"),
  34.                 loaderUp     = display.newImage(_M.filePath .. "loaderUp.png"),
  35.                 loaderDown   = display.newImage(_M.filePath .. "loaderDown.png"),
  36.  
  37.                 gearUp       = display.newImage(_M.filePath .. "gearUp.png"),
  38.                 gearDown     = display.newImage(_M.filePath .. "gearDown.png"),
  39.                 gearFree     = display.newImage(_M.filePath .. "gear0.png"),
  40.                 gear1        = display.newImage(_M.filePath .. "gear1.png"),
  41.                 gear2        = display.newImage(_M.filePath .. "gear2.png"),
  42.                 gear3        = display.newImage(_M.filePath .. "gear3.png"),
  43.                 gear4        = display.newImage(_M.filePath .. "gear4.png"),
  44.                 gearR        = display.newImage(_M.filePath .. "gearReverse.png"),
  45.  
  46.                 hudPanelOff  = display.newImage(_M.filePath .. "hudPanelOff.png"),
  47.                 hudPower     = display.newImage(_M.filePath .. "powerButton.png"),
  48.                 }
  49.  
  50. _M.mt = { __index = _M.prototype }
  51. setmetatable( _M, _M.mt )
  52.  
  53. function _M:new()
  54.     local o = {}
  55.         o.group = display.newGroup()
  56.  
  57.         self.hudBg.x, self.hudBg.y = _W * 0.5, _H - self.hudBg.height * 0.5
  58.         self.hudBg:setFillColor( 51/255,51/255,51/255 )
  59.  
  60.         self.hudPanel.x, self.hudPanel.y = display.contentCenterX, self.hudBg.y
  61.         self.hudPanelOff.x, self.hudPanelOff.y = self.hudPanel.x, self.hudPanel.y
  62.         self.hudPanelOff.isVisible = true
  63.  
  64.         self.hudTrottle.anchorX, self.hudTrottle.anchorY = 1,1
  65.         self.hudTrottle.x, self.hudTrottle.y = _W, self.hudBg.y
  66.  
  67.         self.hudBrake.anchorX, self.hudBrake.anchorY = 1,0
  68.         self.hudBrake.x, self.hudBrake.y = _W, self.hudBg.y
  69.  
  70.         self.hudPower.anchorX, self.hudPower.anchorY = 0,0
  71.         self.hudPower.x, self.hudPower.y = 25,(self.hudPanel.y-self.hudPanel.height/2+25)
  72.  
  73.         self.light.anchorX, self.light.anchorY = 0,0
  74.         self.light.x, self.light.y = (self.hudPower.x+self.hudPower.width+5),self.hudPower.y
  75.  
  76.         self.loaderUp.anchorX, self.loaderUp.anchorY = 0,0
  77.         self.loaderUp.x, self.loaderUp.y = (self.light.x+self.light.width+35),self.hudPower.y
  78.  
  79.         self.loaderDown.anchorX, self.loaderDown.anchorY = 0,0
  80.         self.loaderDown.x, self.loaderDown.y = (self.light.x+self.light.width+35),(self.hudPower.y + self.hudPower.height+25)
  81.  
  82.         self.gearFree.anchorX, self.gearFree.anchorY = 0,0
  83.         self.gearFree.x, self.gearFree.y = self.hudPower.x-30,(self.hudPower.y + self.hudPower.height+55)
  84.         self.gearFree.alpha = 1
  85.  
  86.         self.gear1.anchorX, self.gear1.anchorY = 0,0
  87.         self.gear1.x, self.gear1.y = self.hudPower.x-30,(self.hudPower.y + self.hudPower.height+55)
  88.         self.gear1.alpha = 0
  89.  
  90.         self.gear2.anchorX, self.gear2.anchorY = 0,0
  91.         self.gear2.x, self.gear2.y = self.gear1.x, self.gear1.y
  92.         self.gear2.alpha = 0
  93.  
  94.         self.gear3.anchorX, self.gear3.anchorY = 0,0
  95.         self.gear3.x, self.gear3.y = self.gear1.x, self.gear1.y
  96.         self.gear3.alpha = 0
  97.  
  98.         self.gear4.anchorX, self.gear4.anchorY = 0,0
  99.         self.gear4.x, self.gear4.y = self.gear1.x, self.gear1.y
  100.         self.gear4.alpha = 0
  101.  
  102.         self.gear4.anchorX, self.gear4.anchorY = 0,0
  103.         self.gear4.x, self.gear4.y = self.gear1.x, self.gear1.y
  104.         self.gear4.alpha = 0
  105.  
  106.         self.gearUp.anchorX, self.gearUp.anchorY = 0,0
  107.         self.gearUp.x, self.gearUp.y = (self.hudPower.x+self.hudPower.width+5),self.gear1.y
  108.  
  109.         self.gearDown.anchorX, self.gearDown.anchorY = 0,0
  110.         self.gearDown.x, self.gearDown.y = (self.hudPower.x+self.hudPower.width+5),self.gearUp.y + self.gearUp.height+5
  111.  
  112.  
  113.         o.group:insert(self.hudBg)
  114.         o.group:insert(self.hudPanel)
  115.         o.group:insert(self.hudTrottle)
  116.         o.group:insert(self.hudBrake)
  117.         o.group:insert(self.light)
  118.         o.group:insert(self.loaderUp)
  119.         o.group:insert(self.loaderDown)
  120.         o.group:insert(self.gearUp)
  121.         o.group:insert(self.gearDown)
  122.         o.group:insert(self.gearFree)
  123.         o.group:insert(self.gear1)
  124.         o.group:insert(self.gear2)
  125.         o.group:insert(self.gear3)
  126.         o.group:insert(self.gear4)
  127.         o.group:insert(self.gearR)
  128.         o.group:insert(self.hudPanelOff)
  129.         o.group:insert(self.hudPower)
  130.  
  131.         o.tableForListeners ={
  132.                                [1]={"o.hudTrottle","o.onTrottle"},
  133.  
  134.                              --  self.hudBrake, self.light, self.loaderUp, =self.loaderDown,
  135.                              --  self.gearUp,   self.gearDown
  136.                               }
  137.  
  138.  
  139.  
  140.         function o.startListeners()
  141.             self.hudPanelOff.isVisible = false
  142.             for k,v in ipairs (o.tableForListeners) do
  143.                 print(v[2])
  144.             --  v[1]:addEventListener( "touch", v[2] )
  145.             end
  146.         end
  147.  
  148.         function o.onTrottle()
  149.             print("Trottle function")
  150.         end
  151.  
  152.  
  153.         self.hudPower:addEventListener( "touch", o.startListeners ) --[[ ADDING TOUCH EVENT FOR POWER IN DISPLAY
  154.                                                                         AND ADDING LISTENERS FOR ALL OTHER BUTTONS --]]
  155.  
  156.         setmetatable( o, _M.mt)
  157.     return o
  158. end
  159.  
  160.  
  161.  
  162.  
  163. return _M
  164.  
  165.  
  166. ---------------
  167. DUMPSTER
  168. --------------
  169. local _M = {}
  170. _M.filePath= "assets/"
  171.  
  172. _M.prototype = {
  173.                 speed        = 50,
  174.                 colour       = "Green",
  175.                 body         = "truckBody.png",
  176.                 wheels       = "truckWheel.png",
  177.                 engineOn     = false,
  178.                 soundStarter = "starter.mp3",
  179.                 soundEngine  = "engine.mp3",
  180.                 }
  181.  
  182. _M.mt = { __index = _M.prototype }
  183. setmetatable( _M, _M.mt )
  184.  
  185. function _M:new()
  186.     local o = {}
  187.         o.group = display.newGroup()
  188.         o.truckBody   = display.newImage(_M.filePath .. self.body)
  189.         o.truckBody.x = display.contentWidth * 0.5
  190.         o.truckBody.y = display.contentHeight * 0.5
  191.         o.truckWheel1 = display.newImage(_M.filePath .. self.wheels)
  192.         o.truckWheel2 = display.newImage(_M.filePath .. self.wheels)
  193.         o.truckWheel3 = display.newImage(_M.filePath .. self.wheels)
  194.         o.truckWheel1.x = o.truckBody.x - 170
  195.         o.truckWheel1.y = o.truckBody.y + 75
  196.         o.truckWheel2.x = o.truckWheel1.x + o.truckWheel1.width + 5
  197.         o.truckWheel2.y = o.truckWheel1.y
  198.         o.truckWheel3.x = o.truckBody.x + 125
  199.         o.truckWheel3.y = o.truckWheel1.y
  200.         o.group:insert(o.truckBody)
  201.         o.group:insert(o.truckWheel1)
  202.         o.group:insert(o.truckWheel2)
  203.         o.group:insert(o.truckWheel3)
  204.  
  205.         setmetatable( o, _M.mt)
  206.  
  207.         function o.rotateEngine(event)
  208.             if reverse == 0 then
  209.                 reverse = 1
  210.                 transition.to( o.truckBody, { y = 5, delta=true, time=100 } )
  211.             else
  212.                 reverse = 0
  213.                 transition.to( o.truckBody, { y = -5, delta=true, time=100 } )
  214.             end
  215.         end
  216.  
  217.         function o.rotateWheels(event)
  218.                 transition.to( o.truckWheel1, { rotation=45, delta=true, time=100 } )
  219.                 transition.to( o.truckWheel2, { rotation=45, delta=true, time=100 } )
  220.                 transition.to( o.truckWheel3, { rotation=45, delta=true, time=100 } )
  221.         end
  222.  
  223.         function o:startDriving()
  224. --          if self.engineOn == true then
  225.                 o.wheelTimer = timer.performWithDelay(100, o.rotateWheels, 0 )
  226.                 print("The wheels are spinning ")
  227. --          end
  228.         end
  229.  
  230.         function o:stopDriving()
  231.             if self.engineOn == true then
  232.                 self.engineOn = false
  233.                 o.wheelTimer = timer.performWithDelay(100, o.rotateWheels, 1 )
  234.                 print("The wheels stopped ")
  235.             end
  236.         end    
  237.  
  238.         function o:startEngine()
  239.             self.engineOn = true
  240.             o.engineTimer = timer.performWithDelay(100, o.rotateEngine, 0 )
  241.             print("The engine ON is ", self.engineOn)
  242.         end
  243.  
  244.  
  245.     return o
  246. end
  247.  
  248.  
  249.  
  250.  
  251. return _M
Advertisement
Add Comment
Please, Sign In to add comment