# How do I create random coins?

0 Favourites
• 10 posts
• hi guys im making an infinite jumper type game and iÂ´m having a bit of issues with randomizing the creation of coins-

Basically what i wanted was to create groups of coins with a set distance between each of the coins for example in the format of a vertical horizontal line or a square, etc.

I also want to program it so they are not create where my platforms or other things like boosts alredy are.

How can this be done?

An example can be found on this game.

I appreciate all the help

• shameless bump

• There are loads of ways to do this. For the basics :

groupnum=0

placeY=0

function CreateCoin

while groupnum<8

Create coin at x=0,y=placeY, add 1 to groupnum, add 25 to placeY, run Function CreateCoin

That will create 8 coins that are in a straight line upwards, 25 pixels apart.

You could also create and add to or subtract from placeX rather than X=0 to move them across the screen slowly.

Based on the values you are adding to or subtracting from X you could expand this into more functions called 'CreateLine(the example), CreateLeftToRight, CreateRighttoLeft' to call different patterns. Each function could run based on a random number you 'choose' and therefore each shape of coins would be chosen at random.

• ## Try Construct 3

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

Construct 3 users don't see these ads
• Thank you for your reply. Im off to bed right now as i am extremely tired right now but as soon as i wake up i will test what you said.

By the way if its not too much to ask did you happen to notice the platforms? i would like to know how to also randomize what type of platforms are created.

Some of the platforms had specific behaviours to it like being destroyed as soon as the player touches it and being in constant movement usually to the left and right. how could i make it so which type of platform between the ones that break, are in constant movement and are normal is created is also randomized?

I dont need to know how to create these effects as i alredy know but how to randomize is being a though one for me to figure out.

I am very appreciated to you. You the man!

• Again this would just be set functions responsible for creating a number of certain types of platforms. It gets complicated when you are wanting to create different types on the same horizontal line but this can be done by passing parameters through the function for platform type. The platforms are unlikely to ever overlap because you are choosing your own X,Y co-ords so you would always set them up a good distance apart on the X or Y.

• Sorry for the late reply. I have been really busy these days.

I know this is maybe a bit too much to ask but could you maybe provide me with an example of how to do this.

I have never used functions before, don´t have a clue how they work.

Again thanks alot.

Btw how do you give rep?^^

• Here is an example of how to use a function to create a line of coins.

https://dl.dropboxusercontent.com/u/495 ... ecoin.capx

Rep isn't given, you just gain it when posting on here or by doing the various badges (see profile).

• First of all thanks for the capx.

I understand it alot better now how you managed to do it.

However i´m now struggling with implementing this to my game.

This is because the game im trying to game is an infinite-jumper type and so my background Y position is always changing, in this case to the ViewportTop of the active layer.

Also i would like this set of coins to randomize its x position, i think this part is easier though.

Thanks anyway.

• Hey if you could help me out with something i would be really appreciated.

I was messing around with the sine behaviour to create a platform that dissapears.

I managed to make her dissapear but i cant make it so that when it dissapears the jump-through behaviour is disabled.

This is my "code".

Really simple:

Platform- Is visible- Platform- Set Jumpthru enable

Platform- Is visible(inverted)- Platform- Set Jumpthru disabled.

Any idea why this doesnt work? its a really simple thing, i´m kinda confused as why it doesnt work...