Introduction
CMapEditor
is a simple and efficient interface for using a multi-level matrix of values. This can be easily used in games or any other program that requires a versatile map structure.
Functions
How to use CMapEditor
:
#include "CMapEditor.h"
Include the .h file in your code. Keep also in mind that CMapEditor
requires the <vector>
header to be present on your machine.
To initialize a map just use:
CMapEditor meEditor(WIDTH,HEIGHT,LEVELS);
or
CMapEditor *meEditor = new CMapEditor(WIDTH,HEIGHT,LEVELS);
To set a cell's value in the map, use:
meEditor->SetMapValue(X,Y,LEVEL,VALUE);
You can also use advanced operations, such as region fill, or drag-like procedures:
meEditor->Fill(X,Y,LEVEL,REPLACE_VALUE,VALUE);
and
meEditor->StartDrag(X,Y,LEVEL);
meEditor->EndDrag(DX,DY,VALUE);
CMapEditor
also supports basic undo and redo operations. You can decide what is going to be undone by calling
meEditor->NextUndo();
before performing other operations. For example:
meEditor->NextUndo();
meEditor->SetMapValue(X,Y,LEVEL,VALUE);
eEditor->Fill(X,Y,LEVEL,REPLACE_VALUE,VALUE);
...
in this case, the SetMapValue()
and the Fill()
effects will be undone together. To perform undo and redo, just use:
meEditor->Undo();
and
meEditor->Redo();
Why did I write this class
Actually, the purpose of this class was for me to learn. And I did. As a matter of fact, class programming was a bizarre way of thinking about stuff before, therefore, I decided to start from the basics, and started learning about that. OK, I got the basics, but if you have any comments on how I programmed the class, please let me know. Secondly, I wanted to get familiar with Hungarian notation (all my other projects are big messes), so if you have comments also on that, let me know. And finally, I learned how to use vectors, which I didn't expect to use (actually, I didn't even know what thery were) and they seem to be pretty useful. Another reason for which I decided to write this class, is that I wanted to contribute something hopefully useful to CodeProject.
History
- Last Update (15 Oct 2003)
- I have fixed some memory leaks issues. Now the class destructor is correct.