Stuck for hours... need help please

Hi everyone,

I’m new to programming and new to Corona (although I am loving the simplicity of it!)

I have a few problems I hope someone can help me with.

I am trying to create a simple game. The small ball orbits the large circle. When you think the small ball has lined up with the black hole at the top of the screen, you tap anywhere on the screen to “release” and shoot the ball from its rotating axix, and try to get it into the hole.

Is it possible for someone to insert some code into my snippet below so the game does the following:

  1. Makes the ball shoot

  2. Makes it bounce off the left and right wall

  3. If it collides with the black hole, make it “disappear” into the hole

  4. Once you successfully sink a ball, you get taken to Level 2 (and the red 1 changes to 2).

Thanks!

David1



– -- main.lua



– Add physics engine and apply anti-gravity

local physics = require(“physics”)

physics.start()

physics.setGravity(0,0)

– Add a score label

local scoreLabel = display.newText( 1, 40, 860, native.systemFontBold, 120 )

scoreLabel:setTextColor( 255, 0, 0 )

– hide status bar

display.setStatusBar(display.HiddenStatusBar)

– set default screen background color to blue

display.setDefault( “background”, 255, 255, 255 )

– Make invisible walls

local leftWall = display.newRect (0, 0, 1, display.contentHeight);

local rightWall = display.newRect (display.contentWidth, 0, 1, display.contentHeight);

local ceiling = display.newRect (0, 0, display.contentWidth, 1);

– Add physics to the walls. They will not move so they will be “static”

physics.addBody (leftWall, “static”,  { bounce = 0.1 } );

physics.addBody (rightWall, “static”, { bounce = 0.1 } );

physics.addBody (ceiling, “static”,   { bounce = 0.1 } );

– MAKE A BALL AND MAKE IT INTERACTIVE

local t = 1

local r = 180

local ball = display.newCircle( 100, 100, 20 )

ball:setFillColor( 0.5 )

– turn ball into physics body

physics.addBody(ball, “dynamic”, {density = 1, friction = 0, bounce = 1, isSensor = false, radius = 15})

local group = display.newGroup()

group:insert( ball )

group.x = display.contentCenterX

group.y = display.contentCenterY/0.675

local function onUpdate( event )

    local t = event.time * .007

    ball.x = r * math.cos(t)

    ball.y = r * math.sin(t)

end

Runtime:addEventListener( “enterFrame”, onUpdate )

– add looper to screen

local looper = display.newCircle(100,100,150)

looper:setFillColor( 0.8 )

looper.x = display.contentWidth/2

looper.y = display.contentHeight/1.35

– add hole to screen

local hole = display.newCircle(100,100,30)

hole:setFillColor( 0 )

hole.x = display.contentWidth/2

hole.y = display.contentHeight/7

I had a quick play but did not meet your goal In the time I had, I added some code to make it show the debug walls and work better in iPhone 6 plus (see hole ball.zip)

Check out http://www.x-pressive.com/ParticleCandy_Corona/features.html as it had a CreateFX Field (http://www.x-pressive.com/ParticleCandy_Corona/reference.html#F1) that acts as a central physics pushing force.

--Add physics engine and apply anti-gravity local physics = require("physics") physics.start() physics.setGravity(0,6) --physics.setDrawMode( "normal" ) --the default Corona renderer, with no collision outlines physics.setDrawMode( "hybrid" ) --overlays collision outlines on normal display objects -- Add a score label local scoreLabel = display.newText( 1, 40, 860, native.systemFontBold, 120 ) scoreLabel:setTextColor( 255, 0, 0 ) -- hide status bar display.setStatusBar(display.HiddenStatusBar) -- set default screen background color to blue display.setDefault( "background", 255, 255, 255 ) -- Make invisible walls local leftWall = display.newRect (1, 2, 10, display.contentHeight \* 3); local rightWall = display.newRect (display.contentWidth, 2, 10, display.contentHeight \* 2); local ceiling = display.newRect (2, 2, display.contentWidth \* 2, 10); local floor = display.newRect (2, display.contentHeight , display.contentWidth \* 2, 10); -- Add physics to the walls. They will not move so they will be "static" physics.addBody (leftWall, "static", { density=1.0, bounce = 0.1 } ); physics.addBody (rightWall, "static", { density=1.0, bounce = 0.1 } ); physics.addBody (ceiling, "static", { density=1.0, bounce = 0.1 } ); physics.addBody (floor, "static", { density=1.0, bounce = 0.1 } ); -- MAKE A BALL AND MAKE IT INTERACTIVE local t = 1 local r = 180 local ball = display.newCircle( 100, 100, 20 ) ball:setFillColor( 0, 1, 0, 1) -- turn ball into physics body physics.addBody(ball, "dynamic", {density = 1, friction = 0, bounce = 1, radius = 15}) local group = display.newGroup() group:insert( ball ) group.x = display.contentCenterX group.y = display.contentCenterY/0.675 local function onUpdate( event ) if (boolUserReleasedTheBall == false) then local t = event.time \* .005 ball.x = r \* math.cos(t) / 2 ball.y = r \* math.sin(t) / 2 else if (boolStopForce == false) then ball:applyForce( 200, 200, ball.x, ball.y ) boolStopForce = true boolWaitingForReset = true end end end Runtime:addEventListener( "enterFrame", onUpdate ) -- add looper to screen local looper = display.newCircle(100,100,50) looper:setFillColor( 0.8 ) looper.x = display.contentWidth/2 looper.y = display.contentHeight/1.35 -- add hole to screen local hole = display.newCircle(100,100,30) hole:setFillColor( 0 ) hole.x = display.contentWidth/2 hole.y = display.contentHeight/7 boolUserReleasedTheBall = false boolStopForce = false boolWaitingForReset = false local myTouchListener = function( event ) print( "Listener called with event of type: "..event.name ) -- reset if (boolStopForce == true) then boolUserReleasedTheBall = false boolStopForce = false boolWaitingForReset = false end boolUserReleasedTheBall = true --boolWaitingForReset = true end Runtime:addEventListener( "touch", myTouchListener )

