Monday, July 31, 2006

Tile-Engine Rebirth




It's highly enjoyable remaking old classics of your childhood. but it sure is time-consuming. I'm embaressed to say how long it took to make some of the backgrounds alone. Today I got quite a lot done though.

Check out the Nexus link for some new updates.

You can press Q to punch, and if you're in the elevator room, you can see the doors open too when you press it. I haven't as yet implemented a proper elevator system as of yet(that's probably next) but if you tap Space bar it flips arrays and you can see the next level when you leave the screen.

CODING
First, I got around to rewriting the art/tile based hybrid engine. If you check the Nexus l*ink you can see the little beauty in action.
It wasn't much of a hurdle to code- in fact, I'll post the code here for the newbs.

tile_width=60;
tile_y=50;

myMap = [5, 4, 6, 4, 3, 2, 1, 2, 0];

//myMap is the array for the background. The numbers refer to the corresponding movies. Ah, you'll get what I mean in a minute..It'll probably end up as a 2d array (to deal with levels) but I'm just keeping things simple for now.

myMiddleMap = [[0,10,0,0,0,0,0,1,1,0],
[0,1,0,0,0,0,0,0,0,0],
[0,0,0,0,2,0,0,0,0,0],
[0,1,0,3,0,0,1,1,1,0],
[0,0,0,1,1,1,0,0,0,0],
[0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,10,0]];

//myMiddleMap is a double-array that contains references to objects held in movies that combine to create the middle tile layer.

this.createEmptyMovieClip("background", this.getNextHighestDepth());

background.attachMovie("cavetile_" + myMap[current], "cave", background.getNextHighestDepth());

//In the library, my backgrounds are all named like "cavetile_1" "cavetile_10" etc, so all the above line does is check the myMap array to see which one is up, then attaches it to an empty movieclip called background.


for(var i=0;i < style="font-style: italic;">current is a referer to which screen you are actually in.
First we check to make sure the array reference isn't 0. If it is, that means there's nothing to plot, so we do nothing except go to the next tile, 60 pixels further to the right. If we do have a tile that needs to be placed, we give it a name "Midtile" with a number from 1-9. and we position it appropriately by setting its x co-ords to i*the set tile width.

Later on I make sure to replace 'cave' with the new backgrounds at screen change, and remove the previous one when it's out of view, along with all the tiles that are attached to it.

I quite like my little tile engine because it's fairly flexible. Though the mid-tiles have to retain a set width, their height is dependant upon you. Further more, since they're all movies, they can be animated and code put on them.

For example, an invisible wall tile is pretty easy to implement.
When the character runs, before incrementing or decrementing his x position, we check to see if a collision flag has been raised. If so, we disallow any changes. The collision flag check is performed within the tile movie itself. You run a hitTest to see if the _root.hero has collided with it, and if so it returns true and our character stops moving towards it. With most tile-engines, you have to check every frame for a collision, but because the code is inside the tile and not on the main program, it's that little bit faster as it only runs tests after it has been created.

I'm either really smart, or my code is pants and I'm just too dumb to recognise it.
-----------------------------------------------------------------------------------------------
I was thinking about whos faces to use for the undercover agents. In the original, the faces were digitized and probably mates of the programmers, but I figure "Why not just go the whole hog?" and put my favourite actors in there instead. So look forward to seeing Christian Bale, Al Pacino, Di Caprio (haha, just kidding), Christopher Walken, and plenty of others make an appearance. I figure I'm never going to get sued since the game is being made basically just for my entertainment, and if any Ebaum or wherever steals it without my permission for their site then they'll likely be the ones getting the finger pointed at instead. Hell, I'd find it hilarious if I was a famous moviestar and some cheeky Brit used my face for a crappy game.

Well, it'll be a laugh getting to that, but first and foremost I need to get the levels working properly and a tracking system up and running. Did I mention I welcome volunteers? Sigh.This is going to take forever...

Labours of love.

No comments: