Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Tile Based Level Design in DBC (collision, foreground, background, etc.)

Author
Message
Erusuwasu
20
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Where am I? I think I\'m lost...
Posted: 17th Nov 2003 09:55 Edited at: 23rd Nov 2003 11:31
This post has been edited since it's original post

I know a lot of people are talking about this at the moment and I was hoping to get some help as well since I'm using DBC. I'm going to try to do this on my own, but others should feel free to use this post to help with thier own questions about scrolling, collision, and tile maps in DBC. Thankyou to everyone who helped me



This is the code I started with.

I've got DBClassic and Photoshop Skillz and I'm not afraid to use um!
Prep
20
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 18th Nov 2003 00:39
I'm pretty new to DBP myself (23 days in fact) so I might not be the best source of information in the world.

I have just started my own mini RPG which "uses" a FF style combat system (works pretty well!) and has a tile based map / world.

I don't know much (well anything really) about using Data commands as I just used a 2d array for each map area I have (they are saved as dat files from a little "map maker" style thing I did). It scrolls when I reach the edge currently so thats not much use to you either but the idea might be.

I wrote a function which looks "something" like this, its fired during a KeyState() check in one of the ctrl parts of my code.



With this I simply assign any tiles it wish to be walkable values less then 500 and those I do not greater then. (thinking about it now it would have been a good idea to do it the other way round or add more padding)

The same array is then used to build the bitmap also which saves memory I guess.

------

The following is something I havn't done before so its easily open to failure.

