Subscribe to:

The Kiwi's TaleWitchBlasterDerelict Blow Stuff Up

Syndicate content

SNES Mode 7 in Monkey!

I promise, this'll be the last Monkey demo for awhile! Use cursor keys or hold down mouse button to drive. (I'd be interested to hear how it performs on an iPad).

So, finally I thought up a way to do a Mode 7 type effect in Monkey that looks good, runs smooth (though it could be optimised further by sacrificing some detail) and was actually reasonably easy to program as well.

This is technically a "ray caster", but doesn't cast to every single row and column pixel like my previous "floor caster" did. Rather, it sends out a single ray for each row, and detects where it hits the map. The map texture is then translated, rotated and scaled appropriately, and drawn on screen (with the viewport clipped to that single row, so it doesn't obscure the rows above or below it). In essence, the map is redrawn 240 times each render, which is once per horizontal line from the center of the screen to the bottom.

Maybe I actually will do Earok Kart now. Who wouldn't want a kart game with Nik the Kiwi, Thalia the Elf, Noah or the WitchBlaster? Maybe with some race tracks on the Blow Stuff Up Island or the space ship from Derelict.

An episode of classic British kid's show Rainbow

"We could all paint our twangers, couldn't we?"

3D Textured Polygons in Monkey

Edit: I moved the demo to here to stop it from slowing down the Mode 7 demo. One HTML5 app on the blog stream at a time is enough!

Viola! Drag the corners to reshape the image.

Some background: It's literally impossible to do a "perspective" transformation (such as reshaping an image to be like a trapezoid) with a six element 2D graphics matrix, such as that used by HTML5, and therefore Monkey. In other words, when transforming an image, lines that were parallel before the transformation will remain parallel after that transformation.

I discovered this when I was porting Heart of Ice. Instead of being able to generate the room backgrounds on the fly, I had to manually prefabricate them in Paint Shop Pro.

As I mentioned on my previous blog post, I've been working on a "floor caster", but it's difficult to get it running both smoothly and looking good in Monkey's HTML5 target, due to the massive amount of drawing calls I need to do. So I started to think that maybe the SNES "Mode 7" effect would be better. Instead of "casting rays" from the camera to spots in the 3D world to calculate which part of the texture to draw, Mode 7 transforms a 2D image into 3D space. Super Mario Kart, for instance, transforms a 2D map of a race track into the 3D race track itself. But even a convincing Mode 7 effect is difficult to pull off in Monkey due to, again, not being able to do perspective transforms on images.

