SamSuka
sqwarkdemon
sqwarkdemon

patreon


[Animation Breakdown] Helltaker 2 - Part 3: Tile based game

If you haven't read the other parts I suggest you do so to keep up:
Part 1: Setting up
Part 2: "Typewriter" Text

So here's the thing. I made the tile-based game before everything else. It was more of a test to see if I could, and while it's not perfect (far from it, actually) it at least works!


- = [ Spawning in the tiles ] = -

The first things I even tried to do was get free movement working, and after that it was tiles.
If I couldn't even add the tiles in there was no point continuing. 

To store the tiles I used an array.
The array looks like this:

1 = Dead space (Black tiles that you can't walk on)
2 = Dark grey walls
3 = Grey floor
4 = Light grey floor
7 = "Lava"

If the player walks over the "lava" they get hurt. These were later changed to spikes.

Let's take a look at my first iteration of this:

Primitive, but it works!

And, of course, here's the code:

Okay so there's a lot to unpack here, and this is still the WIP version!

What this is basically doing is this:
"i" is the current array position. It sees what number is in the array position of "i" and then goes to that frame on the tile movieclip. The tile movieclip, by the way, has every tile in it.

With every horizontal placement of a tile it tracks a number. If that number exceeds the maximum number horizontally (in this case 10) it resets and adds that one tile vertically by one instead, and resets the number back to 1 to tick up again.

Once it hits the maximum length of the array (in this case I believe it's 70) it stops adding and the loading phase is considered complete.
In the meantime, while it's loading, if the array position it's on matches the current spawn number then it will add the player character to that exact position and prepare it for movement. 

Now the base loading system is complete, let's look at how to load items in. 


- = [ Adding objects to the stage] = -

So using the same method we did to see if the current array position number ( i ) matched the player starting point, we can do the same for specific tiles. 

Using this, we can now add items to the stage via another object I've named tileObj.

By using an assigned texture, I can add objects over the tile. I have indicators on the tiles you're not meant to see to show me what's meant to spawn where.
This, by the way, is why you can see the "L" underneath locked boxes.

Also this: 

These are under Lucifer, Azazel, and Cerberus. 

The benefit from doing this is that the objects are then placed over the world that's been added first, due to child order.

So if the system detects that the current array number is, say, 31 (locked boxes) then it will add the locked box over that current tile.

Alright, we've created the world, we've placed the tiles, but what else? 


- = [ Movement ] = -

The movement is, actually, deceivingly simple. It's also really poorly done, I'm not going to lie to you. 

Basically what the movement is doing is it's moving the entire width and height of the tile every time you move. it's also tracking where in the array you are, and if the tile you're trying to move to is a tile you can or can't move to.
I would show you my code here but it's somewhat bloated and really requires a re-write. For now, though, it works fine.

Once I got what tiles you CAN and CAN'T walk on out of the way, I worked on character interactions.
To interact with a character you go up to them and go to walk on them. Of course this doesn't move your character or anything but instead spawns in their chat scene. However I'll talk about that in another post...

The most challenging thing about tile based games is constantly keeping track of what tiles you have, adding the right arrays, keeping the right information, and constantly managing your code so it doesn't end up a bloated mess like this one did... 

Anyway, I hope this was a nice insight to how I got the tile-based stuff to work!
Below is the source file for the Helltaker concept. You can open it in any version of Flash I think, as long as it has AS3!

[Animation Breakdown] Helltaker 2 - Part 3: Tile based game

More Creators