Learn to code through making video games

November 19, 2020
Coding

Learn to code -- it’s a rallying cry to future-proof your career. Considering the way the world is going, it’s also not a bad idea. Learning to code helps you understand the technology you use, and strengthens your logical reasoning. You could end up changing your career even and becoming a software engineer if you love it. Or you get good enough to launch your own product, and then hire software engineers to take it from there.  

Even for the ambitious, learning to code is daunting. It’s a lot of text that looks complicated, it’s a lot to learn, there’s a decent amount of math involved, and it never works right the first time.  

Learning to code through learning to make video games is the best way. First, small games use less code than you think. Some fun games are only a few lines of code. Some more complex games are still only less than 100 lines of code. 

Don't believe me, here, copy this code below.

// I copied and edited the code from William Ritson here. This is JavaScript btw, which your browser can run no problem.

var secretNumber = Math.ceil(Math.random() * 100); 

var guess = -1; 

while (guess != secretNumber) { 

guess = prompt("Guess a number from 1 to 100"); 

if (guess > secretNumber)  alert("Too big!"); 

else if (guess < secretNumber) alert("Too small!"); 

else alert("That's right! It was " + secretNumber); 

Hit F12 on your keyboard, then hit control v, then enter. Boom you're playing a game that's less than 10 lines of code. It's pretty simplistic, but it works. Neat huh? 

In this quick post, we'll explore a few reasons learning to code through video games is the way.   

Making video games makes you a genius

Has anyone ever learned to code through video games? Outside of myself I can point to a few people just like me ;)
Enter Elon Musk and Mark Zuckerberg. Both of the famous geniuses learned to code at an early age. For both their first - or at least very close to first - projects were video games. Elon Musk said

“I think video games are a very powerful force for getting young kids interested in technology; it has way bigger knock-on effects than people may realize.”

source

In fact, Elon’s first big project was Blastar. It’s not great by today’s standards, play a browser port version here, but it’s pretty awesome for a 12 year old kid in 1983 when he published it. 1983 is the same year other 12 year old kids were busy playing Super Mario Bros.

Then you have Zuckerberg.

The first significant program Zuckerberg ever designed was a game based on the living room classic Risk. “It was centered around the ancient Roman Empire,” he says. “You played against Julius Caesar. He was good, and I was never able to win.” 

Source: 2004 interview with Harvard staff writer Grynbaum while Zuck was still in school

So there’s a trendline here of video games and wunderkind computer programmers. I’m not the only one to make this connection though, In fact tons of companies have sprung up to capitalize on this. Check out CodeCombat for example, that teaches kids to code through video games.  Even Apple has Swift Playgrounds on the iPad to teach kids to code with video game concepts.

Why do video games work for learning to code?

Most people want to improve their careers, but the potential fruits of learning to code are quite far from the frustrations of actually learning. There’s a certain amount of joy related to writing code, running it, and it working as planned. It’s like solving a puzzle or a problem. It feels nice, and if the code works, you get a little hit of dopamine. The thing about coding games is that the reward is better. We not only get the one dopamine hit of achievement, but we then get to play a game. That’s a second dopamine hit to the brain.

This is positive reinforcement at work. You're more likely to push through the frustration of learning complex coding concepts when the reward is a playable game. Compare that with making a web scraper or a tax calculator. 

There's little downside to learning to code through video games too. You'll learn foundational coding concepts and become adept at a programing language. Learning coding logic to make games is transferable to making business software if that's whre you end up.

Dopamine, positive reinforcement, and an immediate return, it’s a potent psychological cocktail for actually learning. So give video games a chance.

Alright, where do I start?

Rice University. If you search for the best online courses for learning computer science Rice will pop up. Their 2 part ‘An Introduction to Interactive Programming in Python’ course is widely regarded as fantastic. The course has a few notable features

One they use Python

Two they use a browser based editor

Three they use video games as the weekly projects

Each week the games get more complex, until you make a pretty sweet version of Asteroids. As of writing this my code is still available here. You can hit the play button at the top left and play it. In coming back to it after quite some time though, I’d turn down the acceleration of the ship, and the turning speed.

Line 127, fiddle with the constant there, try 0.1 or 0.2. 

And lines 140 and 144 try turning that down, give 0.08 a try.

Hey look at that, you’re coding a video game…. not so scary right? If you want to learn how to make that game, go check out their course: Rice University python course 

~

Learning to code is hard, there’s lot’s of trial and error, but when it works it feels good. When it works and you get to play a game, even better! The immediate reward reinforces the learning and helps keep you pushing through. Games also make the coding concepts more real, as it's easy to see how they are represented in the game. Rice is on to something here, but they’re following in the footsteps of industry titans, who in turn probably were chasing dopamine hits. You want to learn to code? Chase the dopamine hits and make games.


Follow me on Twitter

I tweet about the future, life, business, and random things