Sunday, August 5, 2012

Making a game data server with Node JS

Hey guys,

So this is going to be a new series of tutorials that I'm going to run that are based in the world of Node, mobile gaming and network data delivery and database management. I realise that this is quite far removed from the tutorials that I was running before, but as many of you may be aware, my current work has taken me further away from Flash and Game programming and into a more supportive role with back-end programming and database services taking up the greater percent of my brain power. So subsequently, I'm going to be writing tutorials based around this area.

I briefly mentioned in my last post that I was going to try and use Tuts+ to publish my Tutorials, however, I have had some issues with trying to submit some things to them and so am now going to be running them both here in text form and hopefully screen casts of them on my youtube account also.

This tutorial is going to go over the basics of the software that we'll be using, how to get things moving with Node, and what exactly we're going to be doing with Node.

Node is a Java based server technology, which is very both in terms of running as well as development iteration. The purpose of Node in these tutorials is to provide an end-point for an arbitrary application to connect to to ask for some data. The best way to perhaps think about Node is that it is a gateway that sits somewhere on the internet (or in the case of this tutorial, a port on your computer) and awaits incoming requests and then does something when it gets a request.

Node can be downloaded from here - depending on the operating system you're on, you'll want to get the right version for you. From the experience that I've had, Windows is a bad development environment for this sort of thing, but still works, I work from a Mac and Linux platform, however, the code and skills that you'll acquire from these tutorials are transferable as they're all based in the same language - Java.

Node comes in a installation package, so once you've downloaded it, install it onto your computer, and that's pretty much all you need to worry about for installing. Once you've done that - you'll want to open up Terminal - we're going to go Matrix up in here. Terminal is where you'll be running your Node server from and frankly, Node is a very good way to get to know the way terminal works and the basics behind a command line interface. As I'm working in a Mac environment, the commands that I'll be issuing will be for Mac CLI (Command Line Interface) again, the Windows and Linux commands are fairly similar, e.g. cd in Mac = dir in Windows.

The first thing you'll want to do is create a folder somewhere that you'll want to put your Node server.

$ mkdir SPGames_Tutorial1 
$ cd SPGames_Tutorial1 

This will create a folder on your computer, and then change directories into it. Once you're inside this new directory, you'll want to do one of several things, depending on whether you want to use a simple text editor like VIM or a more complex GUI like EMacs or Notepad++, personally, I use VIM, so the command that I issue is:

$ vim app.js

This will start a new file in VIM, and open up the VIM editor in your Terminal window. If you haven't used VIM before, the controls can be kind of hard to understand and seem quite unintuitive, but after a while, you'll get used to them and be able to navigate through huge files very quickly. The few commands and key strokes that you should know for this tutorial are:

"i" - enter insert mode (Basically, you need to hit this to type anything onto the screen)
"Shift + ZZ" - Save and close a file. Alternatively, if you want to save, but don't want to close the file, you should
":w" - This command will only work if you are outside of insert mode, to exit insert mode, you simply tap escape.

There are literally hundreds of keystrokes and keystroke combinations that VIM allows that allow you to look for things, go to the end of a word, end of a line, start of a line, find a matching parenthesis, the list goes on. But these ones will get you start.

So, once you're inside VIM, you'll want to type out the following. Now, this is where one of my cardinal rules of tutorials comes in, if you're following this tutorial, I seriously urge you to put your Terminal window on top and type out the code in your own screen as opposed to copy & paste it. It is of course up to you,  but I tend to find that I really don't hold onto much information  if I just haphazardly copy and paste things in, and when things go wrong and it doesn't work - then I don't know what on earth is happening because I didn't write the code out myself.

Stepping through this code:

Line 1: Creates the "http" variable, the require('http') grabs the http library from node for use.
Line 2: Create a server with our new http variable, the createServer method takes a function argument, with two parameters, req & res. Req is the request, and of course res is the response.
Line 3: Writes some header information to the response object.
Line 4: Ends the response object with a little bit of writing.
Line 5: The .listen method of the http object sets the server up in terms of what ip address and port you want the server to listen on. Here it's listening on local host and 1337 for port.
Line 6: console.log is a great way to test the server when you need to debug and know what's going on in terms of contact with the server.

Now that we've written on the code of the Node server. Save the file in VIM by hitting Shift+ZZ. Then to start the server up:

$ node app.js 

Once the server has started, you'll want to keep that Terminal window open or the server will shut down. Using your favorite browser, navigate to the address that you specified in the Node app, in my case Here you'll see the message that you put into your node app when you wrote it out.

