Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------------------
- --
- -- main.lua
- --
- -----------------------------------------------------------------------------------------
- local physics = require("physics")
- physics.start()
- local paint = {
- type = "gradient",
- color1 = { 0, 0, 1 },
- color2 = { 0.5, 0.5, 0.7 },
- direction = "down"
- }
- local bg = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )
- bg.fill = paint
- --local myRectangle = display.newRect( display.contentHeight, 0, , display.contentCenterX )
- local float = display.newRect( display.contentCenterX, display.contentHeight-10, display.contentWidth , 20 )
- float:setFillColor( 0.5 ) -- место по Х место по игрику размер по Х размер У
- physics.addBody( float, "static", {bounce=0,friction=0.5})
- local gear = display.newRect( 20, display.contentCenterY, 20, display.contentHeight-60 )
- gear:setFillColor( 0.5 )
- local gearS = display.newRect( 20, display.contentCenterY, 20 , 20 )
- gearS:setFillColor( 1 )
- local car = display.newCircle( display.contentCenterX, display.contentCenterY, 20 )
- gearS:setFillColor( 1 )
- physics.addBody( car, "dynamic", {bounce = 0.2, friction= 0.5,radius=20} )
- local jumpL=display.newCircle( display.contentWidth-60, display.contentHeight-40, 15 )
- jumpL:setFillColor( 1 )
- local jumpR=display.newCircle( display.contentWidth-20, display.contentHeight-40, 15 )
- jumpR:setFillColor( 1 )
- local function moveBox (event)
- local bounds = gear.contentBounds
- local maxLim = bounds.yMax
- local minLim = bounds.yMin
- local gearS = event.target
- local phase = event.phase
- if ("began"==phase)then
- display.currentStage:setFocus(gearS)
- gearS.touchOffsetY=event.y - gearS.y
- elseif ("moved"==phase) then
- gearS.y=event.y-gearS.touchOffsetY
- if (gearS.y<minLim+10) then
- gearS.y=minLim+10
- elseif (gearS.y>maxLim-10) then
- gearS.y=maxLim-10
- end
- elseif ( "ended" == phase or "cancelled" == phase ) then
- display.currentStage:setFocus( nil )
- end
- return true
- end
- gearS:addEventListener( "touch", moveBox )---
- -- Your code here
- --local function JR()
- --car:applyLinearImpulse(0.05,-0.05,car.x,car.y)
- --end
- --jumpR:addEventListener("tap",JR)
- --local function JL ()
- -- car:applyLinearImpulse(-0.05,-0.05,car.x,car.y)
- --end
- --jumpL:addEventListener("tap",JL)
- local function ML (event)
- local phase = event.phase
- if ("began"==phase)then
- display.currentStage:setFocus(jumpL)
- car:applyLinearImpulse(-0.05,-0.00,car.x,car.y)
- --elseif ("moved"==phase) then
- --end
- elseif ( "ended" == phase or "cancelled" == phase ) then
- car:applyLinearImpulse(0.05,-0.00,car.x,car.y)
- display.currentStage:setFocus( nil )
- end
- return true
- end
- jumpL:addEventListener("touch",ML)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement