• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

360° shot, I need help!

P

Pablo Reese

Guest
Hey guys, I'm making a game in which one one the first enemies you encounter are slimes that, every few seconds, fire shots in all 360°. What I want to do is have code like this:

Code:
if(slideCount = 3)
{
repeat(360)
{
bullet = instance_create(x,y,obj_blueSlimeBullet);
bullet.direction = dir;
bullet.speed = bulletSpeed;
dir += 1;
}
slideCount = 0;
}
The problem is instead of repeat i want something that executes 360 all in the same step. I could copy and paste the instance_create stuff 360 times but that is so impractical. Any help is greatly appreciated! Thank you!
 

Jezla

Member
Repeat will execute in the same step, but since you're changing dir each time, a for loop would suit you better.
 

Fredrik

Member
make the slime's direction increase all the time, like:
direction = dir;
dir += 1;

^ the direction of the object will spin around in loop until you stop it.

In the shot object (bullet, or whatever)
set a variable in it's create event printing the slime's direction in the exact moment the bullet was created, like:
direction = obj_slime.direction;¨
speed = 10;

^ this will pretty much make the bullet move in what the slime's direction was when that spesific bullet was created.


obj_slime:
Create Event

dir = 0;
direction = 0;
alarm[0] = 1;

alarm 0
instance_create(x,y,obj_bullet);

Step Event
dir += 1;
direction = dir;

obj_bullet:
Create Event:

direction = obj_slime.dir;
speed = 10;
alarm[0] = 100;

Alarm 0
instance_destroy();

It shouldn't really be any harder than that.
Ofc if you don't want the slime to spawn 10 bullets each second (alarm[0] = 1;) you can just always increase the alarm number.
 
Last edited:
Hey guys, I'm making a game in which one one the first enemies you encounter are slimes that, every few seconds, fire shots in all 360°. What I want to do is have code like this:

Code:
if(slideCount = 3)
{
repeat(360)
{
bullet = instance_create(x,y,obj_blueSlimeBullet);
bullet.direction = dir;
bullet.speed = bulletSpeed;
dir += 1;
}
slideCount = 0;
}
The problem is instead of repeat i want something that executes 360 all in the same step. I could copy and paste the instance_create stuff 360 times but that is so impractical. Any help is greatly appreciated! Thank you!
repeat will execute all 360 in the same step.
 
Top