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! / 2d map tile collisions

Author
Message
DaedalusX
22
Years of Service
User Offline
Joined: 10th Mar 2004
Location:
Posted: 14th Jun 2004 01:00
fixed my problem below now i am wndering if it is possible to have collision responding to 2d map tiles?

Daedalus
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Jun 2004 01:28
Lots of tile collision posts on previous pages. Basically you are keeping a check on the tile positions by storing all of them in an array with an offset value.

DaedalusX
22
Years of Service
User Offline
Joined: 10th Mar 2004
Location:
Posted: 14th Jun 2004 01:39
arrays dont really know how to use them

Daedalus
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Jun 2004 02:35 Edited at: 14th Jun 2004 02:36
An array is just a way to split numbers up into groups.....

Example....Dim Cards(13,4)....A pack of cards 13 numbers..4 suits

**********************************************************************

Dim Map(20,20)....A tile map 20 horizontal tiles, 20 vertical

load Image "Grass.bmp",1......a 32 pixel tile
load Image "Wall.bmp",2......a 32 pixel tile


map(1,1) = 1.....The top corner tile has a value of 1 = Grass
Map(2,1) = 2.....The next tile is a wall.

for y = 0 to 20
for x = 0 to 20

If map(x,y) > 0
Paste image Map(x,y),x*32,y*32...
endif

next x
next y


So the program just pastes 2 tiles. It skips the other tiles because you have not made a map yet. You really need to build the map before you do all this. Data can be used to build the map. You can find Map editors that will create the data. You have maybe a lot to learn to get this program working the way that you want it to. Especially if you have never used an array before.

DaedalusX
22
Years of Service
User Offline
Joined: 10th Mar 2004
Location:
Posted: 14th Jun 2004 20:41
ive always had a basic idea but that is concreate thanx a lot ill have to keep this thread

Daedalus
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th Jun 2004 01:49
DaedalusX,

It might help to look at my reply to JHA in the following thread.
http://darkbasicpro.thegamecreators.com/?m=forum_view&t=32618&b=4

Specifically my response with the screenshot & source code button.

---
The basic idea is to use a mutli-dimensional array (3 dimensional in this case).

Dim world_array(Xtiles,Ytiles,numoflayers)

*! Remember arrays start at 0 so for a (20 tile by 20 tile) world with 5 layers you would.

dim world_array(20,20,5)

when indexing into this array you would have
world_array(<0 to 19>, <0 to 19>, <0 to 4>

hence, the top-left tile the world at the lowest layer would be
world_array(0,0,0)

*******

Layer 0: Are used for base terrain and drawn beneath the player.

Layer 1: can be used as a fringing/transition layer or for highgrass, bridges over water, secret passages(if you placed a wall tile on this layer the character would be able to walk over it, I use this for walkable water and the like) etc.. and are drawn beneath the player

Layer 2: This is the layer that your character is on. Any tiles placed in this layer your character will collide with and not be able to walk on. eg. tree stumps/trunks, items like barrels, deepoceans, mountains, other characters.

layer 3: Tiles that appear above the player eg.s (tree limbs, bridges the charcter walks under

layer 4: I use this layer for effects or sometimes I decide to have the character at level three if I need more effects for tiles underneath.

By using this method, you only need to check for collision on one layer (in this example layer 2). So the collision is internally handled in the design of the map. As well as the drawing order. You always draw layer 0 first, then layer 1, layer 2, 3, and finally 4. A value of 0(a good value to choose) in any layers array index is transparent. A small example(only showing layer 0,& 2) of a island surounded by ocean. The island is walkable so will be drawn on layer 0, the ocean is not walkable so it will be dran on layer 2. assume that 0=transparent: 1=ocean : 8=land

layer 0 (walkable):
0000000000
0088888800
0088888800
0088888800
0000000000

layer 2 (not walkalble):
1111111111
1100000011
1100000011
1100000011
1111111111

when drawn to the screen it the world would look like this
1111111111
1188888811
1188888811
1188888811
1111111111


Emperor Baal
22
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 17th Jun 2004 02:07
Not really, index numbers run from 0 to the declared index number.

So basicly:

dim Array(20,20,5)

can be used with the index numbers 0-20,0-20,0-5
take a look at my tutorial site (link below my sig)

JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 17th Jun 2004 03:25
Hey Zen,

I just checked out what Emperor Baal says above and he's right. Although no other language, that I know of, does it this way, apparently Dark Basic does.

So when you dimension an array with 20 elements, it actually holds 21 elements.

Is this a bug or a feature?

JHA
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th Jun 2004 04:46
That's what I get for going on assumptions and past experience. Leave it to DB to go against the norm, or any rational convention.
I have dealt with both; languages that start indexing at 0 and others that start at 1. This is the first time I have encountered a language that starts at 0 but goes up to the number in the dim command. It doesn't make much sense.

If I say dim array(20)

I am requesting 20 elements AND expecting 20 elements .
either
from 0 to 19: OR : 1 to 20

Never am I expecting 21 elements from 0 to 20!

I swear DB has it in for me sometimes!
From now on I'm going to have my computer play the theme to the "Twilight Zone" everytime I launch the compiler.


I hope my other points weren't missed because of this oversight.


IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Jun 2004 16:03
It's not irrational - It just covers both bases. Remember that this is a language that a lot of beginners learn on, and a few experienced programmers use.

It only makes sense to cater for both sides ... although I admit that catering for both at the same time may seem a little strange, but its easier for Lee - the same generated code deals with both ways.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk

Login to post a reply

Server time is: 2026-06-09 15:43:13
Your offset time is: 2026-06-09 15:43:13