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! / Making a 2D Map

Author
Message
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 7th Feb 2004 23:32
Hey. I was wondering how to use tiles to make a 2D map with walls and a floor that i can move a sprite through. Thanks a lot.

.....
UnderLord
20
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 8th Feb 2004 01:16
coding it would be hard its best to look for a level editor

The search continues.
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 8th Feb 2004 18:11
I don't want a whole level, just one screen. I know you can use DATA for this, but does anyone know how to read it and put it on the screen. If 1 = a wall and 2 = the floor, then I want something like...

data 1,1,1,1,1,1,1,1,1,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,1,1,1,1,1,1,1,1,1

...just very simple. If anyone knows the code for this then please help.

Thanks.

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Feb 2004 18:57 Edited at: 8th Feb 2004 19:53
Dim Map(10,10)

For y = 1 to 10

For x = 1 to 10

read a

map(x,y) = a

next x

next y


data 1,1,1,1,1,1,1,1,1,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,2,2,2,2,2,2,2,2,1
data 1,1,1,1,1,1,1,1,1,1


Something like that should work.

Then to put it on the screen you do the same....

Tilesize = 32

For y = 1 to 10

For x = 1 to 10


Paste image map(x,y),(x*Tilesize)-32,(y*Tilesize)-32

next x

next y

That would build up a whole screen, but you don't build up any more whole screens after this, you just build up a single line of tiles in the direction of the scroll.

Jonny_S
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 8th Feb 2004 21:52
Pincho's way is very good, also making an editor is VERY simple, its not as hard as some people may think, I wrote one in less than 2 hours, and the code to load a level in a game is just as simple its just up to you, using the data way is probably faster, but writing a level editor gives you more experience

Supermonkey - The crime gifhting sex god monkey!
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 8th Feb 2004 22:42
thanks guys. Now I was wondering how to add sprite collision to the sprite that you can move so it can't go past the walls. Here's the code i have so far:



