Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------
  2. --
  3. -- main.lua
  4. --
  5. -----------------------------------------------------------------------------------------
  6. local physics = require("physics")
  7. physics.start()
  8.  
  9. local paint = {
  10.     type = "gradient",
  11.     color1 = { 0, 0, 1 },
  12.     color2 = { 0.5, 0.5, 0.7 },
  13.     direction = "down"
  14. }
  15.  
  16. local bg = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )
  17. bg.fill = paint
  18.  
  19.  
  20.  
  21. --local myRectangle = display.newRect( display.contentHeight, 0, , display.contentCenterX )
  22. local float = display.newRect( display.contentCenterX, display.contentHeight-10, display.contentWidth , 20 )
  23. float:setFillColor( 0.5 ) -- место по Х                место по игрику            размер по Х           размер У
  24. physics.addBody( float, "static", {bounce=0,friction=0.5})
  25.  
  26. local gear = display.newRect( 20, display.contentCenterY, 20, display.contentHeight-60 )
  27. gear:setFillColor( 0.5 )
  28.  
  29. local gearS = display.newRect( 20, display.contentCenterY, 20 , 20 )
  30. gearS:setFillColor( 1 )
  31.  
  32. local car = display.newCircle( display.contentCenterX, display.contentCenterY, 20 )
  33. gearS:setFillColor( 1 )
  34. physics.addBody( car, "dynamic", {bounce = 0.2, friction= 0.5,radius=20} )
  35.  
  36.  
  37. local jumpL=display.newCircle( display.contentWidth-60, display.contentHeight-40, 15 )
  38. jumpL:setFillColor( 1 )
  39.  
  40. local jumpR=display.newCircle( display.contentWidth-20, display.contentHeight-40, 15 )
  41. jumpR:setFillColor( 1 )
  42.  
  43. local function moveBox (event)
  44. local bounds = gear.contentBounds
  45. local maxLim = bounds.yMax
  46. local minLim = bounds.yMin
  47. local gearS = event.target
  48. local phase = event.phase
  49.  
  50. if ("began"==phase)then
  51.   display.currentStage:setFocus(gearS)
  52.   gearS.touchOffsetY=event.y - gearS.y
  53.  
  54. elseif ("moved"==phase) then
  55.   gearS.y=event.y-gearS.touchOffsetY
  56.   if (gearS.y<minLim+10) then
  57.     gearS.y=minLim+10
  58.   elseif (gearS.y>maxLim-10) then
  59.     gearS.y=maxLim-10
  60.  
  61.   end
  62. elseif ( "ended" == phase or "cancelled" == phase ) then
  63.       display.currentStage:setFocus( nil )
  64.   end
  65.   return true
  66. end
  67.  
  68. gearS:addEventListener( "touch", moveBox )---
  69. -- Your code here
  70.  
  71. --local function JR()
  72. --car:applyLinearImpulse(0.05,-0.05,car.x,car.y)
  73. --end
  74. --jumpR:addEventListener("tap",JR)
  75. --local function JL ()
  76. --  car:applyLinearImpulse(-0.05,-0.05,car.x,car.y)
  77. --end
  78. --jumpL:addEventListener("tap",JL)
  79.  
  80.  
  81.  
  82.  
  83. local function ML (event)
  84. local phase = event.phase
  85.  
  86. if ("began"==phase)then
  87.   display.currentStage:setFocus(jumpL)
  88.   car:applyLinearImpulse(-0.05,-0.00,car.x,car.y)
  89.  
  90. --elseif ("moved"==phase) then
  91.  
  92.  
  93.   --end
  94. elseif ( "ended" == phase or "cancelled" == phase ) then
  95.   car:applyLinearImpulse(0.05,-0.00,car.x,car.y)
  96.       display.currentStage:setFocus( nil )
  97.   end
  98.   return true
  99. end
  100.  
  101. jumpL:addEventListener("touch",ML)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement