Showing posts with label Game Development. Show all posts
Showing posts with label Game Development. Show all posts

Monday, 25 February 2013

Animated Mario sprite with game{closure} + coffeescript

Just a quick one; an animated sprite in game{closure} using coffee script:

image directory structure:
├── resources
│   └── images
│       └── mario
│           ├── mario-run-0001.png
│           ├── mario-run-0002.png
│           └── mario-run-0003.png

Sunday, 17 February 2013

More coffeescript + game{clojure} ...

Today I ported game{closure}'s animated trail example to coffeescript.

For anyone wondering, the work flow I'm using is:

Create a new game project:
$ cd ~/devkit/projects/
$ basil init <game-name>


Create a coffeescript directory:
$ mkdir ~/devkit/projects/<game-name>/coffee

Watch and auto-compile coffeescript to js and copy to the projects /src directory
$ cd ~/devkit/projects/<game-name>/coffee 
$ coffee --watch --compile --output ../src/ .

Run sdk web frontend
$ basil serve

Start hacking at your application.
$ emacs ~/devkit/projects/<game-name>/coffee/Application.coffee

And here is the code:

Saturday, 16 February 2013

GameClosure & CoffeeScript

Yesterday a colleague pointed me a very interesting game engine called GameClosure that can compile Javascript and HTML down to native code for mobile devices.



Never wanting to touch Javascript after having discovered the wonders of CoffeeScript I took a quick look at how to get a hello-world example working with CoffeeScript & GameClojure... here's the code:

