How do I create a "stack" for powerups?

0 favourites
  • 4 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hello friends!

    I need your help on the subject.

    I know what I exactly want, but I do not know how to "tell" the constract how to do it.

    I want to create a sort of "stack" for the powerups I collect.

    Each time the player collects a power-up (from a selection of 4) a power-up icon appears at the bottom of the screen, and when he collects a new power-up (while there is already another active) instead of the power-up replacing the existing one or running alongside the active one, his icon joins the stack at the end .

    After the power-up that is already active has finished working - I want all the icons to move one position towards the active power-up. Then the next power-up in the stack will start working. (I.e. the icon that was in position 4 moves to position 3, the icon that was in position 3 moves to position 2, and the icon that was in position 2 moves to position 1 and starts working) One step forward - except for the one that is already active (i.e. the new icon that is in position 4, the icon that was in position 4 moves to position 3, the icon that was in position 3 moves to position 2, and the icon that was in position 2 disappears ....)

    It is important for me to note that I have 4 different power-ups, and a situation can arise where you have several double power-ups, that is, you can have a power-up of a shield and then one of shots, then another one of a shield, then a power-up of power.

    Like I said I know what I want but how do I "tell" the software how to do it ...

    My problem is divided into several stages:

    1- Every time the player collects a power-up, I need to check if position 1 is free. If so, put the power-up icon there and turn it on. If position 1 is not available, check that position 2 is free - then put the icon in position 2, if position 2 is not available, check that position 3 is free - then put the icon in position 3. If position 3 is not available, check that position 4 is free - then put it In position 4.

    I guess it's possible to do it using "else" but how do I tell him "if you already put the icon in one of the locations - stop! Do not put in the other locations because you have already put in one location"

    2- When the active power up is over, I want to make the other icons "move" one position forward. Which will activate the power up that is first on the list. How do I tell them to move in the same order they were (you were in 4th place, move to 3rd place, etc.) only one position forward? I can not crack it ... that is, "the object that was in position X Y will move to a new position X Y (no matter what object it is)"

    3- I guess the answers to the previous two questions will give me the knowledge to do what I want - that if all the places are active, and you collect a new power-up - then move only the power-up that is not active forward.

    I know it was a long question but I tried to be the most accurate in my question so you can help me, I really really thank you! Thank you very much


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can do this easily with an array using the push and pop commands. Create an array that has a size of 0, 1, 1. When you pick up a power up, add it to the array using push back. When the power up ends, remove it from the array using pop front. The active power up will be at array position 0 and each consecutive power up will be listed in order.

    Edit: I had the front and back swapped around so I fixed it above. to be clear, you PUSH BACK and POP FRONT.

  • Let's start by stacking items. Use for each (ordered) to set items in queue.

  • Thank you so much for the amazing answer! And with a files I can learn from! Thank you very much! I so appreciate it !!!

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