22 December 2009

Meme Cloud Special: Misfits of Science

I was born in the tail end of the 80's, so I missed experiencing most of them firsthand. However, through the magic of reruns and VHS, my childhood could still benefit from large doses of 80's TV, movies, cartoons, and music videos. I've come out the other side with an undying love for all things that capture that glittering 80's style.

Indiana Jones, Die Hard, Duck Tales, NES games, Phantasy Star, Men Without Hats, MacGyver, Infosoc - the whole decade was made out of awesome (which, in case you've ever wondered what unprocessed awesome looks like as it occurs in nature, it looks a lot like this).

But there is one 80's TV series in particular that I wish to discuss here - "Misfits of Science". I've just spent the last couple of months working with fellow 80's nut, ThirdBass, constructing a fansite dedicated to the show, Science of Misfits. I must hasten to add that I merely tidied up the HTML and offered a few suggestions - the brilliant retro design, content, and hours of research were Bass's hard work.

I love so many things about the show: the rocking music selections; the humour, which is often content to slip by in the background or in expertly written cross-wise conversations; the comraderie of the characters, and the coolness of their superpowers; the fact that the show remains about the characters, and not about their superpowers; and of course, Johnny B, whose red guitar, super speed, signature colour blue, and wariness of water bear a passing resemblance to another one of my favourite characters. ;P

I could go on about the show itself, but you don't need to hear my trap flapping. Bolt on down to Science of Misfits and check it out for yourself - and if it doesn't put a smile on your face, you have a cold, cold, blackened heart.

13 December 2009

Sonic Extractor 3&K Mix Update Alert!

Just a minor update to Sonic Extractor 3&K Mix, to version 1.2. It now has the ability to view the original Sonic 3 alone object layouts.

Sonic 3 and Sonic & Knuckles were originally intended to be one epic 32 megabit cartridge (according to Yuji Naka), but the game was split in half, and the first few levels were released early as Sonic 3.

By the time Sonic & Knuckles was released, Sonic Team felt like making a few changes to the zone layouts. When Sonic & Knuckles is locked on to Sonic 3, the 6 zones from Sonic 3 are tweaked a bit - sometimes for general ease of play, other times specifically for Knuckles and his new abilities.

Unfortunately, the object layout data for these two games, locked together or not, is read directly from the ROM, not the RAM. Therefore, Sonic Extractor, which uses savestates to map the zones, has to already know the object layout data. It's built in to the programme, and can't be changed.

This was a problem, though, when trying to map Sonic 3 alone levels with the unrevised object layouts. No matter what state you used, Sonic Extractor would blithely fill the level using the modified Sonic & Knuckles object data!

Version 1.2 corrects this problem. The user is now given a choice which version of the zone to view. Now anyone with a taste for minutiae can export both versions of each zone, and get a comprehensive comparison of the changes for the first time!

08 December 2009

Code of the Ninja: Sinusoidal Motion

If you haven't already, read the Code of the Ninja: Introduction

Welcome, Code Ninjas!

This time we'll be looking at a simple script that makes certain motions look more natural.

Imagine you have a platform that you'd like to move back and forth, a common element in platformer games. You might use code something like this:

Create Event:

r = 64;//maximum distance in pixels the platform may travel from its origin before reversing direction

s = 1/32;//speed of the platforms. The divisor is how many steps you wish the platform to take to reach its maximum distance from its origin.

Step Event:

if a //moving forward...
  {
  p += s;
  if p >= 1 { p = 1; a = 0; }
  }
else //...and moving back
  {
  p -= s;
  if p <= 0 { p = 0; a = 1; }
  }

x = xstart + r*p;//update platform's position
xspeed = x-xprevious;//get platform's speed in pixels

(Note: If this code seems a little overcomplicated, it is because it had been purposefully written to be able to make platforms of any speed and range.)

This effect that this code achieves is a platform that moves away from its starting point at the specified speed, reaches its maximum distance, and then immediately reverses direction and trots back to repeat the process indefinitely. This is the sort of platform you'll often see in early 8- and 16-bit games.

The trouble with this kind of motion is the immediate reversal of motion. In one step, the platform can be moving with a speed of +5 pixels, and the in the next, with a speed of -5 pixels. This doesn't look very realistic, because in reality, most often when something reverses direction, it has to slow down to a halt, and then begin to accelerate again.

This jerky motion isn't so bad if the platform's "patrol area" is bounded by walls at its extremes - then it just looks like the platform is bouncing off of the walls, and the motion doesn't look too bad. But if the platform is floating in mid-air, as they often are, there is nothing that appears to plausibly reverse it, and the motion looks unnatural.

And it's worse than just looking unpleasant. It actually makes the game less fair, and less fun. If the player can't tell by some visual cue when the platform is going to decide to turn around, they have a much harder time getting the proper timing on their jump. They will have to use more trial and error, watching the platform make its rounds more than once before they can confidently make their move.

This is almost game-breaking if you want to keep good flow, as in a Sonic game. In the Sonic the Hedgehog games for the Mega Drive (Genesis), almost all platforms not bounded by walls move with a natural motion - decelerating as they reach their extremes, and accelerating toward their point of origin as they turn back around. This allows players to intuit exactly where the platform will be any time when they first come across it, without patient study of its entire cycle. This is one of the subtler points about the Sonic the Hedgehog game, seldom recognised, but it contributes not insignificantly to the sense of speed that made them popular.

Well then, how can we achieve the same effect so that our platforms move with a natural motion, rather than an outdated, unrealistic, and unfair jerky one? Why, with the trusty cosine function, of course!

Imagine, now, a platform that - instead of moving simply up and down, or left and right - moves in a complete circle, as many do in Sonic and Mario games. The platform's speed should be uniform, but if we were to look at just one component of its velocity - say, just the xspeed, or just the yspeed - we would notice acceleration and retardation of its speed. Simply imagine looking at the platform's circular path edge on, instead of face on. It would appear to be moving in a straight line, but slowing down at the edges and speeding up in the middle, just like those Sonic platforms we want to emulate.

So, in effect, what we want to do is make the platform move in a circle - just a really flat circle that might as well be a line. We'd use code something like this:

Create Event:

r = 64;//maximum distance in pixels the platform may travel from its origin before reversing direction (radius of the circle)

s = 180/32;//speed of the platforms. The divisor is how many steps you wish the platform to take to reach its maximum distance from its origin. (This time we use 180, not 1, because we'll be using degrees.)

Step Event:

a += s;
if a >= 360 a -= 360;
//alternatively the preceding two lines could be 'a = (a+s) mod 360;'.

//also, here we don't need to use two states, forward and back, because the circular motion takes care of that for us automatically.

x = xstart + r*cos(degtorad(a));//update platform's position
xspeed = x-xprevious;//get platform's speed in pixels

To make the platform move vertically, we can just replace all the references to x and make them y. Or, to make it actually move in a perceptible circle, we can have both sets of lines. By using a different range value for both x and y, you can squash the circle into any sort of ellipse you want - for example, a circle that is twice as wide as it is tall:

Create Event:

xr = 64;
yr = 32;

Step Event:

//...

x = xstart + xr*cos(degtorad(a)); xspeed = x-xprevious;
y = ystart - yr*sin(degtorad(a)); yspeed = y-yprevious;

Remember to subtract the sine for y, and add the cosine for x, otherwise instead of moving circularly, it'll just move in a smooth diagonal - which is actually another useful effect you might want to achieve.

Well, that about does it for platforms, but the power of sinusoidal motion goes far beyond. There are other applications, and for just such an example, I'll use the purpose for which I first I needed it myself.

In games like Phantasy Star, when you talk to townsfolk or shopkeepers, their dialogue appears on the screen inside of bordered window, or a 'text box'. In most games, the text boxes appear on the screen gradually, either opening up, dropping down, or fading in.

I wanted this animation to appear smoother, so I thought perhaps I could apply sinusoidal motion as the solution. But there was a slight hitch.

Imagine you want to fade in a window, from an alpha of 0 (invisible) to an alpha of 1 (fully opaque). You could simply add 0.1 for ten steps, but that wouldn't look very smooth. How about, instead, we use a sine function.

Code:

step = 18;

for {a=0;a<=180;a+=step}
  {
  alpha = sin(degtorad(a));
  }

Well, clearly this won't work. The value of alpha will go from 0 (the sine of angle 0), accelerate toward 1 (the sine of angle 90) and decelerate back to 0 again (the sine of angle 180). The text box wouldn't fade in, it would fade in and back out again just as quickly! This obviously isn't what we want.

But why not just use 90, instead of 180, so that alpha will stop at 1, thereby fading the text box in how we want it? Well, in that case, the fade would start smoothly, but stop abruptly. I wanted it to both start and stop smoothly.

I needed some way to have the alpha value "move" like a half-circle (slow start and stop), but only "traverse" a quarter-circle (start at 0 and end at 1).

So I made a script, called it 'sinusoidal()', and this is the function I used:

sinusoidal()

//argument0: any value between 0 and 1

return (cos(degtorad(180-(180*argument0)))+1)/2;

Now, sinusoidal motion can be employed anywhere by calling the script. The text box fade code ends up looking something like this:

Code:

step = 0.1;

for {a=0;a<=1;a+=step}
  {
  alpha = sinusoidal(a);
  }

This little script can be very versatile. You can use it to slide logos or menus onto the screen. You could use for flashing lights for smoother look. You could use it to animate a pendulum. You could even use it to make your character push a block (as Link does in the Zelda games) with a less abrupt and better looking motion. And with clever modification, who knows to what ends a Code Ninja might put it to.

For an example GMK illustrating the difference between normal and sinusoidal motion in several types of movement and animation (flashing, shrinking, swinging, sliding), click here.

Next time we'll be looking deeper into text boxes - how to make the text type out, change the text speed, and more. Until then, happy coding, Code Ninjas, and happy holidays, too!

If you use my code or scripts in your game or engine, no credit is necessary. But I'd love to hear about your project if you do! Just drop me a comment below, or e-mail me at us.mercurysilver@gmail.com

16 November 2009

Hedgehog-Headed?

One of my favourite subjects is etymology. I was reading the dictionary recently, and came across a little tidbit that caught my fancy, and I thought I'd share it.

caprice

n
1. impulsive tendency: a tendency to sudden impulsive decisions or changes of mind
2. sudden change or action: a sudden unexpected action or change of mind
3. whim: a sudden idea, impulsive decision, or change of mind

Well, it's not too far a stretch to describe Sonic the Hedgehog, especially as the modern Sega portrays him, to on occasion be taken by caprice. So I was amused to read the etymology:

[Mid-17th century. Via French from Italian capriccio, literally "head with hair standing on end," from capo "head" (from Latin caput) and riccio "hedgehog" (from Latin (h)ericius)...]

Encarta ® World English Dictionary © & (P) 1998-2004 Microsoft Corporation. All rights reserved.

So, someone who is capricious is literally "hedgehog headed". It's a funny language we speak!

14 November 2009

Game Review: Sonic Boom

There's a new hack on the Sonic scene - Sonic Boom. It's been three years in the making, the brainchild of snkenjoi and iojnekns, with music by Tweaker and a host of others. It's not finished - it's only a single zone demo, but it's a big release for the community and deserves a full review.

The first thing I did after firing it up was to check out the Sound Test. I was met by a bevy of expertedly ported songs, mostly from the Megaman X Series, and a kickass (if a little wandering) original composition by Tweaker. The best of all, though, has to be the 16-bit versions of the "Sonic Boom" vocal tracks from the North American Sonic CD sountrack. Both the intro and outro versions are included, and they simply shine.

Then I returned to the intro to check out the game itself. I have to lodge a minor complaint here about the two options on the intro screen, though. Since there are only two, there is no way to tell which is highlighted and which is not - like all those bad DVD menus we have to struggle with. I would have assumed the lighter colour to be the selected item, but it wasn't. Furthermore, since the game remembers where you left the "cursor", and I wasn't expecting this, I went straight back to the Sound Test by accident when trying to start the game. I'll let this slide, though, since the finished version will most likely have more than two options here.

Now for the game - or rather, the zone: Power Plant Zone.

First, the art:

I have to be honest here and say that I'm disappointed by the visuals. The foreground art is nice enough, and so is the background art - but together they create a colour scheme I'm not sure works at all. It's generally not a good idea to have all three primary colours in the same scheme, and the addition of both bright whites and dark greys doesn't help matters.

Sonic's sprites are slightly better, but I have a few beefs with them, as well. For one, I think he's too dark, especially for the dark background of the zone. Also, I've never been a fan of the green eyes. On the more technical side of things: because he faces away from you when he takes damage, and he remains facing straight ahead (instead of looking at you) when he enters his waiting animation, he loses some of the expressiveness, and therefore appeal, that the original Sonic had. A distant, uninterested looking Sonic with low contrast in the eyes and face can throw a pall over the whole thing, breaking your connection with the character on the screen, and thereby your engagement in the game. This is why I've always preferred the Sonic 1/CD style sprites to the Sonic 3&K ones. I'm not advocating replacing Sonic Boom's sprites with Sonic 1's - I like the fact that they're different - but I do think that he needs to be a little more expressive and attitudinous. Also, the raised arms in the springing animation look retarded, but that rounds out my criticisms for the sprites. To end on a positive note, I like the way the kicking animations look, and the combination of Advance style sprites with the classic set is clever and rather seamlessly executed.

The bosses look absolutely fantastic, though. The shading is very well done, but of course they're perfectly round, so we'll just have to wait and see if later, more complex bosses come out as nice.

And now, the gameplay:

One of the first things to be learned about Sonic Boom is that there are new moves for Sonic to perform. And unlike a lot of hacks, you'll be needing - and in fact, wanting - to use them.

The Super Peel Out and Spindash have been included, which is pretty standard, but also pretty nice, and Sonic now has a double jump (much like the Electric Shield affords him in Sonic 3&K, only it takes him higher).

Then there is a class of moves that require Rings to perform. Sonic can shoot straight downward by pressing Down after jumping, which costs one Ring. This is a cool move, related to the Bounce from Sonic Advance 2 and Sonic Adventure 2, only without the rebound at the end. I like it, but I'm annoyed that it only takes a press of the D-pad. This causes it to happen accidentally, which is never good when trying to clear a pit of spikes. I would like it a lot more if you had to hold down and press A, B, or C.

Rounding out the Ring consuming moves are two types of Air Kick. One sends Sonic flying horizontally, costing 5 Rings, and dealing damage to enemies. The other is much like the first, only it sends Sonic diagonally towards the floor, and costs but 2 Rings. The great thing about this downward kick is that Sonic hits the ground running at close to top speed. It is a much more satisfying way of gaining speed than the Spindash or Super Peel Out, as long as you can spare the Rings.

Incidentally, I had envisioned a downward kick as a way to gain speed long ago, so I'm happy to see someone finally using a similar idea. I had come up with it because of Sonic Chaos. In Sonic Chaos, Sonic can do the Strike Dash (which is much like the Super Peel Out, only he is briefly invulnerable as he launches). Tails can Fly, but in order to make Sonic and Tails have similar controls, he must now hold Up and press the button to do so. This sucks (mainly because he can only start to fly from a standstill), but the idea of making Sonic and Tails perform their iconic abilities in the same way was intriguing. In Sonic 3&K, both Tails and Knuckles do their special abilities by jumping and pressing the button a second time. Sega had to give Sonic a comparable ability, and introduced the Insta-Shield. Now, some people don't give a fig for the Insta-Shield (I like it though), and one might want Sonic to have a more speed-oriented ability anyway. So I thought the Super Peel Out could be redesigned as an aerial ability, like Tails' and Knuckles', and that led to the speed-gathering dropkick idea.

Anyway, the move works very well and makes the game fun to play. Which brings me to the level layout. The layout is a strong point. It reminds me of the best speed levels from Sonic 2 and 3&K, like Chemical Plant or Flying Battery, and I suppose that's high enough praise.

They're just long enough, and don't drag, and you don't get lost. They also have to have the best sense of speed I've ever encountered in a fan game, and very nice loop structures. I'm not sure I'm wild about the "clear the room of badniks" parts, but they aren't nearly as onerous as the ones in Sonic Rush and don't mar the experience.

Well, what about the badniks? I counted four types on my way through, and they're all great. The challenge is higher than the Mega Drive games, but I think that was supposed to be the point. The best part about them is that they encourage the use of the new moves, which helps the game feel coherent, rather than a bag of ideas the developers just want to fit in.

Which brings us to the Bosses. The boss in Act 1 is absolutely brilliant. It too encourages the new moves, is challenging yet beatable, and has damage modelling, which is always cool. The Act 2 Boss, however, has a few technical glitches, and is significantly harder. I probably don't play enough Megaman, and my skills are atrophied, but this is like the Metropolis boss (my personal bugbear), only reimagined by a sadistic Dr Wily on LSD. Don't get me wrong, I like the boss, and am awed by the proficiency of the programming. I do however think that the choice to make Sonic invincible after hitting it (sort of like what happens when Sonic is hit) indicates that it may not be as balanced as it should be.

After defeating the Boss, and "surviving" Act 2, we are treated to a real surprise. Act 3, where Sonic has to high-tail it out of the plant with a wall of onrushing flame hot on his heels (pun intended). Again, my twitch gaming skills - underdeveloped as they are - conspire to let me down, but the concept is awesome.* It may sound strange for me, then, to advocate making it even harder, but I think that the edge of the flame should probably kill Sonic immediately. I suppose there might be some perspective or parallax going on, but it seems weird to be halfway into a wall of flame before you finally decide to die.

* It reminds me of Dino Run, which by coincidence I had played mere days before Sonic Boom. I'm not pointing fingers (after all, I think good ideas should be reused), but I am curious for curiousity's sake if inspiration was drawn from Dino Run, or perhaps they both share a common memetic ancestor.

Upon completion of Act 3 are credits (set to the aforementioned 16-bit remix of Sonic Boom) with a welcome "Cast of Characters" scroll showcasing the enemies, in the tradition of Kirby, Mario World, and Mean Bean Machine.

Overall, Sonic Boom is fun, sounds great, and is a technical juggernaut. With some spit and polish on the visuals, it could carve its way into the pantheon of Sonic Hackdom. I eagerly await the next demo. Good work guys, and ganbatte!

13 November 2009

Code of the Ninja: Watchers

If you haven't already, read the Code of the Ninja: Introduction

Welcome, Code Ninjas!

Today I have a simple fix for something that bugged me about Game Maker. First, let me tell you about the problem, and then I will move on to the solution.

Many times I would be running my game, and realise that there was some variable I needed to know the value of. Game Maker allows you to list the values of variables that you specify in a readout, but only when running in Debug Mode.

The trouble is, once you are already running your game, there is no way to dynamically switch to Debug Mode. You have to close the game, and run it again. This is kind of an annoyance, because compile time can get quite lengthy.

So, I thought, is there any way to have a list of "watchers" built into the game, that I can invoke and dismiss at will?

At first I used a simple method that worked much like any HUD (heads up display) in a video game. The values I needed to keep an eye on were just printed on the screen. This was fine and all, but there was no good way to add to it while the game was running. Game Maker's built in Debug Mode allows you to add watchers at any time.

Then I got the idea to - instead of printing out the values of a fixed set of variables - read the variables from a ds_list.

This ds_list would contain a series of strings, each of which would contain the name of the variable to watch (mouse_x, image_speed, etc). By right-clicking the list, I would bring up an input box that would let me add a new variable name to the ds_list.

How can you read the value of a variable by its name? Game Maker helpfully includes the functions variable_local_get(), and variable_global_get(), which take as their only argument the variable's name in string format, and return the value of the variable.

However, there are still issues with this method. A) You can only return the contents of variables, not expressions. This means you can print out the value of mouse_x and things like that, but never the value of instance_nearest(PlayerObj), and other such useful functions. B) You can't tell whether a variable is global or local, a constant, or part of an array, so you're pretty much screwed.

