Function problem (hexagonal zone grid)

0 favourites
  • 6 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • I'm trying to make a system that spreads a player's control over the terrain. The terrain is pre-made of hexagons.

    Each hexagon has a cost (like the one used in pathing). so when the player places a base in an hexagon with no owner, control spreads from the base out.

    The base has "power" to determine how far can it's control reach in every direction.

    example image 1

    example image 2

    CAPX V.1

    I tried to use a function to make each owned hexagon spread to every non-owned hexagon around it using the base "power". However I don't know how the make construct differentiate between instances in functions when every object is actually the same.

    Any ideas?

    EDIT: I played around A LOT with it, and at least I got it to spread now... however it DOES NOT behave like i want it to =( CAPX v.2

  • Hi,

    I like the event setup in your first version. So I edited that slightly to get it working.

    All I added was parameters for the functions. Functions don't keep track of what was picked when it's called, it only knows what was passed to it.

  • R0J0hound woah! thanks :D!!! i'm not really up to speed with functions, but what you did really helped me out!! :DDD

    However, the spread is not going all 5 in every direction =(, any idea why it might be?

    V.2 (I tweeked the debug text, and some other things)

  • R0J0hound it seems to be "prioritizing" certain hexagons over other that never get to spread D:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sargas

    In event 15 it has the condition "hex owner=0". This is where the seeming priority comes from. You can disable that condition and it will spread correctly, but base2 will overwrite areas base has and vise-versa. One idea for a remedy for that would be to add a Boolean variable to hex and call it say "owned" and replace that condition in event 15 with a "[negated] hex is owned". So with that it will spread correctly but we also need to set "owned" to true eventually so we do that by adding a sub-event to event 4:

    system: Pick all hex

    hex: owner != 0

    ---> hex: set owned to true

  • R0J0hound hey, that works perfectly ^^

    fun fact, the original design of this had a "hasOwner" boolean on Hex -_-.

    I find it super weird, in my mind the logic in "!owned" and "owner=0" is the same D:. which is why I ended up not using the boolean in the first place... are booleans more easily read?

    btw, at this point I should put you in the credits for my game xD you've helped me several times already with my game ^^

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)