Author Topic: Creating a wave of Bullets?  (Read 2473 times)

Slith

  • Wannabe
  • Posts: 12
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 38.0 Firefox 38.0
    • View Profile
  • Playstyle: Keyboard
Creating a wave of Bullets?
« 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.
« Last Edit: May 23, 2015, 03:39:26 AM by Slith »

lawatson

  • The Kid
  • Posts: 331
  • I do things and I make things.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.65 Chrome 43.0.2357.65
    • View Profile
  • Playstyle: Keyboard
Re: Creating a wave of Bullets?
« Reply #1 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.
« Last Edit: May 23, 2015, 04:52:08 AM by lawatson »
(click to show/hide)

smoke weed everyday

ilvpag

  • Guest
Re: Creating a wave of Bullets?
« Reply #2 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


Slith

  • Wannabe
  • Posts: 12
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 38.0 Firefox 38.0
    • View Profile
  • Playstyle: Keyboard
Re: Creating a wave of Bullets?
« Reply #3 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.
« Last Edit: May 23, 2015, 07:52:41 AM by Slith »

Sephalos

  • Spike Dodger
  • Posts: 228
  • OS:
  • Windows Vista/Server 2008 Windows Vista/Server 2008
  • Browser:
  • Chrome 43.0.2357.65 Chrome 43.0.2357.65
    • View Profile
  • Playstyle: Gamepad
Re: Creating a wave of Bullets?
« Reply #4 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
« Last Edit: May 23, 2015, 11:39:31 AM by Sephalos »

lawatson

  • The Kid
  • Posts: 331
  • I do things and I make things.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 43.0.2357.65 Chrome 43.0.2357.65
    • View Profile
  • Playstyle: Keyboard
Re: Creating a wave of Bullets?
« Reply #5 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.
(click to show/hide)

smoke weed everyday

Slith

  • Wannabe
  • Posts: 12
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 38.0 Firefox 38.0
    • View Profile
  • Playstyle: Keyboard
Re: Creating a wave of Bullets?
« Reply #6 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!