I had a quick play but did not meet your goal In the time I had, I added some code to make it show the debug walls and work better in iPhone 6 plus (see hole ball.zip)

Check out http://www.x-pressive.com/ParticleCandy_Corona/features.html as it had a CreateFX Field (http://www.x-pressive.com/ParticleCandy_Corona/reference.html#F1) that acts as a central physics pushing force.

--Add physics engine and apply anti-gravity local physics = require("physics") physics.start() physics.setGravity(0,6) --physics.setDrawMode( "normal" ) --the default Corona renderer, with no collision outlines physics.setDrawMode( "hybrid" ) --overlays collision outlines on normal display objects -- Add a score label local scoreLabel = display.newText( 1, 40, 860, native.systemFontBold, 120 ) scoreLabel:setTextColor( 255, 0, 0 ) -- hide status bar display.setStatusBar(display.HiddenStatusBar) -- set default screen background color to blue display.setDefault( "background", 255, 255, 255 ) -- Make invisible walls local leftWall = display.newRect (1, 2, 10, display.contentHeight \* 3); local rightWall = display.newRect (display.contentWidth, 2, 10, display.contentHeight \* 2); local ceiling = display.newRect (2, 2, display.contentWidth \* 2, 10); local floor = display.newRect (2, display.contentHeight , display.contentWidth \* 2, 10); -- Add physics to the walls. They will not move so they will be "static" physics.addBody (leftWall, "static", { density=1.0, bounce = 0.1 } ); physics.addBody (rightWall, "static", { density=1.0, bounce = 0.1 } ); physics.addBody (ceiling, "static", { density=1.0, bounce = 0.1 } ); physics.addBody (floor, "static", { density=1.0, bounce = 0.1 } ); -- MAKE A BALL AND MAKE IT INTERACTIVE local t = 1 local r = 180 local ball = display.newCircle( 100, 100, 20 ) ball:setFillColor( 0, 1, 0, 1) -- turn ball into physics body physics.addBody(ball, "dynamic", {density = 1, friction = 0, bounce = 1, radius = 15}) local group = display.newGroup() group:insert( ball ) group.x = display.contentCenterX group.y = display.contentCenterY/0.675 local function onUpdate( event ) if (boolUserReleasedTheBall == false) then local t = event.time \* .005 ball.x = r \* math.cos(t) / 2 ball.y = r \* math.sin(t) / 2 else if (boolStopForce == false) then ball:applyForce( 200, 200, ball.x, ball.y ) boolStopForce = true boolWaitingForReset = true end end end Runtime:addEventListener( "enterFrame", onUpdate ) -- add looper to screen local looper = display.newCircle(100,100,50) looper:setFillColor( 0.8 ) looper.x = display.contentWidth/2 looper.y = display.contentHeight/1.35 -- add hole to screen local hole = display.newCircle(100,100,30) hole:setFillColor( 0 ) hole.x = display.contentWidth/2 hole.y = display.contentHeight/7 boolUserReleasedTheBall = false boolStopForce = false boolWaitingForReset = false local myTouchListener = function( event ) print( "Listener called with event of type: "..event.name ) -- reset if (boolStopForce == true) then boolUserReleasedTheBall = false boolStopForce = false boolWaitingForReset = false end boolUserReleasedTheBall = true --boolWaitingForReset = true end Runtime:addEventListener( "touch", myTouchListener )