Learning how to make 2D Games in Unity
By EricMesa
- 5 minutes read - 1005 wordsI’ve been playing video games since I was somewhere around 5 or 6 years old and got a Nintendo Entertainment System for my birthday from one of my aunts. I also inherited a Tandy computer from my dad when I was younger. We had a bunch of edutainment games - like this Sesame Street game (that unfortunately a quick search on Google Images does not turn up) where you had to suck the Tweedles (bugs from Ernie’s flower box) to solve math problems. I also, and I’ve mentioned this before in several places on the net, learned to program from a book on BASIC and made myself a bunch of simple games, including Madlibs clones.
I continued making games here and there, including in college when we had to program Moon Lander on an Atmel, somewhat coming closer to what it was like to make games on the Atari. When Linux Format Magazine had a series of Python PyGame tutorials, I made a bunch of games. One of the games I made was a Space Invaders clone.
PyInvaders
I’ve attempted to start a few more ambitious games a few times. I got relatively far in designing a game engine for a Parcheesi/Ludo game, but the implementing the graphics got a bit tough. I’ve also started RPG engines a few times, but never got that far.
A few years ago, I bought RPG Maker and I did a 5 minute Demo, but I couldn’t think of a concept I wanted to create. So that’s gathering digital dust. I probably would have gone further if there had been a class that went along with it. I’ve come to realize that’s closer to my ideal learning style. So when Humble Bundle recently did a Unity Bundle that mostly conisted of Udemy classes by some guys named Rick and Ben, I went ahead and jumped in feet first. I’ve already learned a lot with their Unity and Git class, which I did first, since it was the easiest and quickest. After that I decided to do their 2D class since I figured if there was something I was going to maybe attempt and complete after doing the class, it would be a 2D game. Also, it’s a fun chance to dive back in to C#. I hadn’t done anything in C# since a series of Linux Format Magazine tutorials in 2007. While I really, really love Python, I think it helps keep the programmer’s head sharp to learn new languages. I’ve been using Visual Studio and boy has that thing really come far from way back 20ish years ago when one of my little brothers was using it for a class in middle or high school. It’s like everything I love about KDevelop, plus a few other neat issues. Like the other day in one of the Udemy lessons, they highlighted a line of code in the “Update” method and then right-clicked and clicked on something that said “refactor” (or thereabouts) and it automatically made a new method and linked to it from within “Update”.
So far we’ve done a couple toy “games”. I’ll link to what I’ve done so far, but first I wanted to point out that one thing I’m doing in each ReadMe is adding in what I learned during that unit of the class. The first one was called Text101 and we rendered it to WebGL so you can play it here. It’s a Choose Your Own Adventure, but the lessons I learned there could very easily be ported over to a visual novel. (Not that Steam needs many more of those ;) Although, I really did love Analog: A Hate Story. The second “game”, Number Wizard, used a sort algorithm I remember learning in CS class to try and guess the player’s number. (At least until we updated it to make slightly more random guesses) I put “game” in quotes because the player isn’t really doing anything fun, just letting the computer know if they need to go higher or lower. My eight-year-old likes it, but that’s mostly a factor of the fact she’s impressed at what the computer is doing, not because it’s actually fun in a game sort of way. I compiled both Windows and Linux 64bit binaries for the game, so you can play it if you go to the releases section of my git repo.
The first REAL game we’re making is a clone of Arkanoid/Brick Breaker. You can tell that this is a real game in comparison to the previous games because the first two sets of lectures are each about 1-2 hours. This one is 6 hours long! AND they’re telling us a lot of what to do because it’s a class. Yes, they have challenge slides, but those depend on the student pausing the video. So if you never pause and just do what they say, it’s a 6 hour process. It also has given me a LOT more respect for the original games. Steve Jobs and Steve Wozniak programmed the original Brick Breaker for Atari and that involved programming in assembly and having various chips to interface with. With Unity, friction and gravity are taken care of. Bricks can be copy-pasted and colors easily changed. Adding sound is as easy as adding an mp3, ogg, or wave to Unity. You draw boxes that are easy to see to make your “walls” and “fail” areas. And you don’t even need to compile it to see if it is working. Just clicking on “play” in Unity will allow you to test most of the functionality of your game! Speaking of that, I’d like to share with you a fun video from the lesson where they showed us the 2D physics engine in Unity. I don’t know why this cracked me up so much, but the fact that the paddle was not a perfect rectangle led to this happening:
https://youtu.be/S5_7vda3jtQ
Spinning ball is spinning
Anyway, I’m having a blast and I’ll keep you up to date as I progress.