Monday, 15 April 2013

Zigbit Breakout Board

A hardware project this time, from the start of this year. I was wanting to experiment with Atmel's Zigbit modules (with both Zigbee and Atmel's own Lightweight Mesh) but couldn't find a suitable breakout board/DIP adapter. A few clicks later in Cadsoft's EAGLE I had a schematic, letting the auto-router take care of the layout (for which the choice was size-driven, by both the width of the DIP package and cost of the PCB production). The datasheet has recommendations that weren't possible to fit into such a small package size, although the metallisation rules were followed.

The board was my first experience with OSH Park (and I've since used them another twice and no doubt will use them again). Turnaround was reasonable, taking around three weeks, most of that due to shipping from the US (quicker than Seeed Studio, for example, albeit more expensive). The quality of the boards, especially for the price, is impressive, the silkscreen being the only part I wasn't 100% happy with (on all three runs I had).

The Zigbit module was roughly soldered pin-by-pin, then drag-soldered to finish it; solder paste and hot air would have been easier. A few passives sit underneath (all SMT) and pin headers complete the design. The JTAG connector can either be used for programming or as a breakout for the remaining pins.

For anyone interested in building their own, the gerbers can be sent as-is to OSH Park (link to order directly) or anywhere else with compatible design rules, or the schematic and layout can be used and altered as needed.

Tuesday, 22 June 2010

Accessing Joysticks from JavaScript

Many years ago I wrote a simple browser plug-in to access game controllers from JavaScript. It was Windows only, worked in IE and Netscape 4, and it was used by quite a few JavaScript games at the time (with thousands downloads per day at its peak in 2001, mostly thanks to Scott Porter's JavaScript games). Years passed and it remained largely forgotten, with a few folks still finding it useful for robotics and other specialised cases, but no longer for games. Last year I found myself interested in the project again and decided to update the code, developing versions for Firefox on Windows and Safari on OS X, with the source to all now available under an LGPL license on Google Code (along with prebuilt installers).

Examples of using it from JavaScript, Flash and Java can be found in the project's examples folder; they're quite simple and documented, but in brief, to use it from JavaScript add joystick.js to your page:

<script type="text/javascript" src="joystick.js"></script>

Then create a new Joystick instance, which takes care of inserting the correct type of plug-in into the browser (ActiveX control for IE, NPAPI plug-in for everything else):

var joy = new Joystick();

That's about it! Using it in your game is a matter of reading the controller's axes and buttons wherever you would normally read the keys:

var joyX = joy.getX();
var joyY = joy.getY();

Using it from Flash is slightly more complicated due to having to access plug-ins via ExternalInterface, but the ActionScript Joystick class hides most of that away. Accessing it from a Java applet uses LiveConnect, but again the sample code takes care of this.

So, what are you waiting for? Bring on the games!

Wednesday, 7 January 2009

Opposite Lock Updated Downloads

Following on from last year's release of Opposite Lock under a GPL license, the full game is available to download from the project's site. The files are the 1.3.4 release from June 2007 (the last commercial release) and are optimised versions of what's available in the repository.

Use the cursor keys and space to play in the above applet (you can also select menus using the mouse). The applet is the J2ME code running using a thin MIDP2.0 wrapper written (originally) to test the game's AI.

Wednesday, 30 April 2008

J2ME Director Player

No code this time round, just a quick «look what I done!» This started life as a cut scene player for a (still unreleased) cutesy puzzle game, which was then recycled for the animations in Football Manager Quiz. It uses similar techniques to the mode 7 renderer (posted a while ago) in order to draw the real-time transforms. Animations are exported from Director, reduced to a compact binary form, then played back in pure Java on the phone. The video shows a (rather aged) K750 and a (slightly newer) K800 in action.

Friday, 4 January 2008

Opposite Lock GPLed

Something a little more substantial than a snippet for this latest instalment... an entire mobile Java game! Opposite Lock's source code is now available on Google Code under a GPL license. Check the sources out of SVN (the 'jsr' trunk is the only active one for now) and it should build as-is with Eclipse and EclipseME. Go on! What are you waiting for?!

Okay, where's the catch? Well, whilst the Java source is exactly the same as the published version, I've only included three of the 10 tracks (as per the free demo version). That's the only difference. When the game sales finally peter out I'll release the art assets under a Creative Commons license and commit the missing tracks to the repository.

So, now you have the source how do you create your own tracks? For that you'll need the editor and build tools, available from the project's download page. I'll be cleaning up and adding the source for these to the repository in good time.

I wrote this between 2004/5, originally released as Jet Set Racing (which will explain why the letters 'jsr' appear everywhere). Opposite Lock is a reworking of this earlier game engine with new graphics (and new code to handle the expanded tracks). The tools are all pure Java and run happily on Windows and Mac OS.

Thursday, 27 September 2007

J2ME Mode 7 Floor Renderer

Following on from yesterday's fixed point maths routines, here's a little demo which builds on that. It's another oldie, again from around 2002/3, which I've used in a more advanced form on quite a few projects. It's a very simple texture mapper, visually in the style of the SNES's famed mode 7. Given a 2D map, it presents the image as a horizontal texture mapped surface. It's primitive stuff but can be used to quite nice effect, and with it being entirely software based it doesn't require any additional APIs on the phone.

Grab the source and take a look at Most of the work is done in renderFloor(), which simply works out a pixel offset for each scanline and fills the buffer accordingly. I've taken out some of the optimisations so it's easier to read, but even still it's no slouch!

Wednesday, 26 September 2007

Java Fixed Point Maths

One of the first things I wrote when I started J2ME was a set of fixed point maths routines. I've seen quite a few others over the years, for Java and other languages, and they all seemed to follow the same pattern: sin and cos tables, plus a few methods for basic operations (multiply and divide, usually). The one I offer here, which in various guises and languages has served me well since forever, is a little more advanced (not much, but enough for most mobile games and applications).

The sin and cos (and by extension tan) routines are still table based, but instead of providing the table in-line with the code, it's generated using recursive synthesis at runtime. The advantage here is that the class can be quickly tailored for less or more fixed point precision, depending on the use (16.16 for general usage, 12.20 for audio work, etc.). There's also a fast atan, which was most useful for the physics and AI in Jet Set Racing (seen here, and Opposite Lock, seen here), plus a few other bits and bobs.

Most of the algorithms I devised myself, unless otherwise noted in the comments. The precision is pretty good (I have a test suite for it somewhere) but don't go taking my word for it, find out for yourself!