Page 1 of 2

Writing an Asteroids game - Teaching a 12yo to program

Posted: Thu Jul 11, 2013 7:16 pm
by driguana2000
Hi.

My first post. A few months ago my 12 year old niece asked if I could teach her to program. An interesting question. I've been programming for more than 30 years so the answer should be yes. But what to teach her? Ideally she should be able to create something fun with relatively modest effort. And so I started striking candidates off the list. Eventually the page was empty so I knew I'd have to look further afield.

After much searching I stumbled across these pages about Löve 2D. I'd heard of Lua before in the context of Unity 3D. Since then I've found .lua files lurking all over the place. It's a lot more popular than I'd initially thought. Anyway, Löve 2D has proven to be an ideal vehicle to teach my niece to program. The asteroids game is the culmination of our first project together.

You can find some tutorials that I created for her on my web site at

http://www.dr-iguana.com/prj_love_and_lua/index.html

I'm still writing the last two tutorials but the code is complete. Hope you find it useful.

Cheers.

Dr Iguana

Re: Writing an Asteroids game - Teaching a 12yo to program

Posted: Thu Jul 11, 2013 7:51 pm
by Robin
Neat! So, how does your niece like programming so far?

Re: Writing an Asteroids game - Teaching a 12yo to program

Posted: Thu Jul 11, 2013 8:33 pm
by driguana2000
So far she's enjoying it a lot. She's a pretty motivated kid.

Learning to reuse code is a typical challenge. It takes a while to see how certain patterns reoccur in a program and how you can create one function instead. Still, I'm optimistic. She asks insightful questions so it's sinking in. She enjoys chess as well so perhaps she has the right 'kind' of mind (if there is such a thing) to enjoy programming. Certainly it's not everyone's cup of tea.

Re: Writing an Asteroids game - Teaching a 12yo to program

Posted: Thu Jul 11, 2013 9:03 pm
by davisdude
It's a nice little game! My one suggestion: either make it so that asteroids don't hit you when you're off the screen, or have the screen follow the player.

Re: Writing an Asteroids game - Teaching a 12yo to program

Posted: Thu Jul 11, 2013 9:10 pm
by driguana2000
All good suggestions but I was trying to make a simple game. Also, this follows more closely the original game (pretty limited computers in those days).

I also though about adding passing power ups that would lure the player from the centre of the screen. But, the game has fulfilled its purpose as a teaching tool so I think I'll let it stand as is. But who knows, perhaps I'll be tempted in an idle moment. :awesome:

Thanks.

Re: Writing an Asteroids game - Teaching a 12yo to program

Posted: Fri Jul 12, 2013 12:11 am
by davisdude
I didn't know it was based off another game. Sorry about that... :P
It still is a pretty good game, especially for a first! :)

Re: Writing an Asteroids game - Teaching a 12yo to program

Posted: Fri Jul 12, 2013 6:07 am
by LuaWeaver
Awesome! I started programming around that time too. Make sure to teach her good habits, I didn't get those being self taught. Took me 2 years to break free of all the bad habits (like editing code in notepad). :oops:

Re: Writing an Asteroids game - Teaching a 12yo to program

Posted: Fri Jul 12, 2013 1:51 pm
by josefnpat
First, I'd like to say this is fantastic!

I think asteroids is a daring subject to undertake, due to the trigonometry involved, but I still think it's a universally understandable result!

I have a few notes, if you're interested;

In chapter 1;
Function fred.washclothes()
I would highly suggest making it
function fred.washclothes()
To ensure that the student doesn't think that capitalization is like english.

In chapter 2;

You use "The meaning of each is the text in gray."

Consider introducing comments here instead of on page three and chapter 5! Then you can document every following example.

In chapter 3;

"Finally, we modify the love.graphics.draw function."

Consider writing our your functions like this, so you can easily show the change, and you can comment each argument;

Code: Select all

love.graphics.draw(
    spaceship[spaceship.useImage],
    spaceship.xPos,
    spaceship.xPos,
    spaceship.direction, -- This is the direction, woo!
    1,
    1,
    21,
    36)
Also, it might make the chapter longer, but you ought to consider grouping chapter 3 and 4 together. It doesn't make sense to teach love.update incorrectly, and then correct it in the next chapter. Best to teach it right the first time around.

I chapter 4;

You have this one section in the code where you use "some trigonometry magic"

While I do not believe you can teach a 12 year old all of trig, I think you can teach a subset of trig effectively. Check this out!

Consider taking a chapter to teach this, considering you're teaching asteroids.

For chapter 6;

Be careful of double quotations. Your word proccessor is formatting them to open and closing double quotations, which do not parse correctly, and therefore your code is not copy-pastable.

Re: Writing an Asteroids game - Teaching a 12yo to program

Posted: Fri Jul 12, 2013 2:10 pm
by driguana2000
First I'd like to thank you for taking the time to write your thoughtful comments. I'll look through the tutorials, when I get a chance, and see how many of your suggestions I can incorporate.

Some of the roughness in the tutorials comes from the fact that I'm learning Love and Lua at the same time as writing the tutorials. I hadn't had the asteroids game in mind when I started teaching. Just moving things around the screen seemed sufficient payback to start. At the time I wasn't even aware of dt (delta time) being available in Love.

Once I started on the Asteroids game, and began adding more elements, the frame rate began to drop. The need for a delta time became obvious and I found out about dt via Google searches. This explains the 'fix' tutorial. It also prompted me to work ahead and finish the game before doing further tutorials so I could avoid too many more missteps.

I have to say that Love/Lua is remarkable environment for its simplicity and what you fun things you can accomplish with a small amount of code. I haven't pushed it hard yet so I don't know exactly where the walls are but it seems quite capable.

Re: Writing an Asteroids game - Teaching a 12yo to program

Posted: Fri Jul 12, 2013 6:44 pm
by jjmafiae
sounds good, but love is not only an easy kids engine, it can also be used for more advanced and commercial games :3