I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: Slith on May 23, 2015, 03:30:26 AM

Title: Creating a wave of Bullets?
Post by: Slith on May 23, 2015, 03:30:26 AM
Hi, since people on twitch don't post code in chat very often, I thought I'd sign up here! :atkWaifu:

So, here's exactly what I want:

10 seconds after my Room Start event, I want a wave of bullets appear from directly under the floor that moves up 2 blocks and then goes down again. Kinda like the cheap shots in Eat the ER, but it should look more like a wave and not like a wall of bullets. I know it shouldn't be hard to program at all, but I am new to game maker and no matter how hard I try, nothing moves or appears at all. And I tried for the past 5 hours.
Title: Re: Creating a wave of Bullets?
Post by: lawatson on May 23, 2015, 04:32:51 AM
I would suggest making 2 objects, one for a spawner and one for a bullet.

In the spawner, make an alarm event set for 500 frames. Hopefully you should be able to set an alarm (It's easy, just alarm[0]=500 in the create event)
Put this code in the alarm event:

hspeed=3 (or however fast you want it to move across the screen.);
shoot=1;

Now, create a step event too. In the step event, put this code:

if shoot=1{
instance_create(x,y,object you make for the bullet);
}


Now put the spawner in the bottom left corner and you're done!

For the bullet object, put this in the create event:

vspeed=-3; (or however fast you want it to go up)

And in the step event, put this:

if y<ystart-64{
vspeed=3; (or however fast you want it to go down)
}

And now you should be done! Have fun.
Title: Re: Creating a wave of Bullets?
Post by: ilvpag on May 23, 2015, 04:37:36 AM
This is how I would do it:

In the create event of a new cherry object I would put:

Code: [Select]
alarm[0] = offsetTime; // This changes the time of when the cherry will shoot up
image_speed = 1/15;  // This sets the animation speed of the cherry

and in the alarm0 event I would put:

Code: [Select]
speed = 3; // This WILL need adjustment to have a 2 block height and will control the speed that the cherry shoots up at
direction = 90; // This will send the cherry up
gravity = 0.2; // This WILL also need adjustment and will control the speed that the cherry falls down at

Now to get the cherries to spawn, in the same object that you have the room start event, have a create event with:

Code: [Select]
alarm[0] = room_speed * 10; // This will calculate the amount of frames it takes to reach 10 seconds

And in the alarm0 event for this object, put:

Code: [Select]
for(i=0; i<800; i+=16){
    a = instance_create(i,616,newCherry);
    a.offsetTime = i; // You can divide i by any number to change the time between the cherries
}

This should work, but if you don't have experience with alarms it might be a bit confusing and of course you should make sure the cherry is destroyed after it is completely gone from the screen, but I'll let you figure that one out on your own :P

Title: Re: Creating a wave of Bullets?
Post by: Slith on May 23, 2015, 06:49:39 AM
Thanks for the quick replys!

Ok, so I did not manage to make ilvpags method work. I am already having quite a few alarms in my room start object, so I made a new alarm[3] and copy-pasted everything like mentioned above and nothing spawned. :( Also I don't see how the wave would ever move from one side to the other. :( I just don't get it...

So I used lawatsons method, because it's easier to understand and with this method I can start from scratch in a completely unused object.

And this is how the result looked:
https://gyazo.com/f7c7580fc69406643dd6fe2db06e8b53

And then I put
Code: [Select]
gravity=0.5in the step object of my bullet (because I saw this mentioned in ilvpags post) and now I am feeling like I'm half way there!
https://gyazo.com/e77dd658c8c8ba56099a5b545cb8bc8a

But now there is the problem with the upward gravity... I tried all the numbers. 0.5, -0.5 and so on. But nothing seems to work.
Title: Re: Creating a wave of Bullets?
Post by: Sephalos on May 23, 2015, 10:41:10 AM
Is this what you were looking to do?
https://www.mediafire.com/download/fdd9y3vrin49eeu/spikeWaveExample.zip

EDIT: Ok I think I misunderstood that. If you DON'T want the wave to be spiky, then this is probably what you were trying to do...
https://www.mediafire.com/download/cw8dsdtnmj8gtdt/roundWaveExample.zip
Title: Re: Creating a wave of Bullets?
Post by: lawatson on May 23, 2015, 03:44:38 PM
But now there is the problem with the upward gravity... I tried all the numbers. 0.5, -0.5 and so on. But nothing seems to work.

It sounds like you put the gravity code into the step event where it triggers when the y is above a certain position. Put it in the create event.
Title: Re: Creating a wave of Bullets?
Post by: Slith on May 25, 2015, 05:17:22 AM
EDIT: Ok I think I misunderstood that. If you DON'T want the wave to be spiky, then this is probably what you were trying to do...
https://www.mediafire.com/download/cw8dsdtnmj8gtdt/roundWaveExample.zip

I got everything to work now and my mini avoidance fight is better than what I actually had in mind! Thanks for putting this together for me!