First, let’s define a bunch of useful functions. We’ll later use these functions to extract the relevant sections of our ID3 tags. I’m going to assume you are using your interpreter directly, so lets copy & paste the following lines straight into your terminal:

Now lets say the current directory is full of MP3s that we would like to move to an appropriate folder and give a more appropriate filename (in my case, I had my corrupt old iPod from which I was attempting to extract all the music I could). The structure I’m aiming for is:

ARTIST – ALBUM / TRACK_NUMBER ARTIST – SONG_NAME

Making use of our functions defined above, this for loop ought to do the trick:

Some very good news for all the MHEG developers out there, the BBC have this week open sourced the MHEG+ toolkit and it can be downloaded over at the MHEG+ SourceForge page.

The release comes with little in the way of tutorials and so it might all seem a little daunting at first. But having used (and worked on) the toolkit for a couple of years I think it is worth the initial effort and recommend you give it a try.

I intend to write a full getting started guide to help new users over on the MHEG+ SourceForge forum, but for now here are some code examples and an ultra-quick guide to getting the toolkit up & running…

This blog also has two examples of MHEG+ code, see these posts #1, #2.

Ultra-quick MHEG+ getting started guide

The toolkit contains a compiler and an emulator. Currently both are available for download as a separate Java .jar files. You will need Java installed to use them.

To use the emulator/debugger, download the file named MhegPlus.MhegPlayer-1.0.1.jar and issue the command:

java -jar MhegPlus.MhegPlayer-1.0.1.jar

This will launch the Mheg Player GUI.

To use the compiler first download the file named MhegPlus.Compiler-1.0.1.jar. The compiler can invoked with the following command, but you will need to pass command-line options to get anything meaningful out of it:

java -jar MhegPlus.Compiler-1.0.1.jar

You can get help on the various compiler options by passing –help, e.g.:

]]>https://purplefloyd.wordpress.com/2010/08/20/bbc-open-sources-mheg-toolkit/feed/23purplefloydWorking on a new HTML5 game engine for iPhonehttps://purplefloyd.wordpress.com/2010/02/24/html5-game-engine-for-iphone/
https://purplefloyd.wordpress.com/2010/02/24/html5-game-engine-for-iphone/#commentsWed, 24 Feb 2010 08:33:41 +0000http://purplefloyd.wordpress.com/?p=471I’ve just completed the first stage of development on a new 2D HTML5 game engine for iPhone.

It is a complete re-write of the engine used in my iPhone platform game and it achieves a much higher and more consistent frame rate. I’m currently very pleased to be getting a consistent 17-18 FPS running full screen on an iPhone 3G.

It is a scrolling tile-based engine, meaning it should suitable for most 2D games. I’d like to use it to create another platformer, or maybe a shoot ’em up this time would be cool, but the engine could be used for other game types too.

I need your help! to turn it into a finished game. This is a call out to any artists who would like to get involved, please drop me an email with examples of your work. My address can be found on the about page.

I intend to release 2 versions of the game:-

a demo version that runs in Mobile Safari but has no sound and few levels, and

a full version that can be purchased from the app store.

Revenues made from the app store version would be shared with the artist, so there might even be a few dollars in it for you!

The game uses the HTML 5 Canvas element and a few iPhone-specific HTML/JS extensions. It should still run on most desktop and mobile web browsers however.

I’ve tested the game on an iPhone 3G and 3Gs. The 3Gs performs as well as a desktop PC which is some feat! The 3G on the other had is a little sluggish, but the game is still playable; if you’re using a 3G I recommend playing the game with your phone upright (portrait) for best performance, since in this mode the game aims to draw to a smaller area of the display.

It is also possible to play the game full screen, that is without the Safari address bar & toolbar, by adding the game to your home screen.

See my earlier post for the history of the game, or to play the desktop version. As before I invite you to take a look at the source code of the game. Simply hit your browser’s “view source” button to read the code.

Click the Play link below (ideally on your iPhone!) and be sure to leave a comment with your thoughts.

Nearly 15 years ago, when I was all of 15 years old, I wrote this little platform game which I have recently ported to HTML5/Javascript.

It’s a kind of Mario clone and at the time I named it “Fred Jones in Adventureland”… hmm, not a great name.

The themes of the game are intended to be tongue-in-cheek however. Hence the ridiculous title and deliberately unsubtle references to other games in the genre.

And it is somewhat incomplete; the player has unlimited lives and unfortunately there are only 5 levels. But as it stands it is playable and hopefully a little bit of fun. There are a couple of surprises along the way too.

Browser Compatibility

If you’re using Microsoft Internet Explorer 7 or 8 the game will run dreadfully slow. (Update: The game now supports the Google Chrome Frame plug-in. If you are using Internet Explorer I recommend you install it.)

Internet Explorer 6 and earlier, Firefox 1.x and I believe Opera 8 and previous will not run the game at all. This is because these older browsers do not support HTML5 (arguably, no version of Internet Explorer supports HTML5, however the game can run with the assistance of 3rd-party plug-ins and other workarounds). Please upgrade or switch to a different browser.

