Moving “floors” to free slots

0 favourites
  • 2 posts
From the Asset Store
************ 2D top down floor spikes **************
  • Greetings, I'm making a game in the “tower defense” genre, but with one tower on which you can set different floors, and today I ran into a problem.

    I don't know how I can implement a floor swapping system, for example:

    1) The player removes the first floor, and all floors from the top are shifted down to the vacant spaces.

    2) A player wants to place a new floor, for example on the 3rd position, but it is occupied, however, when the player moves the cursor over an occupied slot, the floor that occupies the slot is shifted to the slot above, if it is free, if not, the player cannot place a new floor.

    How can something like this be implemented? I will be extremely grateful for any help!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It depends on how you've implemented the floors to begin with and also what kind of data is stored in a 'floor'. Assuming you've not made the floors yet, you could use an approach with instance variables, for example different variables for each floor 1,2,3,4.

    For 1) then you can say e.g. if 2 is clicked/removed, set 2 to the value in 3, set 3 to the value in 4 and set 4 to <empty> etc

    for 2) e.g. if 2 is clicked and 'occupied', then you check if 3 is 'empty', if so you set 3 to the value of 2, and set 2 to the new value. if 3 is 'occupied' then do nothing.

    Another approach especially if it is going to have a crazy amount of floors or it is going to be only a single tower in the game then it might be better to use an array, for 1) if you delete a row, the others shift down automatically, for 2) you can check the next room etc as mentioned above.

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