PDA

View Full Version : Writting map editor from scratch tutorial (With Allegro)



Darkhog
12-06-2013, 11:03 AM
Do you know of any tutorials that teaches you how to write map editor from scratch using Allegro.pas/Allegro library? Might be C Allegro as I have no troubles converting C code into pascal (headers are another story though).

The reason of this is that I want to use my own map editor with custom, binary data format for my next game (after Super Heli Land) that saves to custom binary data format, so maps would be fast (XML are text files and as such they take bit longer to process than binary data) and I won't have troubles with loading/saving them properly as it'll be my own data format.

Plus, I would get valuable experience.

SilverWarior
12-06-2013, 11:24 PM
First of all graphic library which you use doesn't have much inpact on making game map editor woth exceptions of 2D and 3D capabilities.
Also it laregly depends on what kinda game are you trying to make.

But in short if you know how to make game it shouldn't be hard to know how to make editor. If we are talking about 2D game you only need to make yourself and aplication which provide you with the ability to chose and place certain parts of the mape (usually sprites).

Not so long ago I was helping another member with making of editor for his own planned game. We haven't finished it which might also be partially my fault. I actually lead him to wrong path on faulty asumption that something can't be done using the graphic engine he was using (I asumed that the graphic engine doesn't have any optimization) so we wasted several weaks on implementing custom optimization which only lead him to confusion. I hope I won't make same mistake again.

Any whay you can find some more infor on this here (all of our mishaps): http://www.pascalgamedevelopment.com/showthread.php?14690-Space-Shooter-Game-Editor

Darkhog
12-06-2013, 11:49 PM
Well with this being tilemap editor (think more RPG Maker than, say, The Games Factory) I would have most difficulties with snapping tiles to grid and showing grid cursor.

How do I determine which "tile" user clicked as in snapping mouse to grid of certain size?
How do I make showing "tile cursor" (small square of size according to tile's size) in proper place instead of always under mouse?

SilverWarior
13-06-2013, 02:42 AM
How do I determine which "tile" user clicked as in snapping mouse to grid of certain size?

Easy!
GridXPosition := Mouse.X div GridCellWidth;
And if your map is bigger than what you can render on the screen you have to take into acount your viewing position. So if your viewing position on X axis is at coordinates 145 the forumla would look like this:
GridXPosition := (Mouse.X + ViewpoirtX) div GridCellWidth;


How do I make showing "tile cursor" (small square of size according to tile's size) in proper place instead of always under mouse?
Once you have grid position you can simply multiply it by grid size like this.
SelectorSprite.X := GridXPosition * GridCellWidth;
And if your map is larger than the screen
SelectorSprite.X := (GridXPosition * GridCellWidth) - ViewportX;

Darkhog
13-06-2013, 08:56 AM
And if map's viewport is moved away from 0,0 (top-left corner) and occupy only part of screen (after all tile palette should go somewhere), equation would be:
GridXPosition := OffsetX + ((Mouse.X + ViewpoirtX) div GridCellWidth);

am I correct?

User137
13-06-2013, 04:26 PM
No, you don't need 2 offset variables, ViewPointX already does that. If you wanted to also draw a tool panel (instead of using IDE components) on the left side, and always draw the entire map more to right, then you would use OffsetX. But then it would be
GridXPosition := ((Mouse.X + ViewPointX - ToolPanelWidth) div GridCellWidth);

Darkhog
17-06-2013, 07:20 PM
Well, allegro.pas don't mix well with Lazarus' forms and allegro gui library looks terrible (just look at ASEPRITE for example).

SilverWarior
17-06-2013, 07:45 PM
Well, allegro.pas don't mix well with Lazarus' forms

None of the game graphical engines doesn't mix wel with either VCL or LCL. The main reason for this is the technology that is used for each learegly differs from others.
Most game graphical libraries use either DirectX or OpenGL as their main technology.
VCL and LCL use default system GUI which is quite slow in comparison to DirectX or OpenGL. Also the biggest problem of default OS GUI is that it laregly depends on system messages which can also be quite slow. That is why it is much better to create your own internal game messaging system rather than using OS messaging system.

laggyluk
18-06-2013, 03:55 AM
I'm experimenting with forms based ui along with opengl scene rendering, so far so good :p

User137
18-06-2013, 06:56 AM
I'm experimenting with forms based ui along with opengl scene rendering, so far so good :p
No problems with that, as long as you don't draw WinAPI controls, such as buttons on top of rendering scene.