i was also wondering how i can get the tiles to surround the whole screen (they're 50x50)

thanks a lot

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Feb 2004 00:11
Quote: "i was also wondering how i can get the tiles to surround the whole screen (they're 50x50)"


Well this is quite simple maths, and you are going to have to learn some maths to make a game.

There are many screen resolutions, so you pick one....

800*600 = 800/50 600/50 = this is how many tiles fill your screen!

Dim map(800/50,600/50)

Collision takes place after a player has walked across some grass. So if he starts the game in the middle of a grass tile, he walks to a wall, and his coordinates, his x/y position has to be moved to the centre of his body....

spritewidth=(sprite width(1)/2)
spriteheight=(sprite height(1)/2)
offset sprite 1,spritewidth,spriteheight

Now the man walks to the wall 25 pixels minus his width/2.
As he walks you need to count the number of pixels that he moves. His Map(posx,posy) has to be checked all the time. You use the same map() that built up the screen earlier. If that map position = 2 then he has hit a wall, and you stop him from moving. So everytime the man walks 50 pixels across the screen you need to...

inc posx

If he walks to the left you have to....

dec posx

If he walks up the screen 50 pixels you need to...

dec Posy

If he walks down the screen you need to....

Inc posy

That's an explenation, but the code still has to be worked out. Try to work it out before you ask for the code.

MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 9th Feb 2004 03:38
thanks a lot pincho. Would i do it something like this:

spritewidth=(sprite width(1)/2)
spriteheight=(sprite height(1)/2)
offset sprite 1,spritewidth,spriteheight

posx=x
posy=y

if posx=sprite collision(1,2) then posx=posx-1
if posy=sprite collision(1,2) then posy=posy-1

...i have a feeling this is wrong...
i'm confused how to use the sprite collision() command. Can you please give me the code for it...i would appreciate it so much.
Thanks again Pincho, you've benn a huge help.

.....
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 9th Feb 2004 04:02
Now i figured out this code...

if sprite collision(1,2)=1 then guyx=guyx-1

...but it keeps giving me this error message that bob does not exist. What does that mean? How do I fix it?

thanks

.....
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 9th Feb 2004 04:19
i know i've just posted 3 in a row..but i figured something out i think...sprite collision() works here

...but not here

..i think it's because it has to read data, or something to do with that. Do you know why and how to fix it? Thanks a lot again.

.....
Kwiki Mart
20
Years of Service
User Offline
Joined: 9th Dec 2003
Location: PA
Posted: 9th Feb 2004 05:13
bob is another term they use for sprites. I dont know why but thats what a bob is. You have not coded a sprite 1 so it says you are missing sprite #1.

On target, On time!
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Feb 2004 10:36
Sprite collision is for two sprites colliding, but your walls are not sprites. So you use your players x/y coordinates to check where he has walked. Then you see if his position is the same as the Map(posx,posy) = 2, and if it is the same, then he has hit a wall. You are making your own collision. You could try sprites if you want, DBPro is quite fast, and can probably cope with wall sprites. I think that this game might be too hard for you though.

JHA
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 9th Feb 2004 20:03
Hi MakcKid,

Bob stands for Blitter Object. This was a term used by the Amiga computer that represented images created by its Blitter Chip. Basically its graphics chip. It is similar to a sprite but is really more of a movable section of a bitmap. You could use this like a sprite, in that you could make the image move and act like one, but it wasn't really a sprite. The only way to move a Bob, was to copy the background of the location where you wanted to move the Bob too, so that you could copy it back onto the screen once the Bob move to another location.

Probably more than you wanted, or needed, to know, but that is basically it.

Thanks
JHA
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 9th Feb 2004 22:44
thanks a lot guys. I finally figured out how to do it..
here it is:

thanks again!

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Feb 2004 23:11
Yeah that sort of works, so long as the walls are always around the edges of the screen. Not a bad attempt.

MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 10th Feb 2004 01:49
hey. I'm having trouble with the screen resolution. Under display properties, I set my screen resolution to 800x600. But, it dispays with the wall sprite all over. Here's my code:

Do you know whats wrong?
Thanks again!

.....
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 10th Feb 2004 10:26
Doesn't DBPro have something like this?

set display mode 800,600,32

UnderLord
20
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 10th Feb 2004 16:00
yes by doing the set display mode 800,600,32 or 1024,768,32

The search continues.
PowerFang
20
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 13th Feb 2004 02:21
I've built just what you need. I'd be more then happy to send you the source if interested. Heres a link to a pic of it:

www.geocities.com/baskers2000/demo.jpg
PowerFang
20
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 13th Feb 2004 02:27
For collisions, i use a seperate array to deal with it:

DIM mapAccess(mapwidth,mapheight)

Access = mapAccess(xCoord,yCoord)

if Access = 1 then blocked = 1 (i.e. hit a wall)
if Access = 2 and HaveBoat = 0 then blocked = 1 (i.e. cant walk on water unless you have a boat)

if blocked = 1
xCoord = xCoord - xmove (i.e. take back the movement so it doesnt
yCoord = yCoord - ymove (paste sprite on the wall)
endif


if Access = 3 then ChangeMap (i.e. you walked into a door so you are now entering a new area)

I found this method allows alot more flexibility with your map and how you can interact with your map rather then just use sprite collision.

Thinking now i guess you can use sprite collision to do the same result....dunno which is better.
MakcKid
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location:
Posted: 13th Feb 2004 03:46
thanks..I'm not using sprite collsion.
Instead I'm doing something like this:



If you know how to make the guy stop when he hits a 1 tile can you please tell me?
thanks a lot!

.....
PowerFang
20
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 13th Feb 2004 11:32
You need something like this: (i.e. check to see if hit before moving)
PowerFang
20
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 13th Feb 2004 11:33
grrrr where'd my code go
PowerFang
20
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 13th Feb 2004 11:34 Edited at: 13th Feb 2004 11:35

Login to post a reply

Server time is: 2024-05-13 10:13:44
Your offset time is: 2024-05-13 10:13:44