I am really bad at keeping up with blogging. It’s not because absolutely no one reads this stuff. It is because I am lazy. Knowing I am lazy doesn’t help either.

Damn is it hot in my office right now. I think that latte had more than just caffeine in it.

The SMS-Style Text Display

I had to give up on making this look like a text messaging program because Safari an an iPod touch is way too slow at rendering it. I was playing around with rounded corners on standard borders to get a slightly quicker version of this but gave up on it for a while. I did get the web page working well with AJAX which helps the load time quite a bit. I will post more on that when I get back to work on it. Maybe a post just after this one would be appropriate.


I have been experimenting with HTML5. Writing JavaScript for the web is very different from writing C++ for Windows. It’s even more different from writing C++ for cross-platform system-level stuff like I program at my work.

The first thing I learned was that there is this canvas thingy that has been around for a long time that I knew nothing about. I did see it in use on someone’s blog but didn’t know what it was. I’ve been trying to stick with using standard fully-supported web browser features for work so HTML5 is out of the question. For home and for fun, and for writing code that runs on phones, HTML5 is apparently the way to go. It, which is really HTML5, CSS3, and JavaScript canvas support, is going to replace Flash. No plug-ins required and there is going to be a standard for it someday.

It’s funny how those standards end up being “finished” well after everyone is using the technology.



My first experiment involved finding someone else’s cool HTML5 game and modifying it. This all happened by accident. I found Core by Hakim El Hattab and thought that it had some similarity to the game Planetary Defense that ran on my old Atari computer from the early 1980’s. Planetary Defense involved using a satellite in orbit to shoot at incoming bombs. The bombs, and your own shots from the satellite, could hit the planet and erode it away until it is gone. The objective is to last as long as possible. it was fun. The cleverness of it was in using the Atari digital joystick, not analog, to move the targeting cursor. It took a while to move the cursor from one side of the planet to the other and bad decision resulted in the inability to shoot because of the planet being in the way.

It was easy to write the code once I got the hang of the JavaScript language peculiarities. I changed Core  enough that the Planetary Defense game is totally different but the look and feel are similar. I had to add code to create explosions that the incoming bombs can hit. Of course I added the satellite and shooting too. I left in much of the object oriented code and the object handling.


Planetary Defense

Hakim El Hattab did a great job although I question the use of the array splice() function. It might have to move a lot of data in memory often. The particles of the explosions would be the most array splicing intensive objects being handled but the incoming bombs and outgoing missiles are also handled with arrays. I plan on changing this code to use linked lists although I will probably keep the data in arrays and using indexes to link items instead of pointers like I would use in C++. I don’t quite trust JavaScript or any pointer-less language to handle linked lists efficiently.

for( i = 0; i < organisms.length; i++ ) 
    p = organisms[i];


    if( p.dead ) 
        emitParticles( p.position, { x: (p.position.x - player.position.x) * 0.02, y: (p.position.y - player.position.y) * 0.02 }, 5, 5 );
        organisms.splice( i, 1 );
Using Splice() to Remove Items from an Array

Using single letter variables names creates a maintenance headache. Professionals who maintain their own code for many years just don’t do this. It makes searches impossible and also creates code that is not self documenting at all. I left most of the code unmodified but I don’t do this myself.

Linked List Handling in Arrays

I would create a very minimal linked list mechanism using arrays for the Planetary Defense game. Each object in an array would have a "next “pointer” which was an index value for the location in the array of the next object. Each array would be accompanied by a variable that held the index of the first valid item in the list and a variable with an index of the first free/invalid item in the list. Each item would have the index of the one that follows it in the liked list. If there are no items in the valid or invalid lists then the variable for that list would point to –1 or something like that. The list could be traversed by following the links and deletion could happen by keeping track of the previous item index and then changing the “pointers” appropriately. Adding an item would require setting the “next pointer” in the item to point to the first item in the list and then changing the first item index to point to the newly added item.

The Game

The Planetary Defense game as it now stands can be found here.