That's all that I wanted to put into this tutorial, it's a slash dash start-up and introduction to Node, and from here we're going to cover a few more complex subject. Most importantly, how Node is going to server as a game server for holding information and some more complicated

Tuesday, July 17, 2012

3D Game Development - A beginners guide to choosing the right SDK

Hey guys,

Recently I've been looking at a range of 3D game engines that lie outside of the Actionscript Stage3D realm, with the announcement that the Flash Player will no longer be supported on mobile devices. I am hoping to create a new 3D game idea that I have been mulling around in my head for quite some time now.

After looking for a really long time and playing with a few SDK's and seeing how they all weigh up against one another, there are a few standouts.

Unreal Development Kit - The engine behind the unreal series, a truly powerful piece of software, I won't deny that this thing LOOKS amazing. However, if you are looking to be able to ease into the development process, be warned, UDK uses it's own proprietary language called UnrealScript, and whilst it's not so far away from other OOP languages, you'll find yourself relearning a few idiosyncrasies of that corner of programming. It's free to play and develop with, however, if you're intending to go big with it (multi-developer big) then you might be deterred by their licensing, which until recently declared that royalties must be paid for any earnings over $50,000, however, there is now a application process that has to be gone through to get approval I believe. Aside from all of this, UDK is a brilliant set of tools to develop with, it's powerful, very quick at programming iteration and the engine itself looks gorgeous. There will be a learning hump before you get into any solid development, but apart from that, a good solid choice.

Unity - Unity is one of the best engines I've played with, it's got a huge developer following and looks great. In terms of pricing, Unity uses a 'module' marketplace, for where you want to deploy, this can be a blessing or a curse depending on how you look at it. For example, if you only want to develop for mobile devices, it'll only be two modules, but if you want to go platform wide, it'll cost you a lot more. There are also both a professional and standard options which allow you to save money by losing out on some features (click on the 'read more' link under each product). Aside from that, the game engine is great, very fast iteration time, good work flow and very easy to do things like model rigging, audio and above all, multi-platform deployment into native code. Unity also frequently does discounts and freebies, so it's always worth having the site on bookmark so you can come back later and see what's going on. Be warned, however, Unity is a end-to-end development suite, so if you are planning on coming into a project half-way through, you might find things difficult to pickup.

jME - jME or Java Monkey Engine is a engine that I came across very recently when searching for alternatives to the standard Android development suite, with 3D in mind, from what I've seen of the features and more importantly their showcase, it looks to be a very powerful, and easy to use system, it comes with it's own IDE, so no need to worry about messy set ups and getting things working in Eclipse or some such. I guess the most important thing that you should take away from jME is that it's 100% free! However, you'll only be developing for Android or Web. Which, considering the market and where the money is at the moment, might not be desirable.

ShiVa - I thought that ShiVa deserved a mention in this list also, ShiVa has been around for a while now and boasts some pretty impressive features, compiling code in C++ it's got a lot going for it, and it's relatively cheap too. And they're currently running a web deployment special which allows you to upload games for free.

Ultimately, as an indie developer, I'm always looking at the free or less expensive options when I look at a development environment, but looking at the wide spread of both suite and of price, I would suggest to anyone going past my blog to have a look at either Unity or Unreal, I recognise that they're more expensive (well, Unreal is only costly if you make a AAA title with it,) but I personally think that for the price that you need to pay for the product, you really do get the support and system that you pay for. 


Saturday, June 16, 2012

The Future of Tutorials

Hi Guys,

Just wanted to post up a quick little blog update about what's going on with me and how I'm hoping to do things in the future for tutorials on the website. As some of you may be aware, I've recently gotten myself a new job, which is taking up a large portion of my time, and as much as I would love to continue to make movies with my dulcet tones and instruction, I just don't have the time any more.

So - that leaves me in somewhat of a predicament, I want to continue to provide all of my followers and readers of the blog with the quality tutorials that I've been putting up in the past months, but I can't physically sit down and dedicate the time to actually doing it - so I've resolved to putting my writing skills to good use and I'm now going to be instructing through the medium of the written tutorial.

To make things easier for myself, and to ensure that everything is kept in proper order, I've gotten myself an account with Envato's Tut's+ to host all of my tutorials on - this will allow for all of my old videos to be put up as well as the corresponding text also.

As for what the future of my tutorials holds, as I said in my last post, I'm going to be moving away from Flash in a somewhat smart fashion because I feel that the language is becoming stagnated and there are better alternatives out there for game development and I intend to show you all just exactly how to do that with my new series of tutorials.

