Category Archives: JavaScript Game Design Book

Controlling the Snowspeeder acceleration and turn speed in Hoth Strike

I thought I’d take the time to share my implementation of the Snowspeeder movement in Hoth Strike.

If you’ve played the prototypes of this game you’ll notice that the speeder is restricted to vertical movement. It sits static in the centre of the playfield and everything else moves around it. All sprites in the game have a speed attribute, including the speeder, but it simply ignores it. The player’s control of the speeder directly affects the ground speed (nGroundSpeed). Consequently all sprites react accordingly to the speed of the ground.

The AT-ATs walk at ground speed. Anything other than this would just look awful since the sprites would appear to “slide”. I hate that. The Probes use their speed attribute but it’s generally set to about 2 or 3 pixels. The explosions move North (0) only but like the Probe and AT-AT are directly affected by the ground speed. In short, when the player moves East (2) or West (6) across the terrain the ground speed increases and this is incremented to the other sprite’s x attribute. It’s quite simple to control.

But how do the player ship’s controls work ?

The firing of keyboard events is key.
onkeydown is used to trigger player input and onkeyup is used to cancel any player input.


If the left or right arrow key are pressed and the onkeydown event is fired I consider increasing the ground speed and moving everything in the appropriate direction. But there’s one catch ! The speeder might be moving at full pelt in the opposite direction. What I didn’t want was to snap the speeder to the other direction. It leads to an awful emotional response in the player and to be honest is quite a cheap trick. What I wanted was Defender‘s smooth sliding. To achieve thisĀ  I set an attribute on the player sprite – object.slowingdown.

So when the keyboard fires an event to move the speeder East or West I now check to see whether the speeder is in the process of slowing down. If it is I ignore the keyboard input. The impact on the player is minimal since the slowdown process is fast. In fact slowing down the landscape happens quite rapidly. I literally decrease the nGroundSpeed value by 6 pixels a time. I didn’t want the speeder sliding for miles before the player turned around.
In the game loop I watch for the slowingdown attribute and wait for the ground speed to reach just 1 pixel. Then I open up the controls to the player again. In the mean time I have registered the thrust attributes object.leftthrust / object.rightthrust accordingly.
The game loop flags the end of the slow down and instantly looks for the thrust attributes. If it finds them the speeder is instantly accelerating in the opposite direction.

One final thing to consider is the player opting not to thrust during the slow down. To cover this I set a object.cancelleftthrust / object.cancelrightthrust value so that the thrust code in the main game loop could override the thrust values if necessary when the onkeyup event fires.

I have played with the values quite a bit and in some cases the speeder slides beautifully for about 2 or 3 playfields. As enjoyable as this was from a spectator’s perspective it was hellish for the player. So I did 2 things. I increased the brake power of the speeder and widened the playfield. (It was originally 640 px wide and is now 950px wide). The effect is that the player can thrash it left and right and quickly respond to a probe coming in to view. Very, very satisfying to descend on a group of probes and blast them all to hell !

The Empire Strikes Back’s early sequences had some incredible photography. As a kid I was blown away by the emergence of the AT-AT walkers. I remember thinking that the cinema screen must have been a mile wide such was the nature of the shot. The imperial walker’s were stunning set against the snowy vistas of Hoth. I wanted the same sensation when playing my own game. Hopefully I’ve achieved some of it !

Comments welcome.


Atari memories and a JavaScript games book

Growing up in the late 1970’s early 1980’s I experienced first hand the wonder and amazement of early home computers.
In the beginning I got hold of a ZX81 and pretty much played every available game on it. I still remember being terrified at 3D Monster Maze.
It wasn’t long however before I needed to progress to colour and Christmas 1982 I got a Dragon 32. Wonderous times indeed and the games of Ken Kalish in particular stood out. Danger Ranger has inspired a number of my own game designs and I intend to relive its magic some day in one of my JavaScript arcade ventures. Unlike most I loved the Dragon 32. It had colour and sound and for me that was enough at that time. I’d always felt that the Atari was the way forward but at that point I was content with the Dragon.

Then one magical day some time in 1984(ish) I clapped eyes on Star Raiders. My life changed forever. I grew up with Star Wars and loved it. Everybody my age loved Star Wars. At least the guys did. To actually play at being Han or Luke on your own home computer was quite simply essential for anyone of my age at that time. It took some pestering but thankfully my Dad saw the potential for these machines and also saw that I was starting to program for them as well. Christmas 1984 I unwrapped an Atari 800XL. I’m pretty sure I got no other present that year :)

Galaxians, Pole Position, Star Raiders… they were all there and all utterly fantastic. Atari were synonymous with arcade gaming and I was instantly smitten with them. So much so that I saved up dinner money to buy the magazines of the day that carried program listings. This was to be my way in to programming my own games.

Atari BASIC worked. It wasn’t so clumsy as people though in hindsight and allowed you to generate sound and colourful graphics with reasonable ease. I devoured countless magazines worth of code and before long had my own library of BASIC arcade games running on the Atari. I saved them to cassette and took them to the local computer store to show the store owners who myself and my friends had got to know quite well. The largely favourable comments I recieved urged me on and I soon knew that a life of games programming was for me.

Sadly education, girls, work and all other stuff got in the way and my Atari gathered dust before finally being “given away” by my Mum. By the time that happened I really didn’t care so much such were the demands of my life at the time.

Zoom forward 10 years and in to the internet boom of the 1990’s and I started dabbling with web page creation. HTML was criminally easy and JavaScript allowed for a certain amount of flexibility. Several iterations later and now with full DOM support writing JavaScript to power screen sprites becomes super simple.

The other night I was putting some work in to a simple JavaScript shoot ’em up when it dawned on me that I was experiencing the exact same thrills I’d experienced as a young teenager making those Atari BASIC games. I had managed to rekindle my enthusiasm. There was no marketing or project management stopping me from expressing myself with my code, I was happily making my own game. It was all my own doing and I was loving it. If I wanted green missiles and a slightly faster scroll speed then I could do that and nobody would stand in my way. If I wanted a squelch sound for an explosion or a puff of smoke when the bombs hit the desert below then I could code that and it would stay in. Nobody was going to tell me to take this stuff out.

This personal expression is important to me and right then I considered the fact that it might just be valuable to thousands of other like-minded game designers out there.

JavaScript, the DOM, computer power and web browsers are at such a wonderful stage just now that I feel the time is right to spread the word.

I had been sketching out an idea for a book called “Writing JavaScript Arcade Games” for a little while but this sudden rennaissance gave it some gusto. I am happy to report that the book is 100% sketched out and I am about 50% through writing it.
The book covers everything. I explain JavaScript and the DOM for beginners and go right in to detail about advanced sprite design techniques (I used to work in Acclaim Entertainment’s art department as Lead Artist), animation and collision detection for the more adventurous.

I’m currently looking for a publisher willing to take a chance on it just now. If you’re a publisher and like the idea of a book that taps in to the huge combined market of web designers and arcade game enthusiasts then please drop me a line.