Page 1 of 1

ive to make a tilelevel editor need advices

Posted: Mon Mar 27, 2006 5:48 am
by PurePWNRER
hello im new to the forums :)

i want to make a level editor my game is 2d and tile based (not isometric but i guess this is no problem anyway),

my questions goes on the following

i have around 1000 tiles - how would i go to manage them all and only load the necesary ones per level?

i want to make levels of about 300x300 tiles and store them later on load in-game or in the editor - what is best for this? i want speed and small filesizes with out compression if possible - what advices would you give me for this?

i need to learn how to get the curent position i clicked on so i can place a tile and all that but my bigest problem is how can i move with the arrows and only display the necesary amount of tiles? (the ones that are going to be seen in-screen and not render the whole 300x300 array),

thnks!!

Posted: Mon Mar 27, 2006 8:29 am
by Joakim Christiansen
I want to make levels of about 300x300 tiles and store them later on load in-game or in the editor - what is best for this? i want speed and small filesizes with out compression if possible - what advices would you give me for this?
I think it sohuld be fast enough with a text file like this:

Code: Select all

0.0.0.1.1.1.1
0.0.0.1.1.1.1
0.2.2.0.0.1.1
0.2.2.1.1.1.1
0.0.0.3.3.3.3
0.0.0.1.1.1.1
Where the number is the tile-number at that position.
And use code like this to load it:

Code: Select all

For Y=0 To Map\Height
  String = ReadString(#Map)
  For X=0 To Map\Width
    Map(X,Y) = Val(StringField(String,X+1,"."))
  Next
Next
And something like this to draw it:

Code: Select all

For X=0 To Map\Width
  For Y=0 To Map\Height
    XX = X*16-ViewX
    YY = Y*16-ViewY
    If XX > -16 And XX < #ScreenWidth And YY > -16 And YY < #ScreenHeight
      DisplaySprite3D(Tiles(Map(X,Y)),XX,YY)
    EndIf
  Next
Next
Where Tiles() is a array holding all the sprite ID's, maybe loaded like this:

Code: Select all

If ExamineDirectory(0,Path,"")
  While NextDirectoryEntry(0)
    If DirectoryEntryType(0) = #PB_DirectoryEntry_File
      ReDim Tiles(i)
      Tiles(i) = CreateSprite3D(#PB_Any,LoadSprite(#PB_Any,Path+"\"+DirectoryEntryName(0),#PB_Sprite_Texture))
      i + 1
    EndIf
  Wend
  FinishDirectory(0)
EndIf
This is almost what i'm doing in a project now.
But I just started and might change it to a bether method.
But just experiment on your own, trying different ways of doing it until you got something that work for you.
I found out that using Sprite3d really speeds things up, so try to use it!

And you could do something like this in the map drawing to only browse trough the necessary parts in the array: (but carefully, or else you'll get array out of bounds)

Code: Select all

For X=(Player\X-328)/16 To (Player\X+312)/16
   For Y=(Player\Y-248)/16 To (Player\Y+232)/16
And then you can loose the:

Code: Select all

If XX > -16 And XX < #ScreenWidth And YY > -16 And YY < #ScreenHeight
If it's to slow having the file as text you could try to save it as bytecode, shouldn't be so hard, and it will take less kb's.

But anyway, good luck to you!

Posted: Mon Mar 27, 2006 9:32 pm
by PurePWNRER
:? But if I use bytes then i can use up to 255 diferent tiles, or am i missing something?. i should go for words then?

:? Id go for the binary format because i dont plan to edit the levels by hand or anything like that and i think it will be faster


2d games seems so easy when you play some of them but reality is that the internals requires lots of thoughts!

I thank you for the examples I will study them right now and tell you if theres any progress :)

Posted: Mon Mar 27, 2006 10:04 pm
by Killswitch
You can always use longs....

Posted: Mon Mar 27, 2006 10:10 pm
by PurePWNRER
but theyll be 4 bytes per tile thats a lot

300x300 = 90000 * 4 = 360000 ! why if i wont have that many tiles i can go around with WORDs they are 2bytes then do 360000/2 thats what a map will weight then why not use words .. or just store 600x600 in the same size a 300x300 of longs would take. how slower are WORDs anyway ? im also short in memory usage.

Posted: Mon Mar 27, 2006 10:29 pm
by Joakim Christiansen
I think words should be fine and fast enough. :wink:

Posted: Mon Mar 27, 2006 11:36 pm
by PurePWNRER
ok :)

on your snippet:

Code: Select all

For X=(Player\X-328)/16 To (Player\X+312)/16
   For Y=(Player\Y-248)/16 To (Player\Y+232)/16
what is 328 ? 312 ? 248 ? 232 ? where did you get that from!

is your screen size 320x240 and you did a sum of the tile size hence those nums?
:? :?

Posted: Tue Mar 28, 2006 1:14 am
by Joakim Christiansen
PurePWNRER wrote:ok :)

