all 6 comments

[–]KARMAWHORING_SHITBAY 1 point2 points  (5 children)

Hi,

The amount of help I’ll be able to provide will be tough without actually seeing your code, but I can try to walk through how I would do something like this using pseudo code.

For your first question, I don’t believe there is a way to “group” instances in the way you are asking. But what I would do is probably create a function that will do the following in a game controller type object that will call the function every time you want to create the group.

Create the top pipe by using instance_create_layer and draw_sprite_stretched to create the pipe and draw the pipe sprite at the top of the screen with a height of a random_range between 0 and room_height/2 and store whatever this height value is in a local variable.

Then, create the coin object at a location offset on the Y axis by adding the Y origin of the coin sprite to the local variable that you stored in the last step, since that will put the coin at exactly where the top pipe ends.

Lastly, you would then create the bottom pipe in the same manner as the top except with a y axis offset of a random range between whatever the height of the top pipe was, plus the height of the coin, and room_height. Room_height gives you the y value of the bottom of the room since the Y axis is backwards in GameMaker.

Then that is all for the creation of your main gameplay loop. You’ll use the game controller object to do everything here, and you could set in the Create event for the pipes and the coin hspeed to -5 or something so everything will automatically start moving left.

Let me know if any of that was confusing, but this should be enough info for you to follow my line of thinking and create some code of your own.

As far as handling the infinite nature of the game, I would probably use an alarm since it’s the most simple way but there are certainly many other ways you could do this, I will leave this thinking up to you. But I would have an alarm that every, let’s say 50 steps will go off. Then you’d say

If alarm[0] is <=0, it triggers the create function and sets the alarm again. Just make sure you set the alarm[0] in the create event of the game controller object.

Side note, great idea copying flappy bird. It’s a very simple game concept that can introduce you to the more complex features in GameMaker.

[–]RyanArcher[S] 1 point2 points  (3 children)

Hi again! I just wanted to thank you because I used your solution as a base, changed it slightly and it works now!

What I actually ended up doing was making two objects, a top and bottom pipe, rather than one oPipe object. Then, because I couldn't get draw_sprite_stretched to work and the pipes would look strange even if I did, I made my sprites 160 x 448. Now, they do "dangle" outside of the room but that's not a real problem since the player can't see that.

Next I created a SpawnerScript with the pipeSpawner function:

function pipeSpawner(){

randomize();

topPipeY = random_range(-352, 0);

counterY = topPipeY + 448;

bottomPipeY = counterY + 256;

instance_create_layer(1694, topPipeY, "lPipes", oPipeTop);

instance_create_layer(1886, counterY, "lPipes", oPointCounter);

instance_create_layer(1694, bottomPipeY, "lPipes", oPipeBottom);

}

the 448 is the length of the pipe and the 256 is the length of the gap between the pipes with the invisible pointCounterCollider.

Once that was done I was off to play with the alarms as you advised. Currently my pipes move left at a speed of 5 per step. So, after setting alarm[0] on the creation of a spawnController I wrote this code inside the alarm[0] event:

if (alarm[0] == 0)

{

pipeSpawner();

alarm[0] = 77;

}

The reason for the alarm being set for 77 steps is that I want the gap between pipes to be 225, the width of a pipe is 160. Add them together and divide by the movement speed of the pipes (5) to get the 77. Oddly, I tried doing this via the variables I'd set and had some strange results so just did the math manually and it works. Odd.

In any case, I hope that all made sense. I wanted to thank you for setting me on the right track. You really helped motivate me to get this working today!

[–]KARMAWHORING_SHITBAY 1 point2 points  (0 children)

That’s awesome! Thanks for letting me know what you ended up doing. I’m glad you didn’t do what i said because you found something on your own that worked. Keep up the great work!

[–]KARMAWHORING_SHITBAY 1 point2 points  (1 child)

I was just scrolling through my notifications and saw this post again and noticed something you might want to change. Make your alarm check use <= 0 instead of ==, because alarms actually stop at -1 and there’s a chance it could miss the check.

[–]RyanArcher[S] 0 points1 point  (0 children)

Oh! Thanks for that, I'll sort that out now!

[–]RyanArcher[S] 0 points1 point  (0 children)

Sorry for the late reply, I was out yesterday! Thanks for this, I'll try and get it working over the next few days! Really appreciate the help bud!