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.

DarkBASIC Professional Discussion / Trying to do a 2D tiling engine...........

Author
Message
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 10th Jul 2003 07:45
And I'm quite new at it. Asking for a little help.......

I have a text file that reads:

1121111111111111
1111111111111111
1111111211111111
1111111111111111
1111111111121111
1111111111111111
1111111111111111
1111111111111111
1121111111111111
1111111111121111
1111111111111111
1111111111111111

Each digit (obviously) represents a certain tile. My question is, how would I read each digit individually? Starting At position 0,0, then 1,0, then 2,0, then 3,0, etc. Thanks for the help...
Kanzure
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location:
Posted: 10th Jul 2003 08:05 Edited at: 10th Jul 2003 08:07
I would suggest NOT doing it like that. Use arrays. I have to go right now, I'll post more latah.


[EDIT]
Er, its later :p..

Okay, what you do is for File #1.



And for file 2...(your game)



There ye go!

~Morph/Kanzure
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 10th Jul 2003 08:06
Then how the heck should I do it?!!!!?!?!?!?! lol

Kanzure
23
Years of Service
User Offline
Joined: 19th Feb 2003
Location:
Posted: 10th Jul 2003 08:08 Edited at: 10th Jul 2003 08:09
Um..read the post..I edited it :p!

My method is better because you can have more then 9 tiles! You can have all the way up to 32 digit numbers I believe, but why the heck would you need that? Lol...

~Morph/Kanzure
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 10th Jul 2003 08:16
What's "tile crap"? lol

HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 10th Jul 2003 08:18
How do i read from the array??????

HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 10th Jul 2003 08:32
Okay, screw that since it's not working at all. Alright, ALL i wanna know now is how to read a text document character by character - any help please? thanks

HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 10th Jul 2003 09:36
Question has changed yet again. I have down reading the lines, but I'm using "read byte" and it will only read the first line of the map and not any lines after that. Suggestions?

HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 10th Jul 2003 10:00
Gargh. Nevermind, father time fixed it

Falelorn
23
Years of Service
User Offline
Joined: 19th Jun 2003
Location: Canada
Posted: 10th Jul 2003 10:18
Im interested on how you did that.

Can we see some screen shots to?
haXor
23
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 11th Jul 2003 02:52
wow that must be a record of most posts talking to ones self in a row...

Sup Kids
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 11th Jul 2003 05:55
lol yes...thanks to me for the help. but the reason i kept changing it is because i was posting at around 1 in the morning.

alright, here's how I did it.

Okay, basically right now, I only have about ten tiles. (My friend has been doing them in photoshop...once we have the basic engine done we're gonna make a game (yay)). Anyway, basically all you do is create a text document and type your level using numbers (eventually letters, and all sorts of characters too). You use this template:

1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111

The map is 16x12 at a size 40x40 pixels per tile, if you do the math, that's 640x480 resolution. The catch is, once your done typing out the map like that, you have to put it all on one line (that's the way the engine reads it: a single line.) So the above would become:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

Here's the engine...which is far from complete:

Sync On : Sync Rate 0
Set Display Mode 640, 480, 32

TileX = 0
TileY = 0
Images = 1

