Brutal Map Engine by FlexiCat

From Spheriki

Jump to: navigation, search

Contents

Brutal Map Engine

Coded by FlexiCat

Description

BME is a map engine capable of handling 2d maps in both standard and isometric views, in a very simplistic manor. It is designed for speed and ease of use, all that is required to make a map is the tiles in image files and a few lines of code for the map engine to work with and you have yourself a working map. This makes the size of each map, not including image size, very tiny and simple. Although at the moment the only way to manipulate the map is with the text alone, a map editor is being developed and is on its way.

The system is capable of maps with an definable amount of layers to which there is no maximum. To enhance the engines performance during the loading of a map, each individual image tile is combined into one large meta image contained in memory.

Currently this system is capable of making a multilayer map in standard or isometric view, however at this stage it is not setup for having characters(movement) or camera movement on these maps, these are the next things to be developed. Along with the features of character support in the future BME will have; particle effects, a simple mini-map system, advanced collision, terrain physics (faster move down hill, visa versa) as well as anything else anyone can suggest we include.

Enjoy the Brutal Map Engine and look to Spheredev for the next update at the Official Forum Thread.

Usage

it is recommended that you create two global variables containing arrays, one for your game Maps the other for your Tile Sets.

const G_MAPS = [];
const G_TILESETS = [];

After that in your when your game starts up you will need to create a tile set and fill it with you tiles.

G_TILESETS[0] = new _BME_tileset(150, 75);
G_TILESETS[0].altertile(0, "transparent.gif", 1);
G_TILESETS[0].altertile(1, "tiles/grass.gif", 1);
G_TILESETS[0].altertile(2, "tiles/crops.gif", 0);
G_TILESETS[0].altertile(3, "tiles/metalplates.gif", 1);
G_TILESETS[0].altertile(4, "tiles/metalplates2.gif", 1);
G_TILESETS[0].altertile(5, "tiles/wood.gif", 1);

Breaking this down a bit now into the Lines: 1) this line create a new tileset with the first slot of the global array for tilesets. notice _BME_tileset, when instanced, has two arguments or parameters it needs. these are the size of your tiles in pixels, width then height. as this demo uses isometric tiles the ratio is 2up and 1across.

2+) the rest of the lines populates the tilesets with tiles. The method .altertile() has 3 parameters; first there is the index in the tileset that holds this tile. It is more important then you would think at first. the first tile indexed at 0 needs to be a pure transparent image the same size as the rest of your tiles. this is the default tile that fills the map space for all layers but the ground layer. the default tile for the ground layer is always indexed as number 1. the rest are not important of the numerical order they are entered in.

The second parameter is the location and name of the image file within the game/image folder. simple enough.

the third is the tiles pass-ability, 0 for non-passable, 1 for passable. as we have not implemented character support this is of little consequence.


Now we need to make and design our map. the demo code for this is as follows:

G_MAPS[0] = new _BME_map("BloodGultch", 001, 9, 9, G_TILESETS[0], true);
G_MAPS[0].addlayer();
G_MAPS[0].layer[0].initlayerspace();
G_MAPS[0].layer[0].altertile(0, 0, 4);
G_MAPS[0].layer[0].altertile(0, 1, 4);
G_MAPS[0].layer[0].altertile(0, 2, 4);
G_MAPS[0].layer[0].altertile(0, 3, 4);
G_MAPS[0].layer[0].altertile(1, 0, 4);
G_MAPS[0].layer[0].altertile(2, 0, 4);
G_MAPS[0].layer[0].altertile(3, 0, 4);
G_MAPS[0].layer[0].altertile(2, 1, 2);
G_MAPS[0].layer[0].altertile(3, 2, 2);
G_MAPS[0].layer[0].altertile(7, 4, 2);

Lets break it down to each line:

first line creates a new map similar to the new tileset. and needs 6 parameters; 1) the name of the game map to be displayed by the game 2) this is the map ID, an easier way to identify all maps, each of these should be unique. 3) the width of the map in tiles 4) the height of the map into tiles 5) a link to the tileset to be used in this map. As we only have one, G_TILESEETS[0] we use this. 6) weather or not this map is isometric, true for true false for false. easy as.

simple enough yeah. moving on to the next line:

this adds a new layer to the map. if it is the first layer this will be filled with tilesets tile indexed as 1, in this case filled with grass.

The rest of these lines alter an individual tile to something new other then that layers default. the method .altertile() has 3 paramaters: 1) coordinate for x position, across the width of the map 2) coordinate for y position, across the height of the map 3) is the a number corrisponding to the tile index of the tile you want to use here. defined in the tileset itself when it was created

NOTE:: both the tilesets and the maps can have their tiles altered at any moment in the game, however no changes will be visable until the map is re-drawn, lets show you how to do that.

during the loading of a map all the tiles need to be fused into a large image to enhance frame rate while using the map. this is done in a very very simple manor:

G_MAPS[0].buffermap();

this will fuse all the tile images into one large meta image in the computer memory and add it to the map in the property G_MAPS[0].BufferedSurface -- latter this will be changed slightly to support having moving characters inbetween the layers of a map.

now all you need is a game loop. as the above function dose not actually flipscreen and actually display what has been draw/blited/buffered into the video memory.

this is simple enough we just have a little loop runing until the user presses the escape key blit the buffered surface the flipscreen to display the map. this is all in your game loop right after you used .buffermap()

while(!IsKeyPressed(KEY_ESCAPE)){
	//buffer the map first as this is behind all other things on screen
	G_MAPS[0].BufferedSurface.blit(0,0);

	//afterwards you would buffer things like you GUI; health bars, minimaps.
	FlipScreen();
}

And you have your own Brutal Map. Enjoy people. Don't forget to follow us on Spheredev at the Official Forum Thread.

Bugs

Version 0.3a has the following bugs (as far as has been found so far):

|BUG| although in the demo code the isometric tiles normal have a margin of white space to the right hand side of each tile about one pixel wide.

|FIX| this the code has been left with the tile pixel dimensions of 150x70 however the actual tile images have been stretched out to 152x71 this fixes there error.

|PROGNOSIS| a way to work around this in code alone has yet to be found but the fix will suffice.

License

This map engine can be used by all who use the sphere engine (www.spheredev.org) and is not permitted to be used outside of this engine at this stage. the one condition when used in a sphere project is that I must be credited in a noticeable location at least within the games credits or during loading if one has a splash screen or a powered by type opening screen Brutal Map Engine must be mentioned and noticeable.

While Sphere developers have permission to use the engine, no one has given permission to edit or alter the BME.js(also named 'BrutalEngine.js') file in anyway. if one would like to alter something in the engine they must have EXPRESSED PERMSION from Brutal Map Engines primary developer FlexiCat, who can be contacted at nekroze.lives@gmail.com it should be noted that currently permission to alter BME is unlikely for now.

By downloading the Brutal Map Engine or having the file on your computer you agree wholly to the terms and conditions expressed here. If you have any quarrel with these terms contact FlexiCat.

thank you.

Downloads

Current Stable Version Brutal Map Engine v0.4a - Standard Single-File Version

Links

Personal tools