I’m stuck in my game I would appreciate some help.
My game is simple I have 2 main objects a bottle/ball and a bucket/basket. The bottle will spawn in top of the screen randomly and the bucket will move from left to right in kinematic mode in the bottom screen and the player has to drop the bottle/ball inside the bucket/basket. If he does so the level and the speed of the bucket will be increased . I have finished to manage the movement of the bucket, the random spawn of the bottle and the “hole” of the bucket my problem is what is the best way to remove the bottle and re-spawn it on top to increase the level which increases the speed of the bucket so the game wont stop. So basically like the game angry birds, the bird on the trebuchet to be respawn after gets throwed or like a 2d basketball game.
Below is my amateur game code.
–
– main.lua
–
– Physics
local physics = require( “physics” )
physics.start()
physics.setDrawMode(“hybrid”)
physics.setGravity(0,0)
–Objects
local background = display.newImageRect(“background.png”,360,570)
background.x = display.contentCenterX
background.y = display.contentCenterY
local ground = display.newImageRect(“platform.png”,1000,50)
ground.x = display.contentCenterX
ground.y = display.contentHeight-0
physics.addBody(ground,“static”,{ bounce=0, friction=0 })
local staticBox = display.newRect( 100, 100, display.contentWidth-240, 10 )
staticBox:setFillColor( 0.2, 0.2, 1 )
staticBox.x, staticBox.y = display.contentWidth-255, 450
staticBox.class = “inside”
physics.addBody( staticBox, “kinematic”, { bounce=0, friction=0 } )
–staticBox.isVisible = false
local bumperA = display.newRect( 0, 0, 10, 90 )
bumperA:setFillColor( 0.2, 0.2, 1 )
bumperA.x, bumperA.y = 20, 410
physics.addBody( bumperA, “kinematic”, { bounce=0.1, friction=1 } )
–bumperA.isVisible = false
local bumperB = display.newRect( 0, 0, 10, 90 )
bumperB:setFillColor( 0.2, 0.2, 1 )
bumperB.x, bumperB.y = 110, 410
physics.addBody( bumperB, “kinematic”, { bounce=0.1, friction=1 } )
–bumperB.isVisible = false
local bucket = display.newImageRect(“crate.png”,100,90)
bucket.x = 65
bucket.y = display.contentHeight-70
–physics.addBody(bucket, “kinematic”,{bounce=0, friction=0})
balloon = display.newImageRect( “balloon.png”, 50, 50 )
balloon.x = math.random(100,270)
balloon.y = display.contentCenter20
physics.addBody( balloon, “static”, { radius=25, bounce=0.1 } )
balloon.alpha = 0.8
balloon.class = “ball”
– function to handle the collision on the ball
function balloon:collision(e)
– only perform logic when the ball is colliding with a wall
if (e.other.class == “inside”) then
balloon.bodyType = “static”
transition.to(balloon,{time=0,x = math.random(50,270),y=0})
– cannot remove objects during a collision, so wait a short moment for it to end
end
end
balloon:addEventListener(“collision”,balloon)
function moveBucketRight()
transition.to (bucket,{time=5000, x=260})
transition.to (bumperB,{time=5000, x=305})
transition.to (bumperA,{time=5000, x=215})
transition.to (staticBox,{time=5000, x=260, onComplete=moveBucketLeft})
end
function moveBucketLeft()
–transition.to( platform, {} )
transition.to(bucket,{time=5000, x=60})
transition.to (bumperB,{time=5000, x=105})
transition.to (bumperA,{time=5000, x=15})
transition.to(staticBox,{time=5000, x=60, onComplete=moveBucketRight})
end
moveBucketRight()
–Functions
local tapCount = 0
local tapText = display.newText( tapCount, display.contentCenterX, 20, native.systemFont, 40 )
tapText:setFillColor( 0, 0, 0 )
local function pushBalloon()
balloon:applyLinearImpulse(0,0.10,balloon.x, balloon.y)
physics.setGravity(0,9.8)
balloon.bodyType = “dynamic”
tapCount = tapCount + 1
tapText.text = tapCount
end
Runtime:addEventListener( “tap”, pushBalloon )