Using BitmapData.threshold()

Since one of my objectives is to be able to publish this yet unnamed game to the web, one of my main concerns is keeping the total download size low, relying on as little static art as possible.

One cool thing I’ve always wanted to try out is palette swapping: basically you take the same bitmap and you replace color values to change the way it looks. Most widely known for its ability to recycle¬†the same beat’em up enemy in several levels by changing pixel colors without requiring a whole new bitmap being stored on the ROM.

In my case, I use it for far more utilitarian goals: to signal player ownership of a given vehicle.

Thanks to openFl’s near perfect port of the flash API, BitmapData.threshold() is available. You give that method a source bitmap, a threshold color, a replacement color and an operation (==, <=, etc) and all pixels that match the condition will see their color set to the replacement color.

I added the color swap method right into my asset manager class:

 public function getColoredTank(p_color1:UInt, p_color2:UInt):BitmapData
 {
 var coloredTank:BitmapData = baseTank.clone();

 //apply first color, replacing Magenta (0xFFFF00FF)
 coloredTank.threshold(coloredTank, coloredTank.rect, coloredTank.rect.topLeft, "==", 0xFFFF00FF, p_color1);

 //apply second color, replacing Yellow (0xFFFFFF00)
 coloredTank.threshold(coloredTank, coloredTank.rect, coloredTank.rect.topLeft, "==", 0xFFFFFF00, p_color2);

 return coloredTank;
 }

This allows me to turn this:

TEST

Into these:

Workspace 1_004

Both tanks in the bottom image share the same source bitmap.

Since I’ve had some fun playing with this, I decided to see about allowing players to set their own color preferences for their vehicles, which might be a nice touch in multiplayer.

About awe6

For this project, I decided to use awe6 as an underlying framework to the game.

It’s a mashup of many different design patterns I was unfamiliar with when I began, and it served as a very good excuse to learn about that.

Other than that, it makes almost 0 assumptions about what your game looks like. Theoretically, it could even be used for 2d and 3d games, but I have yet not found a concrete example of the latter on the web. Who needs 3d anyways, right?

I looked at haxeflixel and haxepunk, but those frameworks are heavily slanted towards making arcade-y games. If you choose another path, you will have all that leftover code lying around doing nothing.

Yes, I’ve had to reinvent the wheel with awe6 a couple of times (I’m looking at YOU, drag&drop!), with the benefit of having learnt something about wheels along the way.

Anyways, I can already predict there will be a point in the future where I will curse myself for going with that framework for X or Y reasons. The most important thing for me to remember when I hit that rough patch is not to give up so easily!

Devlog: Droitwich

Droitwich (n)
A street dance. The two partners approach from opposite directions and try politely to get out of each other’s way. They step to the left, step to the right, apologize, step to the left again, bump into each other, and repeat as often as unnecessary.

Back at the 2010 GDC, I had the chance of attending Jason Rohrer’s presentation of his DS game, Diamond Trust of London, where he exposed upon his view of Knowledge Chains and how they might create interesting gameplay.

Right off the bat I had one big idea related to that, which I may pursue in the future. What motivates me at the moment is an offshoot game of that initial concept, related to the Droitwich definition reproduced above.

In a nutshell, what I’ve set out building is a simultaneous turn based game where you can see which actions your opponent can play (and viceversa), but do not know their order.

From what the paper prototypes I’ve tested with my relatives seem to imply, this might be one of those cases where adding information actually makes decisions harder, not easier, because the player becomes entangled in the “If I do this then he’ll do that but then I’ll do this and he’ll do that and…” loop.

I’m programming the client in Haxe, using the awe6 and OpenFL libraries. While the game will require a basic server to be coded before i can think of releasing a demo, that’s still a long way down the road. After all, I’m programming this in my spare time after the kids have gone to sleep, so it’s not like I’m on a schedule or anything.

Also this is the first time I try to keep a devlog of one of my personal projects. My goal is to just log my daily progress, no matter how slow :)