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:
-
Makes the ball shoot
-
Makes it bounce off the left and right wall
-
If it collides with the black hole, make it “disappear” into the hole
-
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