I'll be looking mostly at mobile development, because that's what I've been developing on all this time, and the skillset that I've acquired at my new job has given me sufficient skills in the mobile programming field to consider myself to be somewhat of a authority on the subject. In the next series of tutorials I'm going to be looking at:

 - The development lifecycle (mobile).
 - Debugging on Android and iOS.
 - Cross-Platform development for indie game developers ($$$ = :( )
 - Mobile games & Database driven gaming
 - Node JS - a beginners guide (this warrants an entire series of tutorials on it's own - it's a big field)
      - Setting up the node
      - Modules and you.
      - Encryption and hashing
      - Database management & REST calls

 - jQuery, EaselJS & the Flash Actionscript killer.
 - In-App Advertising, who to pick and what to call them
 - In-App Purchases, how to set it up.

These topics are all things that I would like to cover and will be writing on in the near future. I DO still intend to finish off the last part of the Nape tutorial series, but I am certainly keeping my focus on the mobile gaming side of the spectrum as I feel that it's going to become a huge part of the future of gaming.

In the mean time, feel free to check out TutsPlus as it's already chockers with tutorials on many different subjects.



Sunday, June 10, 2012

SPGames - Flash & What's next

Hi everyone that reads my blog.

I just wanted to have some face time with you all about what's been going on on my end and where the next in the tutorials is going to be. For all of you that have been following my Nape series, I will be wrapping them up next tutorial. I understand that they've been highly sought after and have been some of the only tutorials written for Nape.

However, in my current job, I have been doing less and less Flash actionscript programming and a lot more on Javascript, HTML5, Python and several other languages, however, what I have been doing most of all is server client architecture and the technologies behind it such as Node js. This had brought me to an interesting point in where I want to go with my tutorials and what I want to be showing you guys.

I'm currently in the process of developing a mobile game which I intend to send out on both iPhone and Android, it has given me a lot of things to think about in terms of languages, server communication, database storage and most importantly, game logic and how to make the game fun whilst maintaining income and the like.

I would hope to be finishing the Nape tutorial in the near future and then I'll start putting my documentation together for the next series, which will start with Node JS and the technologies that are behind that.



Saturday, March 24, 2012

Nape Tutorial 4: Bump and Grind hits Youtube.

Hey guys, just a quick heads up, just wanting to let oyu all know I've gotten around to finishing Nape Tutorial 4. This Tutorial concerns itself with Collision Detection and how to know when two objects are hitting one another. It's starting off small, and I suppose I intend to touch on the subject again when we do a little more complicated stuff. But for the mean time, it's intended to let you all know exactly how to go about listening for collisions in your games!

I have updated my github account to more accurately reflect things, so now there is a repo for each individual tutorial instead of it all being lumped together.

Thanks again for all the input that was sent through to me, really valuable stuff :). Until next time!


Thursday, March 8, 2012

Nape Tutorial 4: In The Works

Hey guys, just wanted to post up a little bit of into to keep you all in the loop as to what is happening with the tutorial series for Nape. I'm currently hard at work at a new job (ActionScript programming!!!) And have had not a lot of time to get things moving along with the fourth tutorial.

 However, today, I have started to make tracks towards the next video in the series. I'm hoping to bring a bit more production value to the series with this newest addition so I'm putting in a bit more work to try and make things a little easier for everyone to understand. There is going to be powerpoints, goals and objectives, things to remember, summaries etc.

The next tutorial in the series is going to look over collision detecting and how to use it in your games for fun effects and functionality! It is going to be entitiled, Nape Tutorial 4: Lets get Physical!

I am hoping to get some time on this weekend to try and get some of this down, but failing that, I'd hope to be bringing out the next in the series within the next few weeks.

Thanks for your patience!


Friday, February 17, 2012

Nape and Flash Develop - Tutorial 3: Joints and you, a comprehensive guide

Hey guys! Here it is! Albeit a little late, here is the third installment of the Nape Physics Engine tutorials, focusing on Joints and the various types of constraints that you will come across programming for the Nape platform. I apologise if it seems a little rushed, I've been wanting to get this movie up for you all a long time ago, but haven't managed to have the time, but finally got my act together and produced something.

Expect to see the production value of my movies go up significantly in the coming weeks as I start to get a little more technical with the things that we do with the engine.

As I say at the end of this movie, I'm planning on doing a few other things with Nape aside from the normal tutorial series, which is next going to delve into Collisions and how to deal with events caused by them etc.