Giving up on the idea of doing Mode 7 in pure Monkey, I thought it might be possible to do it through extending Monkey with a custom Javascript class. Eventually I stumbled upon this neat little HTML5 demo that pulls off perspective transforms very nicely with a neat trick - splitting the image into a number of rows and columns, and then rescaling, rotating and cropping each segment to approximate a perspective transformed image. A couple of hours later, I managed to make a basic clone of the demo in pure Monkey, with no additional Javascript at all (so the demo works identically on all of Monkey's export paths). The image is split up into 32 rows and 32 columns, each segment containing 8x8 pixels.

This demo's certainly not as optimal as it could be. The original pulls off a more convincing effect by clipping each segment to it's exact shape (so there is no overlaping between segments or jaggedness at the edges). I may look at doing custom Javascript to support that, but it'd only work in Monkey's HTML5 export.

There's certainly a few potential uses for the idea. Obviously attempting a full blown 3D engine would be ridiculous (very leet if you could pull it off though). But it may be useful for faking Mode 7 at least. Look out for Earok Kart, the racing game you've been waiting your entire life for!

Edit: Looking at it again, I can see that I didn't get the perspective effect right. It's because the divisions are divided up evenly, in the original they're divided up so that the divisions get closer together as it goes into the distance. I'll take another look at it some other day.

Derelict: Now in a web browser

Well, okay not really =D

But I've whipped up a basic raycaster / level editor in Monkey that uses the Derelict tileset. Check it here (note: It might take a minute or so before it displays anything, as it has a fair bit of data to download). Runs pretty OK in Chrome, though again IE9 is recommended.

Click on the grid to lay down a few tiles, and then press space to toggle the First Person View. Cursor keys to walk.

A raycaster's something I have been itching to do for awhile, and I'm embarrassed to admit it was more difficult than I thought it'd be. The code is quick-and-dirty and it could certainly do with some performance optimisations (probably doesn't help that I'm using 256x256 pixel tiles!) but it seems to run pretty well considering.

I think a raycasted version of Derelict for mobile platforms is certainly a possibility, though there's a few other projects I've been thinking about first. I could also use it to finish off 'Luger Me Now' or 'Refrigeration Management Simulator 95'.

Edit: I did a raycasted floor as well. Programmatically, it was actually easier much than I thought it would be (certainly easier than the walls) but it currently runs slow as a dog, even on the C++ build. I'll have to do lots of optimisations before it runs at a playable speed.

Plus, you can see it badly needs anti-aliasing. Making a purely software renderer is lots of fun

Two Best Friends Play - L.A. Noire (NSFW)


Back on deck

Home from a 10 day holiday to the South Island. Tired. Had a great time. Stayed with Kirsty's sister in Christchurch, my parents in Otira, my brother in Greymouth and Kirsty's parents in Runanga. Caught up with a lot of friends, family and former colleagues (though not as many as I had hoped). Saw a lot of great movies with mates, including Rise of the Planet of the Apes. Spent time with my niece and Kirsty's niece, we ended up watching My Little Pony Friendship is Magic (incidentally, good show). Unfortunately missed an opportunity to challenge my almost decade-long Super Smash Bros rival (64, Melee and Brawl) to a rematch. Bought myself a cool jacket and a cheap (but good quality) parallel imported Android from DSE.

That's enough of a ramble for now. Time to get back to work.

Koi Kitsune's review of Firestart

Nearly five years after Firestart, the first game in the Earok Collection was released, Koi Kitsune has turned in an awesome youtube review of the game. Check it out!

Earok 2011 Collection: Final release

Just a quick note to say that the Earok 2011 collection now has it's own page, I've also re-uploaded the collection with the fixes and enhancements that were present in yesterday's individual re-releases.

This is the absolute last thing I'll be doing on my own game development projects in awhile!


Earok 2011 Collection: Individual re-releases

All of the games in the Earok 2011 collection have been re-released individually. They're identical to the versions in the previous released collections, except for a few tweaks for misc issues that arose during Overload.

  • Blow Stuff Up: Enemy jets are easier to shoot down, crashing bug on two player mode has been fixed.
  • Derelict: Fancy new skybox, co-operative mode glitch on levels 13 and 14 has been fixed. Also the level editor is once again bundled.
  • Firestart: Fancy new skybox, misc tweaks.
  • Heart of Ice: PC downloadable version, as well as Flash and HTML5 versions are available.
  • The Kiwi's Tale: Two player mode look up and down is working.
  • WitchBlaster: Cloak spell no longer stops all enemies shooting in two player mode.

Overload: Day 2

Overload is now, well, over. I had a great time, but I'm glad it's all over with. Totally drained

Today also started with bit of a disaster, although not quite as stressful as yesterday's fiasco. I forgot to pack both VGA cable and an XBox 360 controller, so I needed to race back home to collect them before it was opened to the public.

I think the event wasn't quite as well attended as yesterday's, I had to cut the price of the games to keep them selling. I think I did OK overall, though I certainly didn't break even (Note to self: Budget for a $5 a unit price point if I do this again) and most of what I made went straight back into buying art. I spent a bit more on A3 and A4 prints as well, including some signed photos of Yuri Inaba cosplaying as various characters. Today she was dressed up for awhile as Yoko from Gurren Lagann - hottt. Unfortunately there wasn't as many artist tables as last time, due to the room next door being reconfigured for the panels.

The panel that I was on (on how to get into game development) went well, though I was neither as well spoken nor as interesting as the other two attendees. On my left was Jonathan Rogers who is working on the Path of Exile team, and on my right was Mike Porter (formerly of FASA, Microsoft Aces, 3D Realms et al). Many of the questions asked by the audience were specifically about employment in the games industry, and unfortunately I'm neither an employer or employee in the industry!

Anthony and Sergio again did a great job marketing the games to the public. Sergio set up some of his various games on the laptop. Some of them were very inventive, with interesting graphics and gameplay mechanics I haven't seen before (I'm pretty sure Sergio's the only one who has ever made a game where you have to kill beetles with a shadow).

I know this is bit of a ramble but I can't really think of what else to say. Well, back to normality!