Controls

iPhone Version

Technical Details

This is a port of the original game to HTML5/Javascript. This means it now runs in any modern web browser.

Unlike most web games the game does not use Flash. The HTML5 Canvas is used to draw the visual elements.

All the code for the game is all available to read if you hit “view source” in your browser and I invite you to take a look.

I was pleasantly surprised by the performance of Canvas drawing operations and javascript run-times in most modern browsers. However Internet Explorer users apparently will have to wait for version 10 before such features will grace the browser.

The game currently has no sound but this could be added using the HTML5 <audio> element.

]]>https://purplefloyd.wordpress.com/2009/03/23/my-bbc-red-button-games-blog-post-is-up/feed/8purplefloydI get a mention on the BBCi bloghttps://purplefloyd.wordpress.com/2009/02/23/i-get-a-mention-on-the-bbci-blog/
https://purplefloyd.wordpress.com/2009/02/23/i-get-a-mention-on-the-bbci-blog/#respondMon, 23 Feb 2009 10:37:38 +0000http://purplefloyd.wordpress.com/?p=252Today’s post on the BBCi Labs blog briefly mentions a Pong game I wrote for Freeview/Freesat set-top boxes a while ago. A couple of the guys in the BBCi team took my game and tried to make it multiplayer by passing players’ movements over the internet. I don’t think they were totally sucessful though in getting it to work though…

Also see here for a video of the Pong game (the single player version), it’s the third game shown in the video.

]]>https://purplefloyd.wordpress.com/2009/02/23/i-get-a-mention-on-the-bbci-blog/feed/0purplefloydSigning .deb packageshttps://purplefloyd.wordpress.com/2009/02/05/signing-deb-packages/
https://purplefloyd.wordpress.com/2009/02/05/signing-deb-packages/#commentsThu, 05 Feb 2009 15:00:41 +0000http://purplefloyd.wordpress.com/?p=230Okay, so here’s the scenario: you distribute .deb packages without an apt repository, but want to start signing your packages to ensure they aren’t corrupted or tampered with during transit to your users. I say “without an apt repository” since apt has its own mechanism for signing whole releases, via SecureApt.

The tools you are expected to use for this purpose are debsign and debsig-verify. Unfortunately I found the documentation for these to be pretty thin and ended up having to read the source of debsig-verify to work out what was expected of a signed package.

So hopefully to prevent others from having to trawl through source code, below are steps you could follow to sign your own .deb packages. My method is somewhat contra to the prescribed method from Debian, however it is the only way I’ve managed to get working. Please suggest better methods if you know them.

The steps I performed were:

Create your GPG signing key, run $ gpg --gen-keyand follow the steps.

Sign the .deb with your private key, without using debsign (please comment if you get debsign to work for you, I couldn’t…).

Take an existing .deb and unpack it: $ ar x my_package_1_0_0.deb

Concatenate its contents (the order is important), and output to a temp file:$ cat debian-binary control.tar.gz data.tar.gz > /tmp/combined-contents

Configure a policy for the key, policies are discussed in some detail in /usr/share/doc/debsig-verify. The policy file needs to be kept in /etc/debsig/policies/[key_id]/[policy_name].pol. Mine looks like this:<?xml version="1.0"?>
<!DOCTYPE Policy SYSTEM "http://www.debian.org/debsig/1.0/policy.dtd">
<Policy xmlns="http://www.debian.org/debsig/1.0/">

