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.

Code Snippets / [DBP] Tilebased Map-System

Author
Message
Mr Kohlenstoff
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 2nd Nov 2007 02:06
Hello, it's me again.
With a new function library...

With the functions I wrote it's easily possible to use tilebased maps for 2D-Games, where each tile can have individual values, defining if it's e.g. possible to walk over it, build something on it, or how much a character is slowed down when he walks over it.

The functions make the tile-map-management very convenient and easy, you don't really have to care about anything related to the tilemap, apart from defining the tiles and templates in the beginning of your program.

At first a screenshot of the example-program below:



There you can see three tiles (grass, earth, sand) and some terrain-information in the edge.

By the way, the functions do NOT support texture-blending for smoother transitions.. I thought about it and discussed the topic with a friend for some hours but we didn't find a good solution.

Here a list of all functions and some information:

Quote: "

Functions included:

tbm_Tile(x,y) - Not a function, but an array, storing the template a certain tile belongs to
tbm_Start() - Has to be called before any other function, sets up elemental variables and arrays
tbm_SetMapSize(TilesX,TilesY) - Defines the used amount of tiles. The tiles will go from 0 to TilesX/Y
tbm_AddTileTemplate(...) - Adds a tile-template with specified parameters
tbm_SetTemplateFloat(Template,FloatID,Value#) - Defined the FloatID'th Float-Value of a template (info below)
tbm_SetTemplateInteger()
tbm_SetTemplateString()
tbm_SetTile(x,y,template) - Defines a certain tile's template, can also be made by manipulating the tbm_Tile-Array
tbm_SetTileMap(template) - Changes the whole map to a certain tile-template
tbm_SetTileBox(x1,y1,x2,y2,template) - Changes a box of tiles of the map
tbm_SetTileRandom(template,random_min,random_range) - if for any tile (rnd(random_range) < random_min) is true it becomes the template
tbm_DrawMap(ScrollX,ScrollY) - Draws the visible part of the map to the screen depending on two scroll-values
tbm_GetWalkable(x,y) - Returns 1 if a unit can walk over the tile, otherwise 0
tbm_GetBuildable()
tbm_GetSpeedFactor()
tbm_GetTileFloat(x,y,FloatID) - Returns the specific Tile's FloadID'th float-value (info below)
tbm_GetTileInteger()
tbm_GetTileString()
tbm_GetTile(x,y) - Computes the Tile the absolut point(x|y) is on (independent of scroll-values from DrawMap) and saves them to tbm_ActX|tbm_ActY
tbm_LoadSprite(file$) - Loads an external image, creates a sprite of it and prepares it for tile-usage
tbm_FreeSprite() - Returns the first free sprite-ID
tbm_FreeImage()


Template-Floats/Integers/Strings:

Each tile-template can have several additional information. They can be float, integer or string.
Each template gets a reserved amount of values of each type, depending on the only 3 used constants
tbm_cFloats/Integers/Strings. If one of these constants is 1, each template will have one personal
variable of this type in a separate array.
You can specify the values with tbm_SetTemplateFloat/Integer/String(Template,Offset,Value) and get
the values of a specific tile with tbm_GetTileFloat/Integer/String(x,y,Offset).


"




The functions:




And an example with functions (executable in this form):





I hope anybody needs such functions or finds use for them.
Criticism and suggestions appreciated.
Have fun and see ya.

da power pwnerer
18
Years of Service
User Offline
Joined: 28th Jul 2006
Location: Pittsburgh, PA
Posted: 2nd Nov 2007 13:53
awesome, and very fast too
I was getting 415 FPS constant




-Dan


http://Freewebs.com/noobisoft
Come to Noobisoft's website today!
Mr Kohlenstoff
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 3rd Nov 2007 00:41
@power pwnerer: Thanks.

Does anybody have an idea how I could realize such a smooth-transition-feature? I really have no clue how to do it without using 100's MB of sprites for each possible case...

calcyman
17
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 5th Nov 2007 17:51
There's IanM's Matrix1Map utilities. They can handle large maps.

Your signature has been erased by a hyper-intelligent pan-dimensional being (a mod)

Login to post a reply

Server time is: 2024-11-22 13:41:20
Your offset time is: 2024-11-22 13:41:20