Forum Topic: As2 - Tile-based Engine - Multiroom

(113 views • 3 replies)

This topic is 1 page long.

<< < > >>
None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 3/10/09 04:54 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

I'm working on a tile-based engine. It was working fine with code like this:

var room1 = [ [1,1,1,1,1],
                        [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,0,0,0,0] ];

var room2 = [ [1,1,1,1,1],
                        [0,0,0,0,1],
                        [0,0,0,0,1],
                        [0,0,0,0,1],
                        [0,0,0,0,1] ];

var room3 = [ [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,1,1,1,1] ];

var room4 = [ [0,0,0,0,1],
                        [0,0,0,0,1],
                        [0,0,0,0,1],
                        [0,0,0,0,1],
                        [1,1,1,1,1] ];

var rooms = [ [ room1, room2],
                        [ room3, room4] ];

1 = barrier
0 = moveable area

I have it coded so that when the player reaches the edge of the current room, it checks the "rooms" array to see if there's another room to go to (for example, if a player is in room 4 and on the left edge, it checks for a room to the left in the rooms array, i.e. index - 1).

This worked well until I realized it's no good if the rooms are not the same size. Here's an example of the rooms I want to implement now:

var room1 = [ [1,1,1,1,1],
                        [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,0,0,0,1],
                        [1,0,0,0,1],
                        [1,0,0,0,1],
                        [1,0,0,0,1],
                        [1,0,0,0,1],
                        [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,0,0,0,0],
                        [1,1,1,1,1] ];

var room2 = [ [1,1,1,1,1],
                        [0,0,0,0,1],
                        [0,0,0,0,1],
                        [0,0,0,0,1],
                        [1,1,1,1,1] ];

var room3 = [ [1,1,1,1,1],
                        [0,0,0,0,1],
                        [0,0,0,0,1],
                        [0,0,0,0,1],
                        [1,1,1,1,1] ];

Room 1 is on the left, rooms 2 and 3 are on the right (two towards the top, 3 towards the bottom). But this doesn't work with the "rooms" array from above. How would you suggest I organize the rooms so that the code can recognize what room to go to based on where in the current room the character is?

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

StaliN98

Reply To Post Reply & Quote

Posted at: 3/10/09 05:00 PM

StaliN98 LIGHT LEVEL 10

Sign-Up: 07/27/07

Posts: 690

Maybe have more properties per tile than just 1 or 0, like (pseudo code)

[solidity:Boolean, textureNumber:Number, linkTo:Array ([roomNo:Number, linkToX:Number, linkToY:Number])]

The link to array is in 3 parts.
roomNo is the index of the room array.
linkToX is where the player's x will be in that room
linkToY is where the player's y will be in that room
Just an idea. At least, that's how I will do it in my engine.


None

Doomsday-One

Reply To Post Reply & Quote

Posted at: 3/10/09 05:01 PM

Doomsday-One EVIL LEVEL 10

Sign-Up: 10/28/05

Posts: 1,384

Firstly, working with rooms of different sizes is a little weird. Lots of scaling issues if you do it one way; or the other would mean a single array would suffice.
Not questioning it, just I hope you know what you're doing =)

For going between rooms, you could use a sort of linkage letter or number. For example, give the 'doorway' the letter 'a' at the entrance in one room, and the exit in another.
Then, when the character goes to 'a', check the arrays (or pre-store the exact locations for added ease) for the exit, and put the character there.
Also, you would probably want to stick in your code to put a blank tile (0) wherever the array value is not a number (or just stick a blank tile when the value is not greater than 0).

Doomsday-One, working on stuff better than preloaders.

By the way, I made the 'Create an Animated Sprite' preloader for Sprite TV 3!


None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 3/10/09 05:49 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

At 3/10/09 05:00 PM, StaliN98 wrote: Maybe have more properties per tile than just 1 or 0, like (pseudo code)

[solidity:Boolean, textureNumber:Number, linkTo:Array ([roomNo:Number, linkToX:Number, linkToY:Number])]

The link to array is in 3 parts.
roomNo is the index of the room array.
linkToX is where the player's x will be in that room
linkToY is where the player's y will be in that room
Just an idea. At least, that's how I will do it in my engine.

I appreciate the input. That's how I used to do it in my old engine, but it became crowded. I ended up with hundreds if not thousands of tile prototypes and I had to remember which tile led to which room. This also doesn't work with the code I'm using to scroll the screen.

I am, however, using tile prototypes (i.e. for solidity and texture) in the real code. I just don't want to specify a direct x and y value for the character on the new room.

At 3/10/09 05:01 PM, Doomsday-One wrote: Firstly, working with rooms of different sizes is a little weird. Lots of scaling issues if you do it one way; or the other would mean a single array would suffice.
Not questioning it, just I hope you know what you're doing =)

I have code so that the screen scrolls. The maps are actually much larger than the 5x5 in my example. So one room could be a hallway that's 80 tiles high, but a couple rooms it branches off to on one side could be only 10 tiles high (because they aren't hallways).

For going between rooms, you could use a sort of linkage letter or number. For example, give the 'doorway' the letter 'a' at the entrance in one room, and the exit in another.
Then, when the character goes to 'a', check the arrays (or pre-store the exact locations for added ease) for the exit, and put the character there.
Also, you would probably want to stick in your code to put a blank tile (0) wherever the array value is not a number (or just stick a blank tile when the value is not greater than 0).

Thanks, that makes sense. Rather than keeping the rooms in a multidimensional array, I'll put them in just a normal array and use their indexes to link to other rooms.

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


All times are Eastern Standard Time (GMT -5) | Current Time: 04:58 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!