How do I create random coins?

Get help using Construct 2

Post » Wed Oct 05, 2016 3:39 pm

Message: Husui can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
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.
https://www.youtube.com/watch?v=bU25Bk0wyLo
I appreciate all the help
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Wed Oct 05, 2016 8:21 pm

shameless bump
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Thu Oct 06, 2016 1:05 am

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.
B
47
S
18
G
84
Posts: 2,271
Reputation: 49,796

Post » Thu Oct 06, 2016 2:00 am

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!
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Thu Oct 06, 2016 7:51 am

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.
B
47
S
18
G
84
Posts: 2,271
Reputation: 49,796

Post » Sun Oct 09, 2016 3:22 pm

Sorry for the late reply. I have been really busy these days.
Really appreciate your reply.
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?^^
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Sun Oct 09, 2016 3:47 pm

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).
B
47
S
18
G
84
Posts: 2,271
Reputation: 49,796

Post » Sun Oct 09, 2016 7:29 pm

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.
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Mon Oct 10, 2016 12:25 am

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...
Thanks in advance
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Mon Oct 10, 2016 4:21 pm

How is your game working, is everything just scrolling down? The way the coins will work depends on how you have the game working, that was just a starting point. On the example I set the X to a specific value but you can send the X value through the function as a parameter or choose a random X inside the function.The platform code seems OK, probably something overriding it.
B
47
S
18
G
84
Posts: 2,271
Reputation: 49,796


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests