Newbie needing help

Hey guys, im new to this kinda of thing and was after help to get going I’ve created a game just a simple one to get me started and was wanting to know a few things I have a basket I wish to move left and right automatically while I have a cannon which you have to rotate and shoot I am wanting to know how to rotate the cannon left and right, right and left and also touching the cannon to make it shoot and also placing something like fruit or an object of any sought in the cannon to shoot and for the basket to catch it when you aim right I am also wanting to know how to make a score that will go  up everytime you hit the basket and a level in making the basket faster with the higher score you get and last but not least placing other objects in to make it harder to hit the basket here is what I have so far



– main.lua


local physics = require( “physics” )

physics.start ()

local sky = display.newImage( “sky.png” )
sky.x = 160
sky.y = 195

local ground = display.newImage( “grass1.png” )
ground.x = 160
ground.y = 525
–physics.addbody(ground.{friction = 0.5})
–ground.Bodytype = “static”
ground.Myname = “ground”
local Basket = display.newImage( “Basket22.jpg” )
Basket.x = 157
Basket.y = 30
local Movespeed = 2

local Cannon = display.newImage( “Cannon113.png” )
Cannon.x = 160
Cannon.y = 465

display.setStatusBar( display.HiddenStatusBar )

Is this right so far???

Please help

Mark
 

ummm im also a noob myself but i have come up with something simple to help you: i havent used any images, just rectangles but i hope it helps. The structure of my code is poor so if anyone is willing to edit it that would be appreciated greatly! her it is

[lua]

display.setStatusBar( display.HiddenStatusBar )

local physics = require( “physics” )

–physics.setDrawMode( “debug” )

physics.start ()

screenW = display.contentWidth
screenH = display.contentHeight
screenmidX = display.contentCenterX
screenmidY = display.contentCenterY

local rad = math.rad
local cos = math.cos
local sin = math.sin
local score = 0

    local scoretext = display.newText(“0”, screenmidX + 200, screenmidY - 200, native.systemFont, 75 )

    local background = display.newRect( screenmidX, screenmidY, screenW, screenH )
    background.alpha = 0.5

    local invisOBJ = display.newRect( 0, 0, 10, 10)
    invisOBJ.x = screenmidX
    invisOBJ.y = screenmidY - screenmidY/2
    --invisOBJ.alpha = 0

    –

    local invisObj2 = display.newRect( screenmidX, screenmidY - screenmidY/2 +50, 10, 10 )

    local Basket = display.newRect(0,0, 50,50) --display.newImage( “Basket22.jpg” )
    Basket.x = screenmidX + 200
    Basket.y = screenmidY + screenmidY/2

    --local Movespeed = 2

    local Cannon = display.newRect(0,0, 10,50) --display.newImage( “Cannon113.png” )
    Cannon.x = screenmidX
    Cannon.y = screenmidY - screenmidY/2
    Cannon.anchorX = .5
    Cannon.anchorY = 0
    
    physics.addBody( Basket, “static”)
    physics.addBody( invisObj2, “dynamic”, {d = 1})
    physics.addBody( Cannon , “dynamic”, {d= 0.5})
    physics.addBody( invisOBJ , “static” )

local swingCannonJoint = physics.newJoint( “pivot”, invisOBJ, Cannon, invisOBJ.x, invisOBJ.y)
local swingCannonInvisJoint = physics.newJoint( “weld”, Cannon, invisObj2, invisObj2.x, invisObj2.y )

swingCannonJoint.isLimitEnabled = true
swingCannonJoint:setRotationLimits( -45, 45 )
invisObj2:applyLinearImpulse(0.005, 0)

local function moveBasketLeft ()
    transition.to( Basket, {time = 2000 , x = Basket.x + 400, onComplete = moveBasketRight} )
end

function moveBasketRight ()
    transition.to( Basket, {time = 2000 , x = Basket.x - 400, onComplete = moveBasketLeft } )
end

local function moveBasket ()
    moveBasketRight ()
end

local function SpawnBullet (event)
        if event.phase == “began” then
                local bullet = display.newCircle( 0, 0, 10 )
                bullet.x = Cannon.x
                bullet.y = Cannon.y + 30
                bullet.isBullet = true
                bullet.rotation = Cannon.rotation
                local radians = rad(bullet.rotation-270)
                local speed = 10
                local dx = cos( radians ) * speed
                local dy = sin( radians ) * speed
                transition.to( bullet, {time = 1000, x = bullet.x + dx*100, y = bullet.y + dy*100} )
        end
