Tuesday, January 3, 2012

A letter to my cousins: A Suggested Route for Learning Python and Game Programming

So a new year, and a new resolution to write some more articles on this blog.  I thought I would start off by sharing a letter I sent off to a few of my middle school grade cousins who approached me about learning to program games over the holiday week.  I'm the first to admit I've never written a game, but I have written a considerable amount of code and am aware that game programming is no small feat of coding.  Without further blabbering this is what I pulled together for them (and a link to a google docs version for easier reading).


                    Hey there cousins :)
So I've been puzzling over the best way to present this information to you and give you some direction in the mean time.  I've pretty much just opted for the stream of consciousness approach (or, type as I think).
First your going to need some tools.
An archive manager, this will let you open files zipped up in zip, rar, or other formats.  I prefer 7zip for windows, you can get it here:  http://downloads.sourceforge.net/sevenzip/7z920.msi
Next you will eventually need a version control package so you may as well get that, for home projects I'd recommend Mercurial: http://tortoisehg.bitbucket.org/ Make sure you are downloading the 32-bit version of the program.  I would also add the command line program from http://mercurial.selenic.com/wiki/, just grab the latest version and install it(32-bit windows).
It's an installer and free, just run it and your in good shape.
Then I would recommend downloading Python(x,y) which is also free like the above two pieces.  The direct link is: http://ftp.ntua.gr/pub/devel/pythonxy/Python(x,y)-2.7.2.1.exe and you can get more information on the package at: http://code.google.com/p/pythonxy/  It's a package for making scientific applications in python, however it has a full editor suite and includes all the base software you will need to get rolling except pygame itself.
Finally you will need pygame, your going to want this link: http://pygame.org/ftp/pygame-1.9.2a0.win32-py2.7.msi The version of python included with Python(x,y) is version 2.7.2 so this will give you the correct version of this library.  For more information and example projects you can find extra information at http://www.pygame.org/news.html this is the main site of the pygame team.  Once you've developed your skill set the 'cookbook' section of this website will prove invaluable as will the tutorials area.
Now the hard part.
Once you've installed all that stuff, you are ready to go but you have a significant number of hills to climb before you are ready to start writing game engines, game content or things of that nature.  However using python these barriers should be less painful than they could be in other languages and systems.
You have a number of things to learn, and the first among them is how to use your tools.  If you've installed python(x,y) successfully you should find a program called 'spyder2' in your program list.  This is an editor you can use to easily edit python with large amounts of feed back on your code.  It's documentation can be found at http://packages.python.org/spyder/ I would recommend reading at least the overview and the editor sections for now.  You'll also need to know how the consoles work but that's more of an experimentation learning experience.
After you have learned how to open and close files in the spyder editing environment you will be ready to start teaching yourself python.  To this end I'm going to direct you to the book 'learn python the hard way'.  This is not fundamentally more difficult than other ways of learning python, however it is a more classical approach that requires you to type in every line of code in every program you make.  Following through the book and completing all the exercises will go a long way towards teaching you both programming and python.  The HTML (web browser) version of the book can be found here http://learnpythonthehardway.org/book/ or you can buy a copy of the epub book (for reading on a kindle) for 2.99 off the top of the website.  Follow through EVERY lesson, and make sure to read diligently (you can however skip exercise 0 as this tells you how to get python, it may be informative however).  I also strongly recommend you make an honest effort to do any of the 'extra credit' pieces at the end of each example.  This will allow you to explore the functionality the book is teaching you before you move on.  If you do not understand a word in the book, you can find it's definition by going to www.google.com and typing 'define: word you don't know'.  By the end of the book you will be able to generate webpages in python, and make small web based python games.  This is a significant step towards where you need to get to.
After you've completed those exercises and spent sometime manipulating them to change their behavior I would recommend the following articles on a number of topics.  I recommend reading each thoroughly and trying to combine them with some of your developed knowledge of python.  These links are just to get you started but they should be good leaping off points to discover which sections of programming you don't just 'get'.  These are areas you should spend more time researching using tools like www.google.com, http://stackexchange.com/ and Wikipedia.
Version Control Basics (how to use mercurial and why): http://hginit.com/01.html  Start here and go thru the examples, they are excellent.
The Python Style Guide:http://en.wikipedia.org/wiki/Python_syntax_and_semantics and http://www.python.org/dev/peps/pep-0008/  Following this will help make sure your code is readable and correctly commented so others can read it as well
Conditional Statements: http://en.wikipedia.org/wiki/Conditional_(programming)
Boolean Algebra and Logic: http://en.wikipedia.org/wiki/Boolean_algebra_(logic)
Big O Notation: http://en.wikipedia.org/wiki/Big_O_notation
Sorting: http://www.codeproject.com/KB/recipes/SortVisualization.aspx  This provides visualizations into a number of different sort algorithms that will be critical to understand.  I recommend looking up the wikipedia page of each sort type and reading through those articles as well.  Wikipedia is invaluable for this sort of things (IE, http://en.wikipedia.org/wiki/Bubble_sort, http://en.wikipedia.org/wiki/Insertion_sort).

Object Oriented Programming and Software Architecture: http://www.codeproject.com/KB/architecture/OOP_Concepts_and_manymore.aspx
Software Design Patterns: http://en.wikipedia.org/wiki/Software_design_pattern and specific patterns implemented in python: http://www.python.org/workshops/1997-10/proceedings/savikko.html
Python too executable conversion: http://www.py2exe.org/  and a basic tutorial in it's use http://www.py2exe.org/index.cgi/Tutorial.  This will let you turn your python program into a .exe file you can send to your friends more easily than teaching them how to use and run python.
And finally you'll want to read a book that covers end to end game design, this will include a large amount of math as well as subjects like animating objects and rendering to the screen.  A highly recommended book based on python is Invent Your Own Games With Python.  It can be read online here http://inventwithpython.com/chapters/ or you can purchase it off of amazon here http://www.amazon.com/gp/product/0982106017?ie=UTF8&tag=playwithpyth-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0982106017.  NOTE: While this book can be used in place of the 'learn python the hard way' book, it will lack some of the substance and fine detail that book discusses in teaching you individual lessons.  All that aside it is however an excellent beginning programming book as well.
I wish you the best of luck learning programming/python/game writing/computers and hope this turns out useful for you,
-Garrett
ps. Don't forget, working together will not double your learning, but it will help you both develop much faster.  Also, you should probably print this so you don't lose it.
So to the community at large:  Is this helpful / the right direction to go?  What would you suggest or change about this to gear it more at the target audience (middle-school boys that know they want to write games but don't yet appreciate the scope of what they are getting into).