Load Image "Tiles\01.JPG", 1 : ` Rock
Load Image "Tiles\02.JPG", 2 : ` Water
Load Image "Tiles\03.JPG", 3 : ` Dead Grass
Load Image "Tiles\04.JPG", 4 : ` Dirt
Load Image "Tiles\05.JPG", 5 : ` Grass
Load Image "Tiles\06.JPG", 6 : ` Tree/grass
Load Image "Tiles\07.JPG", 7 : ` Tree/dead grass
Load Image "Tiles\08.JPG", 8 : ` Tree/dirt
Load Image "Tiles\09.JPG", 9 : ` Mini-stone path

Open To Read 1, "Levels\Stoneroad.TXT"

For I = 1 To 192
Read Byte 1, a
a = a - 48
Paste Image a, tilex, tiley
tilex = tilex+ 40
If TileX = 640 Then TileY = TileY + 40 : TileX = 0
Next I

Do
If ReturnKey() = 1 Then End
Sync
Loop

Lines 20-26 are the key to the engine - well, right now. Like I said, it's NOT done (it doesn't even scroll yet!). As you can see, there is a loop I that goes to 192. How did I get that? 16*12=192...simple. When you put the map on one line, it just reads up to 192 characters. Each number has a certain byte value. For example, 1 has a bv of 49. 2 has a bv of 50, etc. So what I did was read the byte value, and subtract 48 from it. That value is written to a. The proper image is then pasted as a tile according to the value of a. Then the x value of the tile is incremented. Once it gets past 640, it resets to 0 and the y value moves down 40 (telling the engine that otherwise, we'd be tiling off the screen).

Maybe that's more complicated than a lot of engines, but the point is, it's the first tiling engine i've ever successfully done like that (reading from a map file), and I did it myself! Yay! I'm a big boy now! Lol.

Well peace and thanks for listening to me rant....comments welcome

JesterDev
23
Years of Service
User Offline
Joined: 22nd Jun 2003
Location:
Posted: 11th Jul 2003 07:06
Thanks for sharing. I was looking for a way to do this exact thing. But didnt even have a clue as to how it was done.

The Darthster
23
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 11th Jul 2003 13:18
Here's how my tile scrolling engine works:

The data is read from a massive data array, this is currently
hardcoded, but could work from a file if the file was fed into the
array.



Movement controls, including scrolling, but there's no collision as
yet.



And sprite all the tiles to the screen! (Images 100+, 32x32)



If you're having any trouble with the scrolling, feel free to use my
code, but give me all the credit! Muhahahaa! (j/k)

Once I was but the learner,
now, I am the Master.
Karlos
23
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United Kingdom
Posted: 11th Jul 2003 17:53
just as a side note - when the read byte reaches the end of a line in a text file it will pick 1 or characters which represent the return key being pressed. It depends on which system you used to edit the file.
i.e there would have been 17 or 18 characters per line on your original text file.

If it ain't broke - try harder.
W2K Pro - Geforce2 MX400 64MB - Athlon 900
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 12th Jul 2003 00:56
I think the best way is with DATA statements. They're very underrated.

Convert your txt file to this:

DATA 1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

etc. etc.

Better still, when you design your map, design it in that format and then all you'll have to do is paste it into your code (or #Include it).

Then all you need to do is define your array:
Dim MapTile(width,height) as integer

Then just do a few loops to read it into the array:
for y=1 to height
for x=1 to width
read MapTile(x,y)
next x
next y


Thats it. All the info in the array, nice and simple.

Machine: P4 2200, 1GB RAM, GeForce4 64MB, Audigy Platinum
http://www.breakbeat-terrorism.co.uk
(It's not all about the coding)
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 12th Jul 2003 06:46
The reason I don't use the data statement is because it's not as customizable. I can just have a file that says "Hey, here's the minimum amount of maps, and here's the maximum." and then my program can just read the amount of maps, load that many, and use them the way the map tells the program to do it. Still, the data idea works well.

HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 12th Jul 2003 06:49
By the way, I think I'm gonna do a windows based map editor in VB...I already have some base-algorithims formulating in this little head of mine. lol.

shwuckie
23
Years of Service
User Offline
Joined: 9th May 2003
Location: Australia
Posted: 14th Jul 2003 17:38 Edited at: 14th Jul 2003 17:52
http://www.geocities.com/shwuckie/PxP.jpg

ok why am i linking to a jpg??? well its really a ZIP file, download that file (the easiest way to do that is to right click on the link and choose SAVE AS), change the extension to ZIP and extract the files. This is my Tile engine, it has 8 directional pixel scrolling, multilayered and animated maps.

enjoy!!

oh i suppose i should make a post too, in case nobody ever notices this reply lol

optic blast! megablast! have a blast!!

Login to post a reply

Server time is: 2026-07-21 12:50:04
Your offset time is: 2026-07-21 12:50:04