Cannon game simple class

Hi Im new with codea, had a little c++ experience
So i try to make a little cannon game.
My first question are there any samples online with simmilar games? Ore open surce games in codea? Wuld help me much…
And second how to make a simle class with no “name” (look at my crappy code ^^) i have used this
http://twolivesleft.com/Codea/Talk/discussion/267/a-probably-nooby-question-about-rotating-a-sprite/p1
So i dont know how to remove mySprite = srite…
And last my angle calculation, i tried to use anglebetween but cant get it work… So i used trigonometry… Any better ideas? Thx

Main

-- Cannon

-- Use this function to perform your initial setup
function setup()
    --displayMode(FULLSCREEN)
    print("Hello World!")
    vgun = vec2(100, 100)     --position gun
    rgun = 200                --radius gun
    
    myGun = Gun( name )      -- this is second question ^^
    myGun.position = vgun
    myGun.angle = 0
end

-- This function gets called once every frame
function draw()
    background(0, 162, 255, 255)
    smooth() 
    
    myGun:draw() 
end

function touched(touch)
    vtouch = vec2(touch.x , touch.y)
    ge = vtouch.y-vgun.y    --gegenkatete dy
    an = vtouch.x-vgun.x    --ankatete dx
    
    if an<0 then            --calculate angle, anglebetween cant get work?
        alpha = 180-math.deg(math.atan(-ge/an))
    else
        alpha = math.deg(math.atan(ge/an))
    end
    --print(alpha)
    --print("dx"..an)
    --print("dy"..ge)
    
    myGun.angle = alpha        --set touched angle to gun
    
end

Gun class

Gun = class()

function Gun:init( name )
    self.name = name
    self.position = vec2(0,0)
    self.angle = 0
end

function Gun:draw()
    pushMatrix()
    
    translate( self.position.x, self.position.y )
    rotate( self.angle )
    
    strokeWidth(30)
    lineCapMode(SQUARE)
    line(0,0,rgun,0)
    
    popMatrix()
    
    stroke(65, 65, 65, 255)
    strokeWidth(10)
    fill(127, 127, 127, 255)
    rect(vgun.x-rgun/2 , vgun.y-rgun/2 , rgun , rgun/2)
    ellipse(vgun.x,vgun.y,rgun)
    
end

You can look at my example that I recently posted here on the forum. Currently just below this post. :slight_smile:

There are some tutorials over at: http://codeatuts.blogspot.com.au/

and heaps of examples and sample code in this forum and wiki.