After checking yesterday's blog for early-morning typos, I realised I'd neglected to include Animated Tiles in my features list. In my experience of tile and graphic Editors, animations have always been painful to set up (and let's face it, if a feature is awkward to use, there's less chance of it being utilised by the artist, and you've compromised the quality of your game from the outset). Therefore, careful thought is required to find a simple but flexible system.
Today was long, but extremely productive (even if I did spend 90% of my time doing household chores while my brain wrestled with a few "Why won't that work?" and "That should work!" nagging niggles). If anything, it made me a little more aware of the weak areas in my coding habits, and should help me to avoid similar problems in the future.
The big task for today was the Grab mode, which allows the user to grab a "Brush" of blocks from the screen, then draw with it (see point 1 from yesterday's entry). The first task was to implement special "corner" cursors for the start and end point, to make it easier to see what's being grabbed. Then I added an overlaid "stipple" pattern which emphasises the area being grabbed even more. The main sticking point here was that the cursors and stipple are drawn to the screen and not the map, so extra code needed to be added to shunt these on and off-screen if the user scrolls the map while grabbing.
Next came the arduous task of copying the highlighted area into a custom-buffer; this seems ridiculously easy in theory, but given the fact that the start and end points can be anywhere on screen, this means that in some situation the routine has to count backwards (whereas, when plotting into an array, it's easier to count forwards using a For...NEXT loop). Struggled with the code for an hour before I realised than my brush display code hadn't been working properly!
After making a few tweaks (and a few coffees), I had the routine fully working apart from a minor bug where the Editor failed to recognise brushes that were 1 tile wide or high. After further investigation, it dawned on me that I was checking for values LESS than the cursor instead of LESS or EQUAL. So, after an hour's hair-tearing, the problem was fixed by typing four "=" characters!
I'm quite pleased with the routine, however (as mentioned earlier, it highlighted a few areas of my code where things weren't going as planned, again thanks to the LESS or EQUAL scenario). It was also my first foray into dynamic arrays - because the Brush array is generated on-the-fly, I can definitely have brushes as big than the entire map. Beans of coolness.
I finished off by adding a red box around the current Brush, which makes things much clearer. I need to invest a little time in some colour-cycling routines at some point, to allow me to "pulse" certain colours to make things easy for the user (the current bog-standard tile cursor cheats by using a small animation), so this has been added to my to-do list.
The final task of the night, and something which was utterly painless to implement, was the Brush clipping at the right and bottom edges of the map. I'm toying with the idea of allowing the user to grab a brush from one map and import the tiles (and brush) into another - this all depends on how the maps are structured (i.e. does every map have its own brush library? Even collision and effects maps?), so tomorrow's main task will involve planning out the map logistics then implementing multiple maps.
