I’ve always wanted to write a game. For the longest time, every time I’ve looked into it, I’ve been overwhelmed by the number of options in what language or framework to whalechoose, what type of game to write and what kind of story I want in my game. This desire to write a game usually lasted for a couple days of looking things up online, before I decided that it was too difficult and I’d put it off again. The other night, I went and got coffee with an old friend to catch up. She’s worked with games a lot and she encouraged me to give it another stab. She also gave me some tips on what a good first game would be to write and how to distill it down to a simple idea.

With that, I am proud to announce the official launch of fail-whale, my first game! I used easeljs, a javascript library for interacting with canvas. The source is here for anyone who’s interested in taking a look.

One of the things I struggled with in writing this game was how to organize my code. All of the javascript I have worked with before has either been ad-hoc interact-with-the-DOM javascript, or stuff I’ve written in Spine. This time, with no framework to provide an enforced structure, I had to decide myself how I wanted things laid out. I went through a couple options before I ended up settling with what I wanted. (git probably shows that history.) At first, I went with a revealing module pattern, but later decided to just attach methods onto the whale and shark functions’ prototypes.

I also did not use a physics engine for my first game. Even though there is an excellent 2d physics engine, I decided to try implementing gravity and collision detection myself, just to get a feel for it. Gravity wasn’t all too difficult to implement; I mostly dropped in the intro physics formula for distance, acceleration and velocity and tweaked the coefficients until it “felt” right. Playing with the actual numbers was probably the hardest part. Collision detection was another story. Originally when I started out, I had red and blue squares representing the whale and sharks. Collision detection was really easy then. But then when I added the animations (all sprites designed and drawn by this guy, and the whale became a funny shape, collision detection became harder. I ended up just adding some “squish” where the whale and shark have to overlap by more than a certain number of pixels to register a collision to make up for the whale’s rounded belly. There’s probably a better way to do this, but I’ll leave that to developers of real physics engines.

All in all, this was a great experience. Have fun playing!


One thought on “fail-whale

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s