How do I prevent multiple enemies overlaping in this turn based hex-based pathfinding ?

0 favourites
From the Asset Store
Upgrade your game's interface with the Purple Hex UI Kit.
  • dropbox.com/s/fnmu2kkvzg6sr7i/hex_pathfind4.capx

    So turned out we could do it with less events. The pathfinder doesn't need us to temporarily mark tiles as walls at all.

    * Now the player and an enemy can occupy the same tile.

    * Once on the same tile you can attack or step off the tile.

    * enemies are done one at a time. If they can't possibly get to the player they just don't move.

    I will say it probably doesn't match what you had in mind exactly. like you may want objects to just battle to the death when on the same tile and not have the option of retreat. Or maybe you want objects to bunch up instead of walking around the water so once a space opens up they are close. Anyways, you'll have to tweak and tailor to what you have in mind since i don't know everything.

    Also one thing i didn't touch is making objects sharing a tile not be right on top of each other. I had a smooth way of doing that in mind but you have some other way in mind.

    -cheers

  • Hi R0J0hound

    Thank you so much for this.

    Going through your code is the best way to learn a lot of Construct subtilities.

    Everything looks as I wanted to. I'll have to adapt the attack part to my gameplay with attacking occuring as soon as Player and Enemy are in the same hex. Then two things can happen : 1) player is killed -> game over 2) Enemy is killed -> enemy destroyed and game goes on.

    I thing I'll try a simple collision test between Player sprite and Enemy's to trigger Attack routine function and not trigger Attack when Occupied =2 (that I'll keep to allow player and enemy to be both in a same hex). And btw, it's more Battle function than Attack function, since it doesn't matter who attack who, Battle function acts the same when two adversaries are in contact.

    I'll let you what I come up with.

    Thank you again !

  • Try Construct 3

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

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

    I think you'l be proud of me.

    I managed to set up an Attack routine that looks pretty well.

    Here's how it runs :

    - When Player and an enemy are in the same hex (ie that hex occupied = 2), game state is set to "attack"

    - a layer is displayed. So far, it is just a button but it is meant to have a battle routine with action choice for Player (use weapon, use spell). Here, when button is clicked, Enemy is destroyed, ie Player wins.

    - Then two things can happen :

    1. Player still has move points left, game resumes to map where reachable hexes are displayed ("show moves" state) --
    2. Player has no move points left (meaning has attacker in the last hex it has been able to reach OR attack has occurred after an Enemy move) then game resumes to Enemies actions ("move enemy" state).

    Since you can't read C3 files, here's a screencap of the commented code :

    Still a lot to do but all this is on the right tracks.

  • Nice. Glad it was useful and you were able to make tweaks to the logic and add stuff.

    -cheers

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