Using a similar system to what you already have going or like what I just said, you could perhaps make a second bitmap (Create Bitmap 2,Xsize,Ysize) build your level on this bitmap (a little loading bar maybe in order if its big, but as your not working on a displayed bitmap it should be pretty quick). Then as the player moves you could Get Image from the second bitmap and paste it into the first increasing the X,Y(I don't know how your scrolling direction wise) as you go making sure your updating your characters position in relation to the collison detecting array / data.

If that makes sence i'll be happy, if that works i'll be suprised. I hope I have given you an idea of how to do it, cause I think I have given me one.

To be no more, sad cure.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 18th Nov 2003 01:51
That sounds right as far as I can make out.
Erusuwasu
20
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Where am I? I think I\'m lost...
Posted: 21st Nov 2003 09:23
Ok, I understand the logic and that makes sense for the scrolling. It's as follows:

When the player reaches certian x or y position return a value which tells the program to display the next row or column of desired tiles. The program is getting the images from an unseen bitmap off screen (?).

The only thing I'm wondering now is how to edit my code to do it. Would I just totally get rid of the data statements and create the screen some other way? Plus that doesn't answer some of the other questions:

1. What is the best way to handle collision in a tile based game and how does it work?

Here's some pseudo code and you can tell me if I have the right idea:



I've got DBClassic and Photoshop Skillz and I'm not afraid to use um!
Erusuwasu
20
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Where am I? I think I\'m lost...
Posted: 21st Nov 2003 09:26 Edited at: 21st Nov 2003 09:27

THANKYOU SO MUCH FOR YOUR HELP SO FAR
IT'S BEEN A GREAT HELP.


I'm just still trying to wrap my head around it all.


I've got DBClassic and Photoshop Skillz and I'm not afraid to use um!
Scuba Steve
21
Years of Service
User Offline
Joined: 8th Apr 2003
Location:
Posted: 21st Nov 2003 22:16
I'm not a DarkBasic programmer (yet? I kinda need money ), I'm currently learning C++ and DirectX 8, but it looks like Prep has the right idea, and it's the same form I use. I've been trying to figure out similar problem with movement, but in a different situation. Seeing as the solution should be similar in both languages, I'd figure I'd post here, and we can both get something out of it.

When programming a bridge (lets say a horizontal bridge), when you are on the ground, you want to be able to pass through the tiles going up to down, and have the bridge tile overlap the player. Should be easy enough to program this. Something like
(psuedocode)
PlayerMoveUpOrDown = True;
PlayerMoveRightOrLeft = False;
DisplayPlayer = False;

But I'm having a problem figuring out how you tell the tile engine that you're going to be on the top layer, and disable the walking from up to down, and enabling walking from right to left, and making the player overlap the bridge tile.

I was thinking of creating a sort of function call that determines what direction the player came from (or when a player moves right, it also returns what direction he came from ie. the left), and having tile engine determine the possible direction of movement accordingly, as well as how to render the tile properly (over or under the bridge).

I think I answered my own question, but does anybody have any comments or suggestions. I'm not concerned with a C++ specific answer, I could figure out how the code will work in my context anyway.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Nov 2003 00:06
That code snippet at the top of the page does all that. Maybe you can understand how it works.
Erusuwasu
20
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Where am I? I think I\'m lost...
Posted: 22nd Nov 2003 11:32
Hey Pincho, not to single you out, but I know you know how to do this stuff. What do you think of the psuedo code snippet I posted in my second post? Do I have the right idea? Can you give an idea on how to feel in the blanks?

Not just you either. CloseToPerfect(even though he uses DBP), IanM, and many others I've seen probably know this stuff. Where's the love

I appreciate everyone who's tried to pitch in so far, but I still haven't really gotten the answer I'm looking for I guess.

I've got DBClassic and Photoshop Skillz and I'm not afraid to use um!
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Nov 2003 14:08 Edited at: 22nd Nov 2003 14:15
The screen is made from pixels as you know. There are really too many pixels to do a collision check with them all, so we do a collision check with square blocks of pixels. 16*16 or 32*32 or whatever you want. You make an array that is divided up into these square blocks.

Screen 800*512 = Dim Map(50,32)

You fill this array with 0's and 1's. A 1 would be a collision, so you stop the player from moving. As the player walks around you only change the Array reference when he has walked 16 pixels.

so
Pseudo Code..

Dim Map(50,32)
ArrayCounter = 8
Walk Player..

If Leftkey...dec X : dec ArrayCounterx
If Rightkey inc X : inc ArrayCounterx

If Arraycounterx > 16 then inc MapPointerx : Arraycounterx = 1
If ArrayCounterx = 0 then dec MapPointerx : Arraycounterx = 16

If Map(Mappointerx,y) = 1 then Collision.


Ok so that's a rough idea of how it works. It's missing lots of other stuff, but I think it is better for people to write their own code so that they learn things better.

Pincho.
Erusuwasu
20
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Where am I? I think I\'m lost...
Posted: 23rd Nov 2003 11:24
I totally agree that it's better for people to do their own code. It's a much greater learning experience. That's why I stated in my first post:

Quote: "
I'm not just asking for you to give me a bunch of code. I'd appreciate any answer that could provide me with insite on how to solve the problems before me.
"


Thankyou for the help everyone. I'll just have to work this one out on my own. If anyone else needs help with this, feel free to use this thread to ask your questions. When I figure it out I might post agian with some info on how I did it.

I've got DBClassic and Photoshop Skillz and I'm not afraid to use um!
CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 23rd Nov 2003 19:55
Hamada, have you got this working?
I do it just like Pincho say with 1 execption.
I use a 3d array for the map and use layers

map(xsize,ysize,layer)

The layers change from program to program but let mee show you 3 layers as thisis th most common for me.

map(xsize,ysize,1) is the background layer (if it a rgp it's the land and water and mountians)
map(xzise,ysize,2) is the object layer (again on a rpg this could be trees, houses, people, (if inside a house chairs, tables),ect)
map(xzise,ysize,3) is the blocking layer, I use several blocking codes, (again rgp, open land would be set to 0, water set to 1, moutains set to 2, trees and other obsticle set to 3, how every many I need.)

This way if the character is walking he can cross any tile set to 0, if he's in a boat he can cross tiles set to 1, if he's flying he can cross tiles 0,1,3 ,moutains are to high and difficult to cross, but maybe I could add a moutain climbing skill and then he could cross tiles set to 2 if he's walking only and has the right equipment)

I draw layer 1 first, layer 2 ontop of that and it gives it a 3-d look where a tall tree may lap over more then 1 tile I only block the 1 tile where the base of the tree is, that ways the person looks like he's walking behind the tree.

That's about all the theroy behind it.

The first thing you should do if make a map editor, mine usually draw the tile to select from down the side. Have it draw color boxes around the tiles to show the blocking. Have the map editor save the array and then you can simple load in the array in your program. Your map editor won't need smooth scrolling but you will have to learn to the basic of drawing tiles for it and selection tiles which will come in very handy.

for your first map don't map something hugh (map(1000,1000,10)) it's such a big task that people get discouraged and quit. Start small (map(50,50,2) and get a simple game working with that, then for the next project make it bigger. My current map uses 64x64 tiles, I tought I could make a really nicly detailed world with that, but my discouraging factor is I can't draw images that look very good at all, They look plain bad to be truthful, I've spent much more time tring to find images to use then programming. 32x32 is a good size image to use, there are alot on the internet ready to be used.

CTP

Lifes short, try to enjoy it and not take it to seriously!
Erusuwasu
20
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Where am I? I think I\'m lost...
Posted: 24th Nov 2003 11:03
Thanks for the in depth description CTP. I'll post when I've got my program up and running. Shouldn't be to long now, thanks to everyones help.

It comes to a point when feelings gotta get hurt, and get dirty with the people spreading the dirt.
las6
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Finland
Posted: 24th Nov 2003 11:34 Edited at: 24th Nov 2003 11:41
just to confuse everyone, simple array collision might not be enough. From what I remember from my rpgmaker95+/2K times, you really want to make it a bit more complex.

let's think about a simple scene. Your have this nice grassy field, surrounded by trees on all sides, effectively stopping you from moving out of the map. You also have this small river/stream running through the scene. Let's say someone built a bridge over it, so that you can cross the bridge.
- - -
let's pause here for a moment. using a simple array collision that returns whether the tile is passable or not, you can effectively keep the player from hitting the stream or running away from the scene. You should even be able to walk over the bridge, as it could be treated as ground. Or if you are using levels, it could sorta be a workaround.
Everything's fine, and you shouldn't be able to bump into any errors. Now add a another bridge next to the one you have. I assume you use a simple rpg-like tile, so the bridge could be just one tile. putting two bridges next to each other does look stupid, but think of what would happen. you would be able to pass from one bridge to the other one, despite the fact that the bridges are separate. But because the collision check returns "land", it will work.
Not the worst case, as you can always leave 1 tile space between these type of tiles. But it can create some errors.

the way they solved this in the rpgmaker programs, is that they had 4 variables in each tile. Or well, they weren't showed us variables, but anyway. East,West,North and South. So a bridge, running vertically would have their North & South variables on, the others off. That means that when you are in that tile, you can move up or down but not sideways.

Better example might be a cliffside. If you are trying to create neat height-differences, you might need this. Two land tiles next to each other doesn't always mean you can walk between them.

oh well, one other thing. The fun, rpg way to do trees is to separate them to 2 or more tiles. The lower tile works as the collision, the upper tile is passable. This enables you to Pass under the treetops.

Keyboard not detected. Press F1 to continue.
JSN
20
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 24th Nov 2003 13:22
At work at the moment, so I can't look at the manual, but isn't there a command to detect pixel-perfect collision with an image, no matter what 'shape' it is?

If this is the case, then CTP's method is fine.

You'd simply have the 'non-collision' background on layer 1, the 'collision-background' on layer 2, and all your after is to see if the users sprite has hit a pixel on layer 2.

~ J ~
las6
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Finland
Posted: 24th Nov 2003 13:45
eh. pixel collision is slow, besides I don't think there is such command. You can use the pixel collision, but not very much. and for something like this, it's rather overkill for most cases. Depends on what you are doing, though.

Keyboard not detected. Press F1 to continue.
JSN
20
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 24th Nov 2003 13:51
Well, like I said, at work so don't have the manual here (must remember to fetch DBPro in this week )

But, couldn't there be something like...

(pseudo alert!!)

MAP(x,y,l)

for x=0 to screewidth/tilewidth
for y=0 to screenheight/tileheight

if map(x,y,1)<>0 then
placeimage(x,y,imagenumber(map(x,y,1)))
end if

next y
next x

for x=0 to screewidth/tilewidth
for y=0 to screenheight/tileheight

if map(x,y,2)<>0 then
placesprite(x,y,imagenumber(map(x,y,1)))
end if

next y
next x

~ J ~
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 24th Nov 2003 14:37 Edited at: 24th Nov 2003 14:38
Well you could make the bridge in the example have a map tile numbered 2 instead of 1. When standing on a 2 you could ignore up/Down keypresses, and just have left/right movement. Also, in real life, who would put 2 bridges next to each other anyway? I understand the example, but array collision is fine until you try to do things to deliberately mess it up. Lets say you really do have to put things near to each other, then you could ignore keypresses like I said, or you could make a map with 8*8 tiles which would leave a small gap between things.

Yeah you could also use sprites for the bridges, and have sprite collision.

Pincho.
JSN
20
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 24th Nov 2003 15:00
Further to this, I'm under the impression (correct me if I'm wrong), that if you were to use the array collision system, then your 'collisions' would have to be with tiles that actually fill the tile, so you wouldn't be able to have detection on "thin rods" because these rods would be less that the tile width. You "could" make a collision on a rod that is 8 x 8 pixels, but then again you'd have to make all the other tiles 8x8 too, which would results in a HUGE amount of tiles on the screen at any one time.

Pincho - did I explain that good? Am I hitting the nail on the head or my thumb?

~ J ~
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 24th Nov 2003 18:09 Edited at: 24th Nov 2003 18:10
Yeah you're right! With thin rods you collide with them with a space around you. Graphics have to be drawn similar to the size of the tiles. 16*16 is good enough though, even for thin rods. A lot of games have used 32*32 and nobody noticed, but that can be very annoying! Dying without touching something can be a pain! I'd use 16*16, that's commercial quality! The collision for 16*16 can be done inside the player/Ship whatever so that they overlap a bit. People can then slightly pass over things, and this keeps the player happy.

Pincho.

Login to post a reply

Server time is: 2024-05-08 11:14:13
Your offset time is: 2024-05-08 11:14:13