Fangames > Programming Questions

Creating a wave of Bullets?

(1/2) > >>

Slith:
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.

lawatson:
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.

ilvpag:
This is how I would do it:

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


--- Code: ---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

--- End code ---

and in the alarm0 event I would put:


--- Code: ---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
--- End code ---

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


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

--- End code ---

And in the alarm0 event for this object, put:


--- Code: ---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
}

--- End code ---

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

Slith:
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: ---gravity=0.5
--- End code ---
in 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.

Sephalos:
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

Navigation

[0] Message Index

[#] Next page

Go to full version