Getting started

Is there a preferred reading list or video information out there that a person completely new to coding can use as a learning aid

@Funchion Click on the “Wiki” above, below the words “Codea Talk”. You’ll find a lot of information there. Another suggestion is to look thru the build in documentation. I’m not saying to read everything and memorize it. Just read thru all of the commands and their explanations. You can’t write code if you don’t know what commands you can use and what they do.

I’ve written some ebooks for beginners, plus a lot of posts. The ebook link is at the top of this page.

I recommend starting with Lua (the language behind Codea, then Codea.

https://coolcodea.wordpress.com/2013/06/19/index-of-posts/

There’s also the “getting started” button on the bottom right of the project browser…

Aside from that and the Codea documentation, you can read Lua’s documentation here, especially the reference manual. There’s a quick overview of how the Lua language works over here, and an official series of Lua tutorials here. I also recommend Ignatz’ tutorials, which he linked above my post.

If you are completely new to coding, it might be favorable to learn some key concepts before learning anything specific to lua

I had a tough time figuring out how to start. Reading through all the documentation was just information overload. What I did was just think of a very simple game, and started putting it together piece by piece, and if I got stuck I would ask the helpful people on the forum for help.

The first game I made was a simple sky background, with asteroids falling from the top of the screen, and you had to tap the asteroids to destroy them before they hit the ground, or the game ends.

Once you have made your first simple game, you then have learned a few things that you can apply to your next game that will be slightly more complex.

So yeah, I would say start with a very simple game, and try to make the complete game with title screen, try again screen, etc.

Everyone learns differently though, that is just what worked for me. I’m still a beginner though…

Here is code for a full very simple game, with comments describing everything. The object of the game is to make your ship dodge asteroids by touching either side of the screen to move the ship. You can copy and paste the code below into a new project to see it run:


displayMode(FULLSCREEN) -- Change game to fullscreen, removing the side bar
supportedOrientations(PORTRAIT_ANY) -- restrict game to portrait mode
function setup() -- used for initial setup of game
    -- table to hold asteroids, to keep track of them so they can be deleted when needed
    ast={} 
    -- load ship image into memory
    ship=readImage("Space Art:Red Ship")
    -- load asteroid image into memory
    asteroid=readImage("Space Art:Asteroid Large")
    -- frequency of asteroid spawn in seconds
    astFreq=1.5 
    -- amount of pixels that asteroids fall per frame (60 frames per second)
    astSpeed=-9
    -- starting score
    score=0
    -- timer used for asteroid spawning, resets after every spawn
    timer=0
    -- images (sprites) position based on center of image
    rectMode(CENTER)
    -- set high score to 0 if there is no saved high score
    if readLocalData("HS")== nil then
        saveLocalData("HS", 0)
    end
    -- start music playing
    music("A Hero's Quest:Battle",true,.5)
   -- begin game at the title screen which is gamestate 0
    gameState=0
    -- set the font that will be used for score, etc.
    font("Futura-CondensedExtraBold")
    -- set the size of the font used
    fontSize(64)
    -- set the font color (this would also effect shapes that are created)
    fill(0, 255, 0, 255)
    -- ship starting X location
    shipX=WIDTH/2
    -- ship starting Y position
    shipY=HEIGHT/4
end
-- function to insert asteroids into table when timer spawns them
-- when the asteroids are inserted into the table, their position is also added
-- the X position is random in this case because we want the asteroids to spawn randomly on X axis
function spawn()
    table.insert(ast,vec2(math.random(96,WIDTH-96),1152))
end
    -- the draw function is performed 60 times per second
function draw()
    -- this is the title screen
    if gameState==0 then
    -- black background
        background(0, 0, 0, 255)
    -- writing the word PLAY on screen for a play button
        text("PLAY",WIDTH/2,HEIGHT/2)
    -- checking if touch is on button, if so it changes to main game (gamestate 1)
        if CurrentTouch.state==BEGAN then
            if CurrentTouch.x>WIDTH/2-256 and CurrentTouch.x<WIDTH/2+256
            and CurrentTouch.y>HEIGHT/2-128 and CurrentTouch.y<HEIGHT/2+128 then
                gameState=1
            end
        end
    end
    -- main game screen
    if gameState==1 then
    -- black background
        background(0, 0, 0, 255)
    -- display the score which starts off as 0 from the setup function
        pushStyle()
        text("Score: "..score, WIDTH/2, HEIGHT/1.2)
        popStyle()
    -- displays a sprite for any asteroid stored in the asteroid table
    for a,b in pairs(ast) do
        sprite(asteroid,b.x,b.y,192,256)
    -- changes the asteroids Y location every frame by adding the asteroid speed from setup
        b.y=b.y+astSpeed
    end
    -- starts the timer counting up
    timer=timer+DeltaTime
    -- when timer is higher than asteroid frequency from setup it spawns 3 asteroids and resets timer to 0
    if timer>astFreq then
        spawn()
        spawn()
        spawn()
        timer=0 
        end
    -- if asteroid goes under bottom of screen, asteroid is removed and score is increased
    for a,b in pairs(ast) do
        if b.y<-128 then
            table.remove(ast,a)
            score=score+10
        end
    end
    -- if left side of screen is touched ship moves left
    if CurrentTouch.x <= WIDTH / 2 and CurrentTouch.state ~= ENDED and CurrentTouch.state ~= CANCELLED then
            shipX=shipX-12
        end
    -- if right side of screen is touched ship moves right
    if CurrentTouch.x>WIDTH/2 and CurrentTouch.state ~= ENDED and CurrentTouch.state ~= CANCELLED then
            shipX=shipX+12
        end
    -- draws ship sprite (image)
    sprite(ship,shipX,shipY,64,96)
    -- if ship image collides with asteroid image, change gamestate to try again screen
    for a,b in pairs(ast) do
            if b.y-96<=shipY+48 and b.y+160>=shipY-48 and
            b.x-96<=shipX+32 and b.x+96>=shipX-32 then
                gameState=2
            end
        end
    -- if ship image collides with either side of screen, change gamestate to try again screen
    if shipX-32<0 or shipX+32>WIDTH then
            gameState=2
        end
    end
    -- try again screen
    if gameState==2 then
    -- draw black background
        background(0, 0, 0, 255)
    -- display RETRY on screen for a retry button
        text("RETRY",WIDTH/2,HEIGHT/4)
    -- check if score is higher than the stored highscore, if so, change highscore to the score
        if score > readLocalData("HS") then
            saveLocalData("HS", score)
            end
    -- display score
        text("Score: "..score, WIDTH/2,HEIGHT/1.2)
    -- display highscore
        text("HighScore: "..readLocalData("HS"),WIDTH/2,HEIGHT/2)
    -- if retry is touched, change game to main menu, reset score, reset ship position, and remove all asteroids from table
        if CurrentTouch.state==BEGAN then
            if CurrentTouch.x>WIDTH/2-128 and CurrentTouch.x<WIDTH/2+128
            and CurrentTouch.y>HEIGHT/4-64 and CurrentTouch.y<HEIGHT/4+64 then
                score=0
                gameState=0
                shipX=WIDTH/2
                for i,t in pairs(ast) do ast[i]= nil
                end
            end
        end
    end
end

Thank you everyone your help and advice

  1. Good performance and an average game are WAY better than an exceptional game and bad performance