Trying to make a FoW with as little actives as possible. I'm still new to arrays and so I'd like to know if this is the most efficient way of doing this:
Player moves around, as it moves its position on a grid is market in an array. A grid of static fog objects set their visibility depending on the value set in the array. The screen scrolls but the fog grid does not, rather the foglets set their visibility depending on the player position value set in the array. I'm using:
ForEach "foglet"
+ set x dimension and y dimension (array) to xpos, ypos "foglet"
ForEach "foglet"
+ xpos, ypos (foglet) = index x,y (array)
+ valueatXY [xpos, ypos (foglet)] = 1
--> make invisible
ForEach "foglet"
+ xpos, ypos (foglet) = index x,y (array)
+ valueatXY [xpos, ypos (foglet)] = 0
--> make visible
This is using a single Text Blitter to display a screen's worth of one character, each of which appears as just a black tile. It then uses the "callback" function, which you can use to give specific instructions to each tile. And so each tile is given its own transparency drawn from the array.
It's a lot like using a screen full of active objects, but by using this method you can get by with smaller squares without any impact on performance (as it is still only one Text Blitter object). Though if you get too small it starts getting complicated. I went for 32x32 pixel squares.
At this size, though, you don't uncover a lot of area at one time, so I added the option to uncover adjacent squares as well by holding Ctrl.
Additionally, I added an extra smoothing option based off of the data from adjacent spaces that I think looks kinda nice. Try it out by holding Shift.
Let me know if you need anything clarified. It's a nice object to use, though a little unusual to deal with.
This is excellent, and almost perfect. Thanks for the comprehensively commented example, indeed I have a lot to learn. I like the smoothing option... nice touch!
However - what if I wanted to use different shapes for the fog grid? Say hexagonal?
(By the way, my game is a miniRTS so player control means clicking multiple characters to a destination and holding right mouse to drag the screen.)
Hexagons, huh? That's going to be tricky, but it should still be possible.
I think the best way would be to use the callback function to move every other row over by a bit to get them staggered, and then move each row up an amount as well to get them to overlap properly. And then it would just be the issue of cleaning up the math to get them to correspond to the proper array values.
Do you care if the hexagons end up stacking straight horizontally or vertically? 'Cause I think this will be much easier horizontally.
And I just like to use int to make sure values stay integers when I divide. I know I'm not forcing floating-point calculations, and most of these wouldn't matter either way, but it's a habit I like to maintain.
@Fifth - Yes, any hexagon stacking is good. I really have no idea how to go about this, my maths is pretty awful. Even without using TxtBlt, could I still use the mod technique to stack or would I have to make the grid the old loop way? Another example would be much appreciated (if you would be so kind).
@Sumo148 - Using Fifth's brilliant example I managed to make one without the text blitter - of course the ForEach extansion I have used here can be substituted with regular loops - oh yeah, added smooth fading
Originally Posted by Noodles @Fifth - Yes, any hexagon stacking is good. I really have no idea how to go about this, my maths is pretty awful. Even without using TxtBlt, could I still use the mod technique to stack or would I have to make the grid the old loop way? Another example would be much appreciated (if you would be so kind).
@Sumo148 - Using Fifth's brilliant example I managed to make one without the text blitter - of course the ForEach extansion I have used here can be substituted with regular loops - oh yeah, added smooth fading
A Surface Object version would be nice though...! Anyone?
Thanks for that example, with this it could be possible but I dont know how hard it would be on an iPhone with all those actives and loops, you know? I'm looking into the surface object at the moment. Maybe something can be worked with that.
I had to download something else with the FOW example. There is no scrolling with that example. I had problems with this months (or years) ago. Spent days on it to try and scroll.
Thanks again, and that's some good theory. But which part exactly is the extra zig-zag math in your example? Not a huge matter, but would still like to know.