0 Favourites

Complicated snake on a grid

  • Here's yet another question related to my board game :)

    I'm trying to create a complicated snake. When the user moves a unit on the grid, it generates 'body parts' until it has reached its maximum. The idea is that once the max is reached, the unit will stop generating parts, and instead the other parts will move with the unit like a snake. A visual example is below:

    Before movement:

    <img src="http://i.imgur.com/WoOynfg.jpg" border="0" />

    First movement:

    <img src="http://i.imgur.com/9IlZUG5.jpg" border="0" />

    Second movement:

    <img src="http://i.imgur.com/1x8CTnh.jpg" border="0" />

    Final movement, here is the problem:

    <img src="http://i.imgur.com/b5hdhC2.jpg" border="0" />

    Basically, in the last image, the other two parts should move with the unit like a snake.

    How might one accomplish this?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I've given some more thought into this, and I think the easier method is simply to delete the last instance and create a new instance behind the object. This would 'simulate' the tail without going into the complexities of actually causing the parts to have to follow.

  • Alright, I almost have it. The problem is, it only seems to work with the first instance of a particular type:

    <img src="http://i.imgur.com/ep2PZY6.png" border="0">

    The events I'm using to handle this is the following:

    <img src="http://i.imgur.com/eBPT6yz.png" border="0">

    I did check in the debugger to confirm that both objects in the first picture that had more than 2 'parts' did indeed have PartsActive = 3 while PartsMax = 2 for both of them.

    Does anyone know why this might be happening?

    BoardGame.capx

  • I've moved the deletion of the furthest part to a function for on-demand access. I also ran a few tests in the debugger and nothing has changed - programs still have PartsActive > PartsMax and the function doesn't seem to be getting called the second/third time around.

    Can someone take a look?

  • I checked your function "DestroyFurthestPart", and you're only calling it once. Everytime your condition is met, be it by one or more instances of the family PlayerPrograms, the function will only be called once, with the first instance that meet the condition. You should do a for each family member under the condition PartsActive > Self.PartsMax.

  • We (another experienced C2 user and I) have done this.

    Adding a For-Each does not fix the issue.

    <img src="http://i.imgur.com/49hj02c.jpg" border="0" />

    <img src="http://i.imgur.com/aHuqnIY.jpg" border="0" />

    There is no 'obvious' fix to this problem. I have tried the 'obvious' fixes, hacky workarounds, and more, and it is still not working.

    It appears to only pick the first instance that meets the conditions while ignoring the others. I'm not sure what is going on at this moment. I am not the only one who has tried to solve this particular problem and lost as to why it doesn't work. We've isolated code, deleted code, and more. It may be time to ask R0J0hound to investigate.

    I'll be seeing if I can reproduce this issue with a simpler case.

  • You should usually do the picking BEFORE the for each, no need to iterate through objects that does not meet the PartsActive > Self.PartsMax condition.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
564 105,260
rexrainbow's avatar
rexrainbow
Unread hot topic
0 Favourites
Grid based lighting/field of view
65 15,239
elwinalice's avatar
elwinalice
Unread hot topic
0 Favourites
[Behavior] Grid based sight
58 36,796
Syazanie Amirin's avatar
Syazanie Amirin