But then I had the brainwave. Instead of using variable_local_get() and its ilk, I'd use the execute_string() command!

Using this method, the ds_list could be filled with strings containing variable names, expressions, anything - using the identical syntax as the Game Maker Debug Mode watchers use. In fact, I could even save and load the strings to TXT documents in the same format, making them fully compatible with Game Maker's normal Debug Mode.

When drawing the watchers onto the screen, all I have to do is read the strings from the list. Then, I use the execute_string() command to perform the string as if it were code. By prepending "return" and a space before the string when I do this, execute_string() will return the value, which can be then drawn on the screen.

Code will demonstrate this better:

Code:

//a for loop that steps through the whole list
for (t=0;t<ds_list_size(watchlist);t+=1)
  {
  //the code string in the list to be executed
  r = ds_list_find_value(watchlist,t);
  //align the text to the left
  draw_set_halign(fa_left);
  //print the code - this is how you'll identify the watcher
  draw_text(8,8+16*t,r+":");
  //return the result of the watcher
  r = execute_string("return "+r);
  //align the text to the right
  draw_set_halign(fa_right);
  //print the result of the watcher
  draw_text(192,8+16*t,r);
  }

Now we have a watcher display that's just as nice as the Game Maker one. With a little bit of polish, you can add functions for adding, removing, replacing, and editing watchers from the list, as well as saving and loading lists to TXT documents.

