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! / Populating 2D array?

Author
Message
Davecgt
20
Years of Service
User Offline
Joined: 6th Feb 2004
Location:
Posted: 27th Feb 2004 20:03
Hey All,

For the collision detection in my 2D Zelda clone i'm trying to use a 2D array with which i can check the player position against certain collidable world tiles. The problem is:

I can't seem to figure out how to populate my array. I'm sure it needs to be just after the PASTE IMAGE command (see code below), but nothing i do seems to work. Any help is soooooooo needed

Cheers All,

Dave.
Chaos
21
Years of Service
User Offline
Joined: 8th Feb 2003
Location: United Kingdom
Posted: 27th Feb 2004 20:28 Edited at: 27th Feb 2004 20:28
If i were you i would create a level editor instead of a dat file and save the info in the level editor into the array. Also in your code you may want to paste during a do-loop otherwise nothing will display. See code.

Edit
oops forgot to mention that i have also included how to populate you array


Prep
20
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 27th Feb 2004 21:00
I wouldn't advise redrawing the map every loop, just everytime it changes.

To be no more, sad cure.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 27th Feb 2004 21:29 Edited at: 27th Feb 2004 21:49
Trying to draw an entire screen from tiles during the game is not recomended. Zelda uses 8 way scrolling I think. So you only draw the tiles that will scroll onto the screen. You can get the number of drawn tiles down to about 8 per loop which is fast. To do this you need two bitmaps. Bitmap 1 is a huge bitmap.
You only paste the tiles onto bitmap 1. Then you copy bitmap 1, to bitmap 0. By the time that your character has walked to the edge of the screen, the whole next row of tiles has been drawn. They are drawn maybe 2 to 4 at a time, and only in the direction that the player is walking.

Not easy to explain.

Chaos
21
Years of Service
User Offline
Joined: 8th Feb 2003
Location: United Kingdom
Posted: 27th Feb 2004 21:38
Obviously you would need to cut down the number of tiles drawn per loop but that depends on the scrolling conditions etc.


Prep
20
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 27th Feb 2004 21:49
Personnally I would avoid using a paste image routine at all, using a sprite for each tile makes scrolling far quicker, I would imagine the same holds true for plains. (but perhaps it wouldn't be a "True" 2d game)

To be no more, sad cure.
Chaos
21
Years of Service
User Offline
Joined: 8th Feb 2003
Location: United Kingdom
Posted: 27th Feb 2004 23:55
Ive made a few small 2d games and i have noticed no speed reduction using paste image (even in DBC but now i have PRO). But i suppose its a matter of code layout and the style of the game.


Prep
20
Years of Service
User Offline
Joined: 17th Nov 2003
Location:
Posted: 28th Feb 2004 01:46
Speed reduction from what?

If I was scrolling only 2 ways I wouldn't mind using paste image, but I have yet to see any paste image code that handles as fast as swapping sprites images. Its a lot easier to animate your tiles also.

I looked at a varity of scrolling techniques and would be interested in seeing some very fast scrolling with paste image routines as it would take out some of the calculations I have to do with my sprites.

The only real advantage of using paste image (that I can see anyway) is for very small accurate scrolling.

I could be wrong though, and have just seen / wrote really poor paste image routines.

To be no more, sad cure.
PowerFang
20
Years of Service
User Offline
Joined: 6th Feb 2004
Location: Australia (But currently in the USA)
Posted: 28th Feb 2004 12:10
I recommend seting up your tile/map info into files. What i do (i'm also making a 2d top down zelda clone......different though) is have a file called Terrain.dat This file holds all the info of the Tiles in the game set out like this:

Tile Name
Tile Filename
Tile Access Number

Then, when use my map editor to make the map, it uses 2 arrays. First it loads all the Tile Numbers into an Array called MAP(), and saves it to a File called [Map Name].MAP, This is where i draw my map. Then i load all the Access Numbers into an Array called Access() and save it to a file called ACCESS.Acc

Open To Read 1 , [MAP NAME].MAP
For x = 0 to (Map Grid X Squares - 1)
For y = 0 to (Map Grid Y Squares - 1)
Read String 1,Tile$
Tile = val(Tile$)
Map(x,y) = Tile
Next y
Next X
Close File 1

Open To Read 2 , ACCESS.ACC
For x = 0 to (Map Grid X Squares - 1)
For y = 0 to (Map Grid Y Squares - 1)
Read String 2,Acc$
Acc = val(Acc$)
Access(x,y) = Acc
Next y
Next X

Then when you want to check for collisions/events, you look into the Access Array and read the Access Number. In my game, this is what they all mean.

0 = Cant ever walk on this tile (Wall etc....)
1 = Can Always walk on the tile
200 -> 299 = Doors that open a new map (Shop doors, edge of map)
300 -> 399 = Entrances, So the program knows what grid square to draw the player on when he walks through the door
400 -> 499 = Messages, when walked on displays a text file to screen
500 -> 599 = Merchants, when walked on opens up the shop menu
600 -> 699 = Monsters, when walked on starts combat

etc, etc......

That way all you do is change the Access number in your Terrain.dat file and when you make a map it has alot of flexibility. This is real simple Array Collision but i found it is soo powerful/useful.

Email me at: mbaskerv@hotmail.com

If you need any help with your Zelda clone engine since i'm almost finished mine so i might be of some help to you.
Davecgt
20
Years of Service
User Offline
Joined: 6th Feb 2004
Location:
Posted: 29th Feb 2004 13:15
Cheers All!,

Got a lot to consider from your posts. I'm gona have a good sit down now and see what i can do.

Cya,
Dave.
UnderLord
20
Years of Service
User Offline
Joined: 2nd Aug 2003
Location:
Posted: 5th Mar 2004 07:33
Hmm inttresting i wonder if this would work for a game im making right now its going to be a basic shoot em up space game but im thinking of building off of it after that and making it into a trade/shoot up/ do what you want type of game but then again maybe not but who knows...

The search continues.

Current project - A space game

Login to post a reply

Server time is: 2024-05-18 05:24:20
Your offset time is: 2024-05-18 05:24:20