One night I was playing Legend of Grimrock and one of my best friends, Garrett, messaged me. He commented about the game, and I in reply told him he needs to play it. He told me he had no time because he’s always doing one thing or another, whether it be for school or for for extra-curricular things. I couldn’t really relate, and as a result he challenged me to make a game by April 14th. As you may have guessed, I accepted. So, in the next 7 weeks, I will be chronicling my adventures through making a game from start to finish, creating hopefully everything, art and music included, by myself.
For a while now, I’ve been doing work in a course from Udacity to learn programming (for the bazilinoth time). I’m taking CS 101, or Intro to Programming, and I’m quite enjoying it, even as I near the end in Unit 6. I feel like I’ve learned a lot in this course, and have gone further in it than I have in any other online course or book or series of videos. I feel somewhat confident in my basic programming experience in Python.
As a first order of business towards making a game, I went out and found a suitable library to work with. I would have tried to use an engine, but alas, there really aren’t any 2D ones. So, I found pretty much the most popular Python game framework, pygame. Boy, did I have trouble getting it to work. I tried and tried again to get it working, uninstalling, re-installing, doing it over and over again with different versions of both Python and pygame. Out of desperation, I even went to /r/gamedev’s IRC channel and asked them for help. A kind gentleman helped me out and told me I needed the 64 bit version of pygame to accompany my 64 bit version of Python.
Spending my whole life around computers, I felt ashamed, and I facepalmed. Hard. But, at the end of Friday night, I finally had pygame working properly, and I went to sleep.
Skip forward a couple days to Monday, and I started reading the second chapter of this book. I made a blank window, as it describes, read about how pygame works, colors, pixels, etc. But as I was reading and doing the section on drawing primitives, I thought to myself, “there’s no way I’m going to learn how to do this if I just copy everything word for word.” That in mind, I decided I wanted to make a checkerboard pattern maker. First try, no syntax errors! Yay!
…Oh. DANG IT. I scoured over my code, trying to figure out what was going wrong, skimming over the most obvious mistakes. After getting frustrated for a while, I contacted the aforementioned friend, the one who issued the challenge. I sent him a copy of my code, and I asked him for help. I suggested that it was probably a non-terminating loop somewhere, and lucky enough, it was. I had mistaken a “=” with a “+=” in a while loop. I facepalmed, again. This time even harder because I knew what I was doing wrong, but couldn’t find where. Two keystrokes later, and…!
Well, I mean, at least it worked by that point. But it only drew one line of tiles. The next day, Tuesday, I tinkered around with it a little but, but no success. Today, even, more tinkering, still no success.
And that’s where I am now. Still trying to figure out where my program is jumping out of the tile-drawing loop prematurely. I will not post this article until I have the damn thing working. All I’ve been able to do lately is clean the code up and make it look nice. The problem, I believe, is that the first while loop either skips the second loop (the row-drawing one) entirely, or exits out after a single loop.
Wow, alright then. I decided to ditch the while loops I was using and replace it with “for e in range(0, 15)” , 15 being the 300 (the screen height) / 20 (the size of a square). I know it’s a really archaic and inelegant solution, but it’s not like this program matters a whole lot in the long run. Here’s the final code:
# Checkerboard pattern maker # Makes a checkerboard pattern in the given screen space size # # Last updated: 2013 - 03 - 06 import pygame, sys from pygame.locals import * ### INITIALIZATION ### pygame.init() # Window setup DISPLAYSURF = pygame.display.set_mode((400, 300)) pygame.display.set_caption("Checkerboard Drawing demo") # Color setup BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) ### MAIN BLOCK ### DISPLAYSURF.fill(WHITE) numRows = 0 startX = 0 startY = 0 for e in range(0, 15): for e2 in range(0, 10): if numRows % 2 == 0: pygame.draw.rect(DISPLAYSURF, RED, ((startX, startY), (20, 20))) startX += 40 else: startX += 20 pygame.draw.rect(DISPLAYSURF, RED, ((startX, startY), (20, 20))) startX += 20 numRows += 1 startX = 0 startY += 20 ### MAIN GAME LOOP ### while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update()
Sorry for the lack of proper indentation. The in-editor code poster is lame and won’t let me do much.
Also, here’s a screen of the final product.
And what you see there is the first step into legitimate game development.
Previously, I have joined groups and taken the position of a leadership role. In all attempts, we have failed miserably. But by the end of these 7 weeks, I think I might be able to say that I’ve made a game on my own.
Next week, I’ll talk about what I plan to make, and maybe make something functional. Perhaps I’ll even learn how to make some art, even if it does look crappy.
This is gonna be fun.