For Code Ninjas who may need a working example to make sense of all this, here is a zip file which contains a GMK example and a sample TXT document of watchers.

Happy coding!

If you use my code or scripts in your game or engine, no credit is necessary. But I'd love to hear about your project if you do! Just drop me a comment below, or e-mail me at us.mercurysilver@gmail.com

03 November 2009

Only a Theory?

I began my last post with this sentence:

Sadly, there are those who deny the fact of evolution....

Before I even leave the starting gate, many creationist readers will have already snorted in disgust and stopped reading, merely because of my use of the word "fact", instead of "theory". Why did I not use the word "theory"? To be perfectly honest, I used "fact" because Richard Dawkins does, and I admire his forthrightness. But I had a deeper reason, too - and I think it is the same reason that Dawkins chooses to use "fact" as well (and it's not because we happen to believe in its veracity).

It is because the word "theory" causes unnecessary confusion.

What is a theory?

Many would here quote definitions from major dictionaries, trying to make a point about how "theory" has been watered down with a second connotation. I'm not going to, because others have already done the job admirably. Anyone who doesn't know the distinction between the two meanings has only to spend one or two minutes in the culture of evolution and its deniers to learn it.

Instead, I'm going to point something out that should be obvious, but apparently isn't to some. A theory is manmade. It is similar to a book, a song, or even a religion. It is a group of cohesive ideas, knowledge, and descriptions about a subject. But it is made of language, and doesn't actually exist in the strong sense.

However, theories are usually about things that exist (but not always). The things a theory is about, and the theory itself, are discrete. One should not be confused with the other. This is not an overly subtle point - it's about as obvious as saying that we should not confuse the dark side of the moon*, and the Pink Floyd album, Dark Side of the Moon.

* which, like the night side of the Earth, is not always the same side, unless you take "dark" to mean "unseen until mankind launched probes".

Is evolution a theory?

Well, yes, if you are being colloquial or elliptical. The word "evolution" is popularly used to refer to what should more properly be called the "modern evolutionary synthesis". It is also used to refer to Darwin's theory of natural selection. It is shorthand, though, and whenever one uses a shorthand term, things can get confusing. For instance, if you took "evolution" to mean Lamarck's theory of inheritance of acquired characters, "evolution" would be false. So, I wouldn't strictly call "evolution" a theory, anymore than I would call "light" a theory. There are theories about evolution, and about light, but evolution is a process and light is... well, ask a physicist.

By a quirk of language and history, the theory of evolution has come to be called simply "evolution". This has not happened in other cases, such as with light or gravity. But evolution is a process, which either happens or doesn't, in the real world.

You would never hear someone say, "Evolution isn't a fact! It's a word!" But the "only a theory" argument amounts to about as much. This is why I didn't say "theory". Theories are incomplete, and some, like Lamarck's, are demonstrably false. Even Intelligent Design is a theory of evolution, and I deny it.

Evolution is a fact of history. Those who take advantage of the "theory" canard have either not learnt enough about the subject or are being willfully obscurantist. I like to think the former, because then the problem is remediable.