I'm also going to be starting another series which puts into use my new software MazeGen, and takes the XML files generated from that into a Nape backed physics file to create physical mazes! Stay tuned, now that I'm back at home, I hope to be churning movies out midst all the other stuff that I have going at the moment.

Also, one final thing, in regards to a github repo for this tutorial, something that I forgot to mention in the actual movie is that I haven't made one, the reason being is that the code changes several times and the most that you can hope to get out of it is just a single example of a joint. The purpose of this movie was more informational than actually build something.

Thanks again guys,

David out.

Thursday, February 16, 2012

MazeGen v0.0.1

Hi guys, bit of an update for you all, and the introduction of a new piece of software to my online portfolio! I present to you all MazeGen. For a few moths now I've been infactuated with Maze Generation tools and how to create dynamic mazes that are both solveable and highly complex. I spent a lot of time on Emanuele Feranato's site (found here) which goes through how maze generation works and there are a few open source code snippets on the matter also.

The main reason that I was interested in maze generation is that I have a passion for maze type games - anything that is both puzzling and interactive. So mazes and maze generation is perfect for me! What I originally set out to do was to use the code on Emanuele's site to in turn create physics objects from the generated maze, which could then be manipulated as I saw fit.

The way in which I envisioned the code working was this:

 - given a height and a width the maze would generate
 - the maze would then be sent to an xml file, with each row of the maze having a row in the xml file, 1's representing a wall and 0's a gap. This would allow for the maze to be broken down into something akin to:



- The XML file would then be parsed by a physics creating loop which essentially looked through each row, and for each 1 it found, create a physical object. Thus leaving us with a maze!

I had several fairly major problems along with way. My main issue was that I was targetting Corona SDK for the project - which, took on the actual code generation part of the task admirably, but when it came to converting the XML file in to a tangible maze I found that it had some pretty major shortcomings. The biggest of which is that you can't actually create a compound physics object, which is a large object made up of smaller objects all tied onto the one entity, the reason that I needed this was that in order for the object to remain a whole maze would be that each wall was connected to the ones next to it, without this, say for example when the maze rotated, each individual block rotated about it's own axis as opposed to rotating about the center of the maze.

After a few weeks of frustrated bashing away at the keyboard I turned back to my flagship language Flash to get things moving. I re-wrote the maze generation code and put Nape in as my engine of choice, which turned out to be a godsend, as Nape allows you to push as many "shapes" as you want into a single body before creating that body in the world, which in a nutshell was exactly what I needed.

So, now that I had a working system, I went about modifying the maze generation engine to make things easier say for a person wanting to make a maze based game. The major things that I wanted to produce with this piece of software was ease of use and simple interface interaction, this alpha release accommodates these features, as you can see from the screen-shot, there is some very limited functionality. The user manual (however brief,) will uploaded and available for reading along with the swf.

Here is a link to MazeGen v0.0.1 - this will open up in a new pop up window.

I'll give you all a quick rundown of how it works - enter in a width and a height into the respective boxes, and then hit generate. You'll get a image of what the maze would look like, if you don't like it you can just hit generate again until you find a maze that you like.

When you do, click the Save Maze to XML File button, this will push the Maze into the XML file, that particular maze is now "saved." And you can enter in a new width and height to get a new maze to save.

Once you have finished generating all the mazes that you want, click the Save to disk button, this will give you the save file prompt and you can select where on your computer that you want to save the XML file.

v0.0.1 is by no means bug free - I expect that there will be problems, but the major ones I hope to have plugged by now.

In future versions I'm hoping to introduce a number of other things:

 - Multiple export types
 - Load XML file
 - Edit Mazes that are in the XML "stack"

Thanks for reading through all of this, and I hope that you have read up to here. Please feel free to have a play with it and I'll soon be uploading a video of how to get the XML file back into Flash and generate some physics objects from it!


Tuesday, January 24, 2012

Upcoming tutorials

Hey team, I know it's been forever since I posted, and there's good reason too! I've had massive computer problems, and have just managed to get myself back online and everything shipshape again. For readers of the blog, and people that are watching my tutorial series on Flash Physics, the next two movies (Box2D and Nape) in the series will be out just as soon as I get some good recording software and a mic for my new Mac.

I will be covering the creation of joints, and the various different joint types and what you would use each type for. I also have a special video that I want to record to show you all a little something that I've been working on, and hopefully include a few of you in too!

Thanks for everything guys, if you have any questions, feel free to ask me!