Thursday, 5 February 2015

Do we really need a native app?

As with most adolescent males, I have always been into gaming, having owned an Amstrad at 6 years old, wasting hours playing games like bomb jack. We all remember waiting for what seemed like an eternity on those old tapes to load!

Gaming intrigued me more so because I was curious as to the inner workings and mechanics that drove the games.

I wrote an essay back in college, on the history of gaming, and it was fascinating to me just how far it had come in the mere 30 years since its inception. I always knew that it would be an industry that I would love to work in. After a few years of working in web development, I decided to dive deeper into the guts of gaming, in an attempt to vary the work I was doing. Mobile gaming always stood out to me a bit more, as it seemed like an easier market to penetrate, and with the advent of smart phones and developer programs for iOS/Android, it lowered the bar for developers to get their work out there. I decided to research what was actually required to get a game to the app store.

So, did I want to build an native iOS game?

I had done some C/C++ in college, but having worked with Ruby On Rails and front end JavaScript frameworks (EmberJS, Backbone) for quite some time, I found that taking the leap back to these type of languages would only slow me down, or at least initially during the steep learning curve. I did not really feel the drive to learn either objective C or the new Swift programming language that will eventually take over the apple ecosystem. I thought that I might as well try to harness the skills I have at hand. Also, if I the game was to run on the android platform, I would have to port the code to Java and use the android SDK. Not so much fun!

Enter Phonegap, or now as it is known: Cordova. Cordova is a great little piece of software under the Apache licence that allows you to write a HTML/Javascript/CSS application (using any of the previously mentioned JS frameworks) and then simply build a native version of your application for multiple platforms such as Android/iOS/Windows Phone etc.

It all sounds too easy, right?
If you plan on writing a really heavy duty blockbuster 3D game then you might want to consider writing a native app, as with the performance of a native app over an app built with Cordova, there is simply no comparison.

For simplicity sake, however, I am going to stick with writing a simple 2D game from scratch. Well at least at first, and then include a 2D Javascript physics engine known as Box2D to do some of the heavy lifting. I will start from scratch with some simple animations and x/y coordinate manipulation so as to give you a better understanding of what the physics engine is actually doing for you once we hook it up! We will tinker with a framework called CanvasQuery which is a simple JS library for controlling your game run loop. This will allow you to read some input from the mouse/keyboard and control an on screen character, essentially creating a really simple game.
Once we have this up and running I will show you how to use Cordova to translate the game to an installable mobile app. I will show you how you can read from the devices sensors (Accelerometer), via the Cordova API.
Then we will dive into some really interesting stuff, and what I find most interesting in Computer Science. Artificial Intelligence. I will introduce some AI concepts into the games, such as hooking up a neural network to control other players.

This blog assumes some knowledge of HTML/Javscript/CSS and also some JS tools such as Grunt/RequireJS/Bower, but if you do not know these technologies too well, fear not. Our primary focus here is on the gaming side of things!

Knowledge of Vector maths might also be a bonus when we get into some more advanced graphic rendering and line of sight algorithms, but again not essential! I will link to the Box2D docs and any other required documentation for any plugins/frameworks I bring into the mix!

By the end of this, I hope to have a fairly playable mobile game written in Javascript that utilizes some sort of AI that performs reasonably well on a standard mobile device. It will never be as sharp as it's native counterpart, but for the simplicity and effort involved, I think that this route to creating a mobile game should be something you consider!

If you want to see a live demo of some of the things I have been playing around with, see:

http://canvasgames.herokuapp.com/game

Stay tuned!

2 comments:

  1. Great project Lee. Good luck with it.

    ReplyDelete
  2. Cheers Ed, I have wanted to follow through with this for quite some time now!

    ReplyDelete