Using Codea to teach programming (UPDATE: Codea programming class starts Monday)

Hello, I teach programming to children. I am writing a new curriculum for a 15 hour class (5 days, 3 hours each). Students are age 11-13 and have no prior programming experience.

It is my goal to have them finish a simple game in this amount of time. Ideally this game should be simple yet addictively fun. It should also showcase the tactile interactions possible with an iPad (turning it to control the character, touching the screen where you want to shoot, etc).

The kids will basically follow along with me as I make a game and explain the reasons behind my actions.

I’m looking for ideas on what sort of game to make. I’m currently trying to program a simple boids implementation for my own benefit until I can get a better idea of what I’d like them to do.

Some thoughts:

Setting up the physics engine is verbose (if the demo is any indication) and not something I care to spend much time on. I’d be okay having them copy some class to handle this, but I try to keep the ‘use this blackbox solution from the internet’ approach to an absolute minimum.

I always try to emphasize the concepts of scope and inheritance to beginners. Working with tables will seem to be a good exercise too.

Whatever approach I use must use good programming techniques, and ideally be elegant. The collisions in the Brickout demo are an example of something Id like to avoid. That said, I’m not sure how to improve on them, and I think that a Brickout-like game might fit the ticket.

Here’s my experience helping me when making programs: Start with the classics. Frogger, space invaders, pong, snake, packman, etc. Those tend to use array/table managing a lot. I really think that Codea is a great place for beginners to start.

As a non-techer, this was my attempt. It may be too basic and silly. It’s hard for me to know how many concepts can be grasped in a single session and how to get everyone to the same level of comprehension.

Hi @SciQuest. Thanks for joining the forums.

I may have mentioned this before, @Ipda41001 has written a pretty great Codea intro for young kids:

Regarding scope and inheritance. Scope in Lua is global-by-default, just something to keep in mind that you need to explicitly declare variables as “local” to get normal scoping rules.

I would probably avoid classes and inheritance in targeting the age group you mention — a purely procedural might suit better, what does everyone else think? You can still split the code up into multiple files, just make “Blank files” rather than class templates.

All my schooling was in class. :smiley: That being said, I think it would be a good place to start to bring up the idea of classes. First write an example without classes, then show what it looks like with classes. Keep doing that for a bit, then just use classes later on. Your students will thank you later!

I started in QBASIC in DOSBox (google it). Really messy and not the best place to start (no syntax highlighting). That was a side note. I actually suggest making your own programs in Codea and shown it to the students as inspiration. My dad did that. He would make snake or something like that and I would have to code it myself. He would also every once in a while put an easter egg in my program and I would have to find it. That helps with finding bugs. Haha. I remember when he randomly made a StarTrek ship fly through my program. That was annoying to find. He imported code from a different program using Good days…

Ah… forgot Lua was global-default scope. Thanks, you just solved an annoying bug! (boids only formed a neighborhood when they were near the borders of the screen)

Im beginning to think they could make boids. Its pretty, interactive, highlights simple concepts, and requires some (but not much) math.

Ill post more once the work day is done / tomorrow.

EDIT: Trying to make the game framerate independent. The time functions only seem to deal with full seconds. Can I get milliseconds?

You can use the two global variables: DeltaTime and ElapsedTime to make your code frame-rate independent.

Multiplying your movement-per-second by DeltaTime should give you what you’re after. (Note: the physics engine is frame-rate independent internally, as well.)

Someone posted a boids or flocking code or video at some point. I went looking back through the forums and couldn’t locate it. I can’t find the code on my iPad so I am guessing they didn’t post it.

I tried looking for boids too, and was surprised to not be able to find it. Ill release my code once its presentable.

At the moment there can be an arbitrary number of species of boids, who will flock within their species and avoid other species (Im calling that behavior ‘xenophobia’ :slight_smile: ). You can click to place a new boid. This is achieved in ~230 lines. I will add obstacles and predators soon.

I think that for my class I will start them off with a simple drawing program I made (day 1, 3 hrs) and then spend the remainder of the class time on boids (4 days, 12 hours).

The ‘drawing’ program has a number of parameters (links, angle, length, deltaAngle, deltaLength) which then draws links-many lines, translating and rotating according to angle and length, and on each step multiplying angle and length by their deltas. It also lets you draw it around, and click to recenter. Note that push/popmatrix is not used, so it tends to generate a spiral. I might give each line a slightly different color than the one previous, to generate a rainbow effect.

I taught a class on Codea last week [my style can be summarized as “follow along!”], and it went swimmingly! Unfortunately, there was only one student (age 11), and he was not representative of his peers. He knew the syntax of Lua, and had the sort of keenness of mind that would lend itself well to the field of pure mathematics.

That said, in our 15 hours of class time we made:

The chain-demo (which I described in my post immediately previous this one)
The Game of Life (random initial conditions)
Bubble-Sort and Merge-Sort (I wanted to include a visualization for them but wasn’t sure how. Anyone want to help me out?)
Naive recursive implementation of the Fibonacci sequence (I provided no code for this one and made him recreate it himself!)
Connect Four with the MCTS AI

and I taught him the properties of exponents, logarithms, and introduced him to geometric meaning of the sin / cos functions. I showed him how the Boids code worked, but we didn’t try to re-implement it due to his curious lack of math background.

So, not a typical class /AT ALL/.

I do have another class on Codea next week, which will have 5-6 people in it (ages 11+).

My intent is to do my introductory spiel, then start on the chain-demo [because this is a no-experience-necessary class], while discussing the elementary aspects of Lua programming (variables & assignment & types, conditionals, and loops - functions and lists will be mentioned soon after).

Then I will move into creating the Game of Life (as it teaches not just lists but two dimensional lists).

I will use this to transition to creating Connect Four, then build the AI on top of it.

If time allows, we will add TicTacToe to the game (because I would have cleverly had them implement it in a modular way, without knowing that was what they were doing).

Does this sound good? Anyone have any suggestions?

Wonderful! I wish I could have that much time to be in a class and just program in Codea. Sounds like fun. Quick suggestion: Give them free time to get a hang f the language an help them web needed. To implement an image, go like this: ![anyimagenamewhatsoever](
For instance:
Here’s the code:

function setup()
    hb = ElapsedTime --heartbeat
    t = {} --table to sort
    max = 10 -- max entires and value, allows duplicates
    for i = 1, max do
        t[i] = math.random(max)
    i = 1
    j = 1

function draw()
    background(40, 40, 50)
    if ElapsedTime > hb + 1 then
        hb = ElapsedTime
        --start sort
            if i <= max then
                j = j + 1
                if j > max then
                    i = i + 1
                    j = 2
                if t[j] < t[j-1] then
                    t[j], t[j-1] = t[j-1], t[j]
        --end sort

    --draw table
    for di = 1, max do

This is a visual bubble sort.

I didn’t decorate much because it may not be the right direction.

It is to show that having to display the loop, breaks the loop, and may break the lesson.

They would code between “start sort” and “end sort” given i and j set in setup()

Another alternative may be a that they write thier code in a function that they coroutine out to draw.