Android Tetris Variants

quantroI spent some time today searching for an android Tetris variant I had seen a long while back called Quantro. I couldn’t remember the name, and searching for Tetris in the Google Play store (for this particular app) is an exercise in futility.

Quantro claims to have 4 different game modes, but at least one of them involves what are essentially two games of Tetris played one on top of the other. I’d definitely like to give it a go at some point.

What’s frustrating about Quantro for me is that it’s Android only. The app’s description even includes this text: “Quantro is an Android exclusive tetromino and tetracube game, built from the ground-up for Android phones and tablets. Don’t settle for a poor-quality iOS port!” I’m not sure what we should be reading into this description. Has the app been cloned in iOS? (Quite possibly, but if so, I haven’t seen it.) Are the devs just Android fanboys? (Also quite probable.) I don’t have any android devices, and while I’ve always kinda wanted one just to play with, (and for checking out Android exclusive games like this one!), I haven’t succumbed to that temptation quite yet.

Apparently the Tetris Holding Company isn’t sending cease-and-desist letters to apps on Android the same way it does on iOS (or google is taking a harder stance against that sort of bullying, not sure). But whatever the case, there are tons of tetris clones for Android. Here are some other interesting looking games I stumbled onto while searching for Tetris in the Google Play store:

tower-defense-tetrisTower Defense Tetris Classic – Yes, this is actually what it sounds like. A hybrid Tetris & Tower Defense game. Essentially you have tetris blocks with towers on their edges. You build a structure out of them, and the waves of minions or whatever walk through the structure you’ve built. The gameplay video is actually pretty compelling, and made me want to play.

It will no doubt amuse my friend Jason to find that there is a My Little Pony themed Tetris clone for Android.

Tetris Dungeon – appears to cross Tetris and a 2D platformer. It’s two-player only, one person plays the blocks, another plays a little guy presumably trying to escape from the dungeon, as well as avoid any full tetris-style rows the other player makes, as they will blow him up. Either way, it reminded me immediately of Blocks of Explosive Dismemberment (which you can read more about over at Indie Static). BoED is a 3-D version of pretty much the same thing. I think the platformer character plays in 1st person. Anyway, the graphics in Tetris Dungeon are not very exciting, but I’d definitely like to check it out anyway. (Another interesting point about Tetris Dungeon is that it’s open source, and the code is up on Github.)

I’m sure there are more in the literally 20 pages of search results for Tetris that look interesting. (I found all of the above in the first 4 pages.) The 20th page appears to be an arbitrary Google Play Store limit, actually, so I have no doubt that other creative searches would find many more interesting tetris-like games. Perhaps someday I’ll get a device so I can enjoy them.

How to change the color of a transparent image in iOS

This is probably as good a time as any to mention the next project I’m working on. It’s a turn-based (yes, asynchronous) board game. I decided to work with an existing game, because I wanted it to be really awesome, but also really simple. It’s an abstract game that is well respected in some circles. (I’m not going to reveal which one just yet.) Anyway, I’m working closely with the game’s designer, as well as with the same AI programmer I worked with on For The Win. The main goal of the project is to get the async code really solid, so I can feel like I really understand how it works, and re-use it in future projects.

Anyway, I think I’m also going to try something I’ve wanted to do before, and that is implement a variable color scheme for the app. Essentially you’ll be able to change the app’s background color, and that will also programmatically change the color scheme. I spent about two hours and had the basic color change functionality working pretty great with some code based on an already pretty great open-source color picker.

Anyway, one tiny piece remained… I would need to be able to programmatically tint images I get from the designer on this project. He’s going to give me some icons and other assets that we’ll no doubt want to change colors along with the rest of the app.

Some unknown number of hours later, I’ve got a solution. The number of hours is probably around the same as the number of lines of code in the solution. Here are those lines, implemented in the drawRect: method of a UIView subclass with a UIImage property named image, and a UIColor property named colorToChangeInto.

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextScaleCTM(context, 1, -1);
CGContextTranslateCTM(context, 0, -rect.size.height);

CGImageRef maskImage = [self.image CGImage];
CGContextClipToMask(context, rect, maskImage);

[_colorToChangeInto setFill];
CGContextFillRect(context, rect);

I hope this is fairly straight forward. These few lines stand on the backs of many stack overflow answers. (And I did actually write this up into a question of my own at some point.) None of the other answers were exactly what I needed, but several of them got me close. In the end, I was super frustrated because it really seemed like I should be seeing what I wanted to see, but the background of the image was black… turned out I was instantiating the image in IB (in a storyboard), but I hadn’t set the background color. Somehow that defaulted to black. That particular issue probably wasted me an hour or two.

And then writing this blog post… another half-hour, at least.