on your snippet:

Code: Select all

For X=(Player\X-328)/16 To (Player\X+312)/16
   For Y=(Player\Y-248)/16 To (Player\Y+232)/16
what is 328 ? 312 ? 248 ? 232 ? where did you get that from!

is your screen size 320x240 and you did a sum of the tile size hence those nums?
:? :?
Hehe, it's not so easy to explain, i'm not always shure where I get my numbers from :lol:
328: 320 + SpriteWidth/2
328: 240 + SpriteHeight/2
312: 320 - SpriteWidth/2
232: 240 - SpriteHeight/2
The screen is 640x480 and the player is always drawn in the center of the screen in my game.

And for this to work the player position must not be less then 320x240 or more then the size of the level - 320x240... (or you'll get array out of bounds)
Basicly if you see beyond the level; it will crash...
So you should place an wall or something so the player can't trawel so far... Or you might try to change the code or something...
And I use the ViewX and ViewY to modify where things are drawed, like you allready saw in my code.

But I just comment it away and use this for now, until i'll make that wall or whatever :wink: :

Code: Select all

For X=0 To Map\Width
  For Y=0 To Map\Height
    XX = X*16-ViewX
    YY = Y*16-ViewY
    If XX > -16 And XX < #ScreenWidth And YY > -16 And YY < #ScreenHeight
2d games seems so easy when you play some of them but reality is that the internals requires lots of thoughts!
And I agree with you, I'm gonna have 3 layers with tiles in my game, ground, walls and roof.
And i'm still wondering about that roof, because I want it to hide when I enter a building, but only the roof tiles for that building... :x

Posted: Tue Mar 28, 2006 1:51 am
by dracflamloc
that shouldnt be hard, just do a perimeter check around the current tile the player is under. Don't draw that tile and any adjacent roof tiles. Should be fairly simple.

The mmorpg I was working on had this: 2 'roof' layers, 2 bg layers, which alternate every 1 second (for a primitive kind of animation), and a ground tile at the lowest.

Posted: Tue Mar 28, 2006 1:54 am
by PurePWNRER
hi thanks :)

about the roof thingie: what about a child-parent way ? you could parent a set of tiles to a child or vice versa? then you could see if youre in the building zone and then dont render the roof sprites? its sure easy to say but harder to achive.

im very new to this and im just doing it for fun and learning a lot by watching your codes :) but from a logic point of view the child idea is not so bad I think. but RPGs must achive this somehow, right?.

dracflamloc wrote:that shouldnt be hard, just do a perimeter check around the current tile the player is under. Don't draw that tile and any adjacent roof tiles. Should be fairly simple.

The mmorpg I was working on had this: 2 'roof' layers, 2 bg layers, which alternate every 1 second (for a primitive kind of animation), and a ground tile at the lowest.
cool it could work! but some games hide the roof entirely this would only hide within a range right?

Posted: Tue Mar 28, 2006 2:32 am
by dracflamloc
If your algorithm was correct it would hide only those roof tiles which have roof tiles adjacent to them. This would therefore only hide roof tiles for which your player is under if you start your algo from whatever position the player is in.

Posted: Tue Mar 28, 2006 6:28 am
by Joakim Christiansen
Actually I wrote a little wrong yesterday, i guess I was a little tired.
My tiles are 16x16 and the player is 32x32, so the numbers are actually this:
328: 320 + TileWidth/2
328: 240 + TileHeight/2
312: 320 - TileWidth/2
232: 240 - TileHeight/2
Sorry about that...