The Daily Click ::. Forums ::. Klik Coding Help ::. static (but moving) fog of war with array
 

Post Reply  Post Oekaki 
 

Posted By Message

SolarB



Registered
  26/12/2011
Points
  564
21st February, 2012 at 21/02/2012 15:38:39 -

Hi guys,

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


Does this make sense? Is it the best way?

My example:

http://www.mediafire.com/?pg2w5jjd92pi274


Also (and this may be too much to ask considering how it's done), is there any way of making it scroll smoothly?


Cheers.

 
My Open Source Examples: http://bit.ly/YyUFUh

Fifth

Quadruped

Registered
  07/05/2003
Points
  5818

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
21st February, 2012 at 21/02/2012 21:50:29 -

Alright, I thought this would be a great place to implement the Text Blitter object (my favorite object), so I cooked up an example file.

http://www.l-ames.com/logan/arraytest2.mfa

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.

 
Go Moon!

SolarB



Registered
  26/12/2011
Points
  564
22nd February, 2012 at 22/02/2012 05:20:04 -

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.)

 
My Open Source Examples: http://bit.ly/YyUFUh

SolarB



Registered
  26/12/2011
Points
  564
22nd February, 2012 at 22/02/2012 06:59:17 -

Also a quick question: why use Int? Surely the grid calculations make this redundant...?

 
My Open Source Examples: http://bit.ly/YyUFUh

Fifth

Quadruped

Registered
  07/05/2003
Points
  5818

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
23rd February, 2012 at 23/02/2012 17:01:47 -

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.

 
Go Moon!

Sumo148

Super amazing fantastic user

Registered
  26/01/2009
Points
  530

360 OwnerThe Cake is a LieVIP MemberPokemon Ball!I am an April FoolI donated an open source projectSanta Hat
27th February, 2012 at 27/02/2012 02:45:13 -

Is there a way to make this shadow system in iOS? Maybe use the surface object, not sure. Any suggestions and/or help?

 
n/a

SolarB



Registered
  26/12/2011
Points
  564
27th February, 2012 at 27/02/2012 13:20:20 -

@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

http://www.mediafire.com/?kz75743c58kx73p

A Surface Object version would be nice though...! Anyone?

Edited by SolarB

 
My Open Source Examples: http://bit.ly/YyUFUh

Sumo148

Super amazing fantastic user

Registered
  26/01/2009
Points
  530

360 OwnerThe Cake is a LieVIP MemberPokemon Ball!I am an April FoolI donated an open source projectSanta Hat
27th February, 2012 at 27/02/2012 22:11:08 -


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

http://www.mediafire.com/?kz75743c58kx73p

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.

 
n/a

nivram



Registered
  20/07/2006
Points
  171
27th February, 2012 at 27/02/2012 23:33:58 -

Sumo148. I have always had problems with scrolling using the Surface Object with Fog of War.

Marv

 
458 MMF2 & CTF 2.5 examples and games

http://www.castles-of-britain.com/mmf2examples.htm

SolarB



Registered
  26/12/2011
Points
  564
28th February, 2012 at 28/02/2012 06:05:01 -

I think Sketchy has a good example for basic FoW using the surface object somewhere...

 
My Open Source Examples: http://bit.ly/YyUFUh

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
28th February, 2012 at 28/02/2012 13:15:01 -


Originally Posted by Noodles
I think Sketchy has a good example for basic FoW using the surface object somewhere...


This?
https://skydrive.live.com/redir.aspx?cid=b1e7ee094271bbda&resid=B1E7EE094271BBDA!405&parid=B1E7EE094271BBDA!131

 
n/a

nivram



Registered
  20/07/2006
Points
  171
28th February, 2012 at 28/02/2012 15:57:56 -

Sketchy. I can't get the link to work.

Thanks,
Marv

 
458 MMF2 & CTF 2.5 examples and games

http://www.castles-of-britain.com/mmf2examples.htm

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
28th February, 2012 at 28/02/2012 16:10:43 -

Don't know why. It still works for me, without me being logged into Hotmail. Maybe just try it again?

 
n/a

nivram



Registered
  20/07/2006
Points
  171
28th February, 2012 at 28/02/2012 23:14:02 -

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,

Marv

 
458 MMF2 & CTF 2.5 examples and games

http://www.castles-of-britain.com/mmf2examples.htm

SolarB



Registered
  26/12/2011
Points
  564
29th February, 2012 at 29/02/2012 10:28:32 -

Perhaps this?

http://www.mediafire.com/?k34io44x7nuj0wv


Still, this type of FoW isn't really what I'm looking for. I'd love to hear back from Fifth!

 
My Open Source Examples: http://bit.ly/YyUFUh
   

Post Reply



 



Advertisement

Worth A Click