end

local function addToScore (event)
    if event.phase == “began” then    
        print( “lol” )
        score = score + 50
        scoretext.text = string.format( “%d” ,score )
    end
end

moveBasket ()

Basket:addEventListener( “collision”, addToScore)
background:addEventListener( “touch”, SpawnBullet)

[/lua]

Edit: after testing it i’ve realised the scoring is off and the firing is quite laggy, you could definitely improve on it.

ummm im also a noob myself but i have come up with something simple to help you: i havent used any images, just rectangles but i hope it helps. The structure of my code is poor so if anyone is willing to edit it that would be appreciated greatly! her it is

[lua]

display.setStatusBar( display.HiddenStatusBar )

local physics = require( “physics” )

–physics.setDrawMode( “debug” )

physics.start ()

screenW = display.contentWidth
screenH = display.contentHeight
screenmidX = display.contentCenterX
screenmidY = display.contentCenterY

local rad = math.rad
local cos = math.cos
local sin = math.sin
local score = 0

    local scoretext = display.newText(“0”, screenmidX + 200, screenmidY - 200, native.systemFont, 75 )

    local background = display.newRect( screenmidX, screenmidY, screenW, screenH )
    background.alpha = 0.5

    local invisOBJ = display.newRect( 0, 0, 10, 10)
    invisOBJ.x = screenmidX
    invisOBJ.y = screenmidY - screenmidY/2
    --invisOBJ.alpha = 0

    –

    local invisObj2 = display.newRect( screenmidX, screenmidY - screenmidY/2 +50, 10, 10 )

    local Basket = display.newRect(0,0, 50,50) --display.newImage( “Basket22.jpg” )
    Basket.x = screenmidX + 200
    Basket.y = screenmidY + screenmidY/2

    --local Movespeed = 2

    local Cannon = display.newRect(0,0, 10,50) --display.newImage( “Cannon113.png” )
    Cannon.x = screenmidX
    Cannon.y = screenmidY - screenmidY/2
    Cannon.anchorX = .5
    Cannon.anchorY = 0
    
    physics.addBody( Basket, “static”)
    physics.addBody( invisObj2, “dynamic”, {d = 1})
    physics.addBody( Cannon , “dynamic”, {d= 0.5})
    physics.addBody( invisOBJ , “static” )

local swingCannonJoint = physics.newJoint( “pivot”, invisOBJ, Cannon, invisOBJ.x, invisOBJ.y)
local swingCannonInvisJoint = physics.newJoint( “weld”, Cannon, invisObj2, invisObj2.x, invisObj2.y )

swingCannonJoint.isLimitEnabled = true
swingCannonJoint:setRotationLimits( -45, 45 )
invisObj2:applyLinearImpulse(0.005, 0)

local function moveBasketLeft ()
    transition.to( Basket, {time = 2000 , x = Basket.x + 400, onComplete = moveBasketRight} )
end

function moveBasketRight ()
    transition.to( Basket, {time = 2000 , x = Basket.x - 400, onComplete = moveBasketLeft } )
end

local function moveBasket ()
    moveBasketRight ()
end

local function SpawnBullet (event)
        if event.phase == “began” then
                local bullet = display.newCircle( 0, 0, 10 )
                bullet.x = Cannon.x
                bullet.y = Cannon.y + 30
                bullet.isBullet = true
                bullet.rotation = Cannon.rotation
                local radians = rad(bullet.rotation-270)
                local speed = 10
                local dx = cos( radians ) * speed
                local dy = sin( radians ) * speed
                transition.to( bullet, {time = 1000, x = bullet.x + dx*100, y = bullet.y + dy*100} )
        end
end

local function addToScore (event)
    if event.phase == “began” then    
        print( “lol” )
        score = score + 50
        scoretext.text = string.format( “%d” ,score )
    end
end

moveBasket ()

Basket:addEventListener( “collision”, addToScore)
background:addEventListener( “touch”, SpawnBullet)

[/lua]

Edit: after testing it i’ve realised the scoring is off and the firing is quite laggy, you could definitely improve on it.