Making a power grid using an array.

0 favourites
  • 14 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Hi again fellow constructors.

    I want to make a power grid using an array. I kind of made the initial setup and it works fine.

    But I have a hard time to figure out how to disconnect parts of the power grid from the generator.

    I really could use some guidance from a pro on how to make it work properly.

    I would love to hear some inputs from you on how to make this baby to happen.

    Link to CAP file

    drive.google.com/open

    Thanks! :)

    Tagged:

  • Hard to give any input on this without some context, only you know what the game is really doing. What's the generator? What do the 3 different symbols mean and do? What is 'disconnecting' in this game and where is the problem?

  • Ok, I might have been too vague in my question, sorry Plinkie.

    Well, the yellow icon is the power source. If you connect a red square by putting it next to the power source it will get powered indicated by turning green. (This is my problem ->) If you have a string of (cords pieces) red blocks (that is now turned green) and removes one block in the middle of the string - the rest of the blocks that are not connected to the yellow power generator will lose power and will turn red again.

    The tilemap is a work in progress and needs a bit more explanation.

    I hope it makes more sense with these pictures. (English is not my main language.)

  • Ya this is why I mentioned on the mewnbase post that putting the whole game into an array could become pretty complex, it's possible though. Also have you thought of using letters or words instead of numbers in the array? Might be easier to see things but of course you know what the numbers refer to so maybe it's fine.

    Depending on how the power works you could run something like, when you right click to remove a connecting tile, get its X and run everything across that x-1 looking for green tiles and set them to red. Then also go for x+1 until you stop finding a green tile and set them to red as you go. But then again I don't know how the power sources work really, if you remove a middle one but it can still be powered from the right by another generator then that won't work as they would remain green. You'll have to come up with something that you want in relation to the proper game design.

  • You know what Plinkie, I have probably made it a bit too complicated for my level of experience. I can see a lot of coming dilemmas width this approach using an array. And I think I have to go with your idea about the distance check. But it was a valuable lesson getting familiar with arrays. Thanks for your support once again Plinkie. Cheers m8.

  • I think the array is possible but if you are going for a game as in depth as mewnbase it could create problems. Looks like you were on the right track with it though :) but yes objects are a bit easier.

  • Hi Microbex, did you mean something like this :

    dropbox.com/s/e0lj64hx93cx4wc/array%20test%20grid.c3p

    What I basically did is add an 1D array (akin to a list) that get populated with tiles that need to propagate power.

  • Hi Magistross. I think you might have uploaded the wrong cp2 file as I can't see anything changed?

    But iI am looking forward to see what you have done! :-)

  • God i like you Magistross! ;0)

    I do not fully understand how you did it, but i will sit down and figure it out now. I owe you one budddy!

  • It works like a charm! I do have a lot to learn yet. :)

  • I am spamming my own post *sigh* ;D

    Well, this is soo clever done! I would not ever have come up whit a solution like this. It makes me revaluate on how to use arrays like that in the future. My failed method looks more like brute force compared to your method. ;-)

  • It's basically a queue based flood-fill algorithm. It was perfectly suited for this kind of situation! ;)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It really does work fantastic. I am still trying to fully understand your workaround, it seems so tightly knitted. :) You should really distill this system and sell it on the store imo. Thank you so much, you are a champ. :)

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