You should now be able to verify the package using debsig-verify, i.e.:$ debsig-verify my_package_1_0_0.deb
debsig: Verified package from `PurpleFloyd' (Another package from PurpleFloyd)

Et voila! You have signed and verified a debian package.

Note: on most distros, dpkg/apt will not check the signature of a package when installing it, even if a signature is present. This checking can be enabled by removing the --no-debsig line from /etc/dpkg/dpkg.cfg.

]]>https://purplefloyd.wordpress.com/2009/02/05/signing-deb-packages/feed/27purplefloydMHEG+ Game Development Tutorial, Part #2 — Animationhttps://purplefloyd.wordpress.com/2008/12/14/mheg-game-development-tutorial-part-2-animation/
https://purplefloyd.wordpress.com/2008/12/14/mheg-game-development-tutorial-part-2-animation/#commentsSun, 14 Dec 2008 17:41:50 +0000http://purplefloyd.wordpress.com/?p=123In part #1 of this series we built a basic MHEG+ scene which was capable of firing timer events at a consistent rate. In this part we will look to extend the code by adding an animating graphic to the scene.

A further aim of this part is to explain some more of the language features exclusive to MHEG+, including foreach loops, sequential blocks and ifs.

Adding our graphics to the scene

I have hand crafted the following 5 png graphics to use for this tutorial:

Using an MHEG+ foreach loop, we can add all these graphics to our scene in one fell swoop:

There a number of subtleties of this loop which are probably worth discussing:-

foreach loops are preprocessor instructions, not run-time loops. Because of this we can use foreach loops around object declarations, or in fact any code section at all.

In this case, the contents of the foreach loop will be duplicated 5 times, this is controlled by the (0..4) range on the first line. This range need not be numeric, text may also be used, for example: foreach key (red, green, yellow, blue) is allowed.

The Bitmaps we declare will be named bmpPac0 through bmpPac4, <num> is substituted with each value in the range.

The object identifiers for the Bitmaps will be 100 through 104, assuming constPacObjectIdOffset has the value 100. We use the MHEG+ notation: objectname = objectid to declare both names and object identifiers for our Bitmaps.

<num> is also substituted in the png filename

You may also have noticed that our 5 Bitmaps have :InitiallyActive set to false. We will later call :Run and :Stop on our Bitmaps to control which frame of the animation is visible, so they do not need to be running at startup. However we do still want to pre-load our Bitmaps when the scene loads in order to have them prepared in memory and ready to use, so we add the following to lnkStartup:

Here we are using a foreach loop not for ingredient declaration but to duplicate a line of code in a link effect. Again, <num> is substituted appropriately.

Drawing each frame

As in part #1 of this series, we will use the Link lnkGameTick to calculate and render each frame of our game. The first thing we did in lnkGameTick is set the next timer event, this is to ensure our game runs at a fairly consistent pace.

We now extend lnkGameTick to call out to two sequentials. The first sequential “calculates” the next game tick, the second renders it to the screen. We therefore add the following to lnkGameTick:

(Note: Games often separate the concerns of calculating a frame from rendering it. In an environment other than MHEG this could allow us to choose whether to render the current frame (which is normally an expensive operation) to keep the game tick rate consistent. MHEG however without precision timing does not allow us this freedom, but separating along these lines makes our code more maintainable.)

Note that we call :LockScreen and :UnlockScreen around the call to updateScreen. This effectively tells the MHEG engine to render our new frame off-screen and display the changes only when we call unlock. This is akin to Double Buffering and helps reduce screen flicker.

We still need to implement the sequentials calculateNextFrame and updateScreen, which I’ll describe in the next two sections.

Calculating what to display

For each game tick we need to determine what should be visible on the screen. In the case of our animation of the ‘Pac’ character, this means determining which of our 5 Bitmap ingredients should be visible.

So the effect of the calculateNextFrame macro should be to modify an integer variable whose value will later be used to identify the Bitmap to display. We’ll call this integer intNextPacObjectId.

The sequential declaration states which namespace it belongs to. When we call a sequential we use the notation: namespace dot CallActionSlot( sequential ), as we do in lnkGameTick.
In MHEG+ we also must declare the tgPac token group and call :InsertSequentials, see the complete code listing below for example code. An MHEG+ sequential is a façade to an MHEG ActionSlot. Sequentials though can be declared anywhere in the source file and have cleaner syntax.

Did you notice the :If? MHEG+ gives us the syntatic sugar of being able to declare inline If blocks. In classic MHEG our only way of implementing conditional code sections was to use the :TestVariable action and write separate :Links to perform actions based on the evaluation of the test. In fact this is what MHEG+ does behind the scenes, but the abstraction is very handy. We can also write :Else and :ElseIf blocks.

Updating the screen

Now that we have calculated the object Id of the Bitmap to display and stored this in an integer, we need to write a sequential to hide the current Bitmap that is displayed and show the new one.

Only by a call to a resident program can we translate an integer value into a reference to an actual object, the resident program to do this is called CastToObjectReference, or CTO.

We call the prgCastToObjectRef resident program in order to retrieve a handle to an object given its object Id. We pass an integer (which will be in the range 100 to 104) and dynamically gain access to the object with this identifier. This is why we explicitly stated the our Bitmaps’ object Ids when we declared them.

Note that we can’t use object dot action notation when dealing with object references (objPac is an object reference variable), this is a limitation of MHEG+. This we must write :Run(:IndirectRef objPac) and not objPac.Run().

Putting it all together

Hopefully it should be fairly clear by now what the scene does. At the middle of the screen we see the following animation:

Because we have used :LockScreens and tried to keep the work done whilst the screen is locked to a minimum, the animation will be fast and practically flicker free.

Looking at the complete listing (see Resources section below) it would be true to say that MHEG+ is not the cleanest of programming languages. However it is a lot more readable and maintainable than traditional MHEG.

The source listing really boils down to two key sequentials: calculateNextFrame and updateScreen. We would be wise to move each of these sequentials into separate files and develop them somewhat independently of eachother and the rest of the scene. MHEG+ allows us to use import declarations in order to better manage our source code.

Where to from here?

This is a good starting point for a game. Of course there is still plenty to do, including:-

Moving the sprite around the screen

Rotating the sprite when it changes direction

Adding a maze

Adding other objects to the maze

There are also a number of MHEG+ features we have yet to use including macros (both parameterised and not), state machines and imports.

In later posts I hope to explore these themes and also discuss the tools that make up the MHEG+ SDK including the MHEG Player (emulator), MHEG+ compiler and the Eclipse editor plug-in.