Creating random cards in certain positions for card battle game

Hello everyone,

We are making a game for 4 player which you get 8 cards and whoever win 3 rounds he/she wins the game. The problem is I want to create cards randomly in certain positions in front of the player, but how do i do that? I am so new to Gdevelop 5 so if you can answer simply for a beginner I would be grateful, Thanks in advance.

(After this topic I want to create another one for the ai system and the multiplayer system of the game, if you have the answers feel free to contact me through this topic :slight_smile: )

Here is a simple way to make preset up positions for your cards to go.

Create an object called cardPosition, drag one to each spot you want the card to go.
Then you can use a condition of Pick a random Object (cardPosition) and an action of set the position of your card to cardPosition.X() and cardPosition.Y()

Additionally you would probably want to make it so cards only go to empty spots, so you could give cardPositions a variable Boolean isFull = false.

Then when you are picking the random cardPosition, also check cardPositions isFull = fale
Then in your action set that to true. So this will verify the position is empty, put a card there, then set it to full for next time.

1 Like

Thank you so much for your detailed answer, I will try to apply that and write the results here for future in case of anyone having the same problem with me.

2 Likes