0 Favourites

Need a quick tip on how to handle simple random spawning

  • Picture Below.

    Orange square is the player. Gray is a building and all 20 buildings are 1 sprite copied over and over. When the pink AI collides with the player, there are 2 different choices. One choice is supposed to turn a single random building green, the other turns a single random building red.

    Do I have to create 20 different sprites for the buildings, 20 for green, and 20 for red? Or is there a simpler way to do it? The game ends when there are no longer any gray buildings left, and ending message depends on the number of red and green buildings on the board, different message for different amounts. Do I create 60 seperate sprites or is there an easier way? Any tips are Much Appreciated!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You could use animation frames to easily switch from gray to green or red.

    on.collision pick nth.grays instance int(random(0,grays.count-1)) // When player collides with enemy, pick a random instance of the gray buildings

    grays.changeframe to choose(1,2) // assuming frames 1 and 2 are green and red.

    // Now we need to check if any gray buildings are left, this could be every tick, or when one the buildings have changed

    pick by comparison grays.animationframe = 0 // picks all the gray buildings

    sub event > system.comparetwovalues grays.pickedcount =< 0 // the subevent inherits the picked buildings so now we see if any gray buildings are left, if not end the game

  • Wow, that's fantastic! I REALLY appreciate the time you took to explain it!

    Your effort won't go to waste, I will carry this information on all my projects

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