Walking into a late-nite session, the mission is to enable the
selection and placement of tiles into a dungeon, using the tile
selection panel created and placed in the designer.
To accomlish this, the initial plan was to, first, add logic to the
RHD_MapDisplay
, which would allow replacent of tiles on the
map. The next step would be to adjust the mouse listeners for
RHD_MapDisplay
, which would call the tile replacement
routine.
Some design flaws were discovered with the Dungeon
class, as there
were no methods attached to allow the replacement of an individual
tile at a given point. This and other minor adjustments were made
while preparing to write the tile replacement method.
With the minor touch ups made, creating the method within the
RHD_MapDisplay
was a breeze.
protected void replaceTile(Point position, Tile newTile) {
dungeon.replaceTile(position, newTile);
}
Problems struck soon after authoring this method. Because the two
components, RHD_MapDisplay
and the RHD_TileList
,
were not direct communicators with one another (though they share the
designer form). Some way had to be found to allow replacements
onto the map display, using the tile list.
The plan involved in the response to this problem involved the catch-all
'everything manager' for the game designer, RHD_StateManager
.
A new property was added to the state manager to keep track of the 'currently
selected' Tile
. Whenever the user chose a tile from the
RHD_TileList
, it would now call RHD_StateManger.setTileInMemory
.
(tile)
With a mechanism in place to keep track of the users desired tile,
it was now possible to call the tile replacement routine without any fuss.
Callers would simply invoke the RHD_StateMangager.getTileInMemory()
method when calling the tile replacement method.
There was mixed success when the work was first done.
For some reason, new tiles were being represented by white, empty
squares. By simply adding a command to reload the dungeon map, this
problem was solved.
It later was made clear that relaoding what may
become a very large dungeon map, each time a single tile was replaced,
was probably not a wise plan. A much more efficent means of map updating
was found by simply checking to see if the current tile's image
resided in the map's memory. If it did not, it was added to the memory
bank (a HashMap
) where it could be referenced in the
future.
protected void replaceTile(Point position, Tile newTile) {
dungeon.replaceTile(position, newTile);
// Load the tile image into the imagemap, if its not there
// already.
if (!imagemap.containsKey(newTile.getImagepath()))
{
try {
imagemap.put(newTile.getImagepath(),
FileBroker.readImage(newTile.getImagepath()));
}
catch (IOException ex) {
Logger.getLogger(RHD_MapDisplay.class.getName()).
log(Level.SEVERE, null, ex);
}
}
}
The results, for about an hour or less worth of work, were stunningly
successful. With the capability to plug tiles in willy-nilly with the
click of a mouse, this project just picked up a lot more power than it
had when it started.
There is still a whole ton to do, just to get mapping system done, both
mechanically and in the UI. The UI will receive added functionality
to place entities within tiles. Then the polish will start to be added
into the user interface, allowing use to navigate using menus like any
other decent software. The next step will be to get off of the 'test' start
crutch, and to store our game envrions and entities in files.
Be sure to check in for further updates! And don't forget to check out
the code site! http://
code.google.com/p/project-hardin is the place to check out source
code and get project details.
Happy Coding!
Timon