Monday, January 25, 2010

Doing things differently - Part 1

Ok, this is going to be a little series about how I'm doing things differently in Jungle Hat Madness 2 in comparison to the original. When I say it will be part of a series I mean that I might have more comparisons to put up, but nothing solid at the moment.

Which brings me to today's topic.

Walls

Original

In Jungle Hat Madness, walls were created by going through a whole bunch of strings (lines of text) one by one and depending on the character (letter) that was there and the type of character all around, a different type of wall was created. For example:

If the code looked like this:

WW _ WW
W _ _ _ W
WWWWW

(Underlines mean there is nothing there, spaces don't seem to work.)

You would get this:







This looks very nice, all you have to do is type in some letters and you get exactly what the letters look like, in wall form. The problem with this way of making the walls is that each "W" is a separate wall. Sure, they all look joined, but they aren't. Each part has its own 32x32 pixel picture that is magically generated depending on the walls around it, and because I like people to know how awesome I think I am, I'm going to explain how the pictures are generated. Then I'll get back to my original point, if you don't want to know this next bit, just skip ahead.

So, the first thing you do is pick a wall, now you figure out what "squares" directly around it are walls. Done that? Good. Now you go to this convenient picture I just made and add each number in the squares that correspond to the surrounding walls.







Now that you've added up, go to the big list of different wall pictures and find the one that corresponds to your number. Then that picture is the picture that the wall displays.

So, as a demonstration, let's say I want this wall:

W

Ok, now I look around it to see what walls there are:

W _ W
WWW
_ W _

Now add up the numbers:

1 + 0 + 4 + 8 + 32 + 128 =173

Go to the list and:




Wow! That is the exact tile that is needed to make the wall.

Each of those walls around our wall have also had the same treatment, so when we load up the game we get this:







And this is exactly what we wanted. Yay!

Ok, enough tanget, back to my Original Point.

Because each of these walls has their own pictures they have to draw their own picture onto the screen every frame of the game. All of this drawing going on all the time starts to slow the game down. Because time was starting to run short, we broke each world up into "levels" to avoid having so many walls on at the same time.

Another problem with these walls is that every time the player and the enemies moved, they would check to see if they collided with each and every wall. This was a problem because the more enemies, the more lag from each of them testing each of the walls. I tried to make it so they only tested against the walls within a set distance of them, but it wasn't working properly so I once again changed it to try and get rid of some lag. This fix was to make them start moving when they first came on screen, it fixed up most of the lag, assuming the player killed pretty much all of them.

Comparison

In Jungle Hat Madness 2, I'm doing things differently. Instead of a myriad of tiny boxes in each level, with their own pictures and collision checks, I'm making big boxes without any pictures.

"But how do we know where to go?" Say the voices in my head.

Simple. There will be one huge picture that has "walls" where all the walls actually are. This fixes both problems, hopefully, of having to draw too many pictures and of having to check a bunch of walls, most of which won't even be touched by the player.

However, there is a downside to this. Because they are no longer in a handy grid format, each wall will have to be carefully and agonisingly positioned in the code. It also means more work for whoever makes the backgrounds as they will have to draw the whole level, instead of each different type of tile. But once again, I have a solution.

With JHM2 (Jungle Hat Madness 2) I will be creating a map editor. In fact, I am creating a map editor. The problem of positioning is fixed as you can see where the walls go without having to reload the code every time you want to change something. It will also, hopefully, output a visual reference for the artist so they know where the walls should be. Which makes everyone happy. Yay!

Types of Walls

Original

In JHM (Jungle Hat Madness), there were three different types of walls.

- Normal
- Moving
- Falling

Normal walls are pretty self explaining, they stop you from moving through them. Moving walls are really moving platforms, they go from side to side, move you with them if you are on top of them, and stop you from moving through them. Falling walls are parts of the floor that will fall down if you step on them, they also stop you from moving through them.

Comparison

With JHM2 I was feeling a little more ambitious, so (at the moment) there are:

- Normal Walls
- Moving Walls
- Falling Walls
- Slopes
- Fading Walls
- Walls made of ice
- Walls that you move through in all directions bar one
- Walls that disappear and then reappear at set intervals
- Sections you can climb, like ladders, or lattice, or something. You climb them.

The first three are the same as in the original, coded better, but the same. Slopes are walls on a slant, you can walk left or right while increasing or decreasing your height, pretty crazy, right? Fading Walls are like falling walls but instead of falling, they just fade away, maybe they might crumble, or change dimensions. Ice walls are slippery to walk on, you will slide for a while before you stop if you are on one of these. The others are pretty self explanatory.

Also, this is probably more writing than most of my essays from High School. If only the topic for the HSC was Jungle Hat Madness, I would have done so much better.

So, that's basically it for part one. Stay tuned for more of me talking about how good I am.

-Shadowfred

No comments:

Post a Comment