A couple of points of note here are:
  • exports is backtick-escaped so as to render directly to javascript as the engine requires exports to have global scope.
  • CoffeeScript's implementation of inheritance replaces GameClosures 'Class(<super class>, func...' inheritance helper function (and is much nicer IMO) as seen in their javascript implementation of hello-world

Hopefully it's this easy with, non-trivial, GameClosure applications.

Sunday, 20 January 2013

Haxe & HaxePunk

I've had a lot of fun looking into cool stuff this new year and having made a move into the gaming industry; with my first job based around the development of a small, tablet based, casual game I've been looking into multi-platform, 2D, off the shelf, games engines.

I came across a project called Haxe (pronounced: Hex) that uses a language which is a derivative of ActionScript3 that compiles to native code for Android, IOS, Blackberry, Windows, Linux and Mac as well as Flash or HTML5 + Javascript... Which is pretty awesome in my opinion.
http://haxe.org/ 

HaxePunk is a Haxe port of the FlashPunk game engine which is extremely handy as it means there is a wealth of resources and tutorials on developing games with it.
Haxe Punk: http://haxepunk.com/
FlashPunk learning resources: http://flashpunk.net/learn/

I ran into a couple of problems while setting up my environment on OSX so I'll cover installing Haxe plus a couple of the problems I had here:

#1 Download Haxe here: http://haxe.org/download.

#2 Run these from the command prompt (you may need to sudo these, depending on your setup):

haxelib install jeash
haxelib install actuate
haxelib install nme
haxelib run nme setup
haxelib run nme setup android

#3 The last line will start up the android SDK installer, but the one it downloads will need upgrading. After the auto update remember to reopen the android SDK installer and select the version 8 API then download and install before continuing on with the setup script.

#4 The Haxe language bindings for MonoDevelop 3.0 didn't show up for me in:
MonoDevelop > Add-ins > Gallery
So I downloaded them manually from: http://addins.monodevelop.com/Beta/Mac/3.0/MonoDevelop.HaxeBinding-0.4.0.mpack

#5 When targeting IOS in MonoDevelop the IDE just hung. So I tried from the command prompt with:
$ sudo haxelib run nme test "project.nmml" ios  -simulator
From the directory containing my project.nmml.
This provided me with a meaningful error about the compiler not being able to find clang++ this, I think, was due to me having XCode 4.2 intalled .
Make a note of the directory it was looking for clang++ in then run:
$ which clang++ to find out where clang++ is on your system (/usr/bin/clang++ on my system) and symlink it to the directory that you made note of earlier.
Rerun: $ sudo haxelib run nme test "project.nmml" ios  -simulator
If it works then you should be ok to target iOS from MonoDevelop again, without it hanging this time.

#6 If you're having performance problems with HaxePunk on Android check out this Stackoverflow post

Wednesday, 25 August 2010

A* With F#

First of all please accept my apologies if you find this post and my last one rather scant on details and description.
I'm mega-busy at the moment, I'll pop back soon and try to flesh some of these posts out with detailed descriptions.

I've updated my path finding to use a generic version of the A* algorithm. This slows it down (~6 milliseconds on my box, in debug mode) but it does make for more reusable code.

My Tools module has become the home of this new algorithm and is as follows



And my Pathfinding module has shed some weight to look like so:



JD

Tuesday, 24 August 2010

F# Pathfinding

I've recently started to have a play around with F# and for my first non-trivial application I'm thinking of implementing a path finding algorithm as seen in games. Seeing as this is a learning exercise I'm going to try and be as "functional" as possible (trying to stay as "pure" as I can with immutable data).

First things first:
We'll need a world to 'path find' our way around. Lets start off with defining some simple utility functions. Below is my Tools module that contains functions to:

  • Square ints to a float 
  • Remove items from lists 
  • Load ints from a file (2D arrays of numbers will serve as our tile maps, collision maps, monster & item locations, etc)

The map:
Ok we still need to describe the world we want to navigate: In our world a 0 represents an open space and a 1 represents an area we can not enter. For example a 4 unit long corridor, running left to right, would look like this:

* Wall 1 1 1 1
* Void 0 0 0 0
* Wall 1 1 1 1

Here is my level module that describes:
  • Map point: an x,y location in our 2D space, plus the value of the tile at that location and a function to calculate distance from another map point
  • Map: a list of map points and a function to get the neighboring tiles of any given tile
Pathfinding: Now comes the fun part. This contains the PathingNode type (that basically wraps a map location with information that the A* path-finding algorithm needs), some utility functions and the path-finding function itself.

Level 1: Now let's create a file to represent our world. Open up a text editor and and create a delimited 2D array of 0's and 1's with a definite path between 2 points. like so:

* 0; 0; 0; 0; 0;
* 0; 0; 0; 1; 0;
* 0; 0; 0; 1; 0;
* 0; 1; 1; 1; 1;
* 0; 0; 0; 0; 0;
* 1; 1; 1; 1; 0;
* 0; 0; 0; 0; 0;
* 1; 0; 1; 1; 1;
* 0; 0; 0; 0; 0;

(I've highlighted my start tile green and end tile red for reference)
...Save this text file some where on your hard drive for later.
The Results:
The code bellow shows the pathfinding in action:

Saturday, 17 July 2010

F# & SDL.NET

Disclaimer:
I'm no F# expert. I've used F# at work before but only in a single project for lexing and parsing a simple domain specific language (and the bulk of that work was carried out by a colleague). So some of this code may stink, feel free to let me know about it :¬)

I got up this morning and thought: I fancy mucking around with some F#, I know I'll make a little game.
After some Googling I was left a little disappointed when I found no good, simple, tutorials. It's been about a year since I've done any F# so I'm as good as a newbie again and needed some hand-holding. Alas that wasn't going to happen.

So my first mission was to get hold of a simple input and graphics API ... Having used SDL some time ago with C++ I went hunting for a .NET wrapper and handily enough found this: link SDL.Net

Set up:
All you need to do (at least on a Windows box with Visual Studio) is download SDL.NET, run the exe, and add a reference via solution explorer.

Code:
Now, as you can see, this code is not a "game". It simply blits a background to the screen, overlays a sprite and moves him around in response to the left and right arrow keys... VERY not-a-game indeed. But it will hopefully give anyone reading this the simple first steps towards using SDL.NET with F#.
The code also uses mutable state so is not as purely functional as I would have liked.