GML [Solved] Random powerup spawn

T

tobii

Guest
hey guys,

so i am making an old school kinda like space invaders as my first ever game since i have no past exp in coding or even game coding, but i am stuck and i have tried a lot of diff things to do this but none of them worked.

So how it should works is after a set of time (random time) it should spawn a new game object called obj_powerup but it does nothing plus i found a way to make it work but i spawn so many power-ups that my game just lagged out.

I am out of stuff to try so if anyone would be able to help that would be awesome and i will learn from it as well!

Thanks!
 
I would need to see some of your code. But my first instinct is
Code:
//create event
cooldownTime = irandom_range(mintime,maxtime);
alarm_set(0,cooldownTime);


//alarm0 event
var xx = irandom(room_width);
var yy = -10;
instance_create(xx,yy,depth,obj_powerup);
cooldownTime = irandom_range(mintime,maxtime);
alarm_set(0,cooldownTime);
This assumes that powerups fall from the top to the bottom. Make sure you have a check on the power up to destroy itself if it gets past the bottom of the room.
 
T

tobii

Guest
i was using this as my last code

Code:
//create event

SpawnTime = irandom_range(1000,1500);
alarm[0] = SpawnTime

//alarm event
var _x_range = irandom (room_width);
var y_range = irandom (room_height);

instance_create_layer (_x_range, y_range, "Instances", obj_powerup);
thinking about your last lines that this is what i forgot to make it not spawn so many at once that my game crashed i just forgot to add it to my alarm step then? and the powerup is just spawning in the room not falling down for now :)
 
Are you running that code in the powerup object? If so it will create them exponentially. If its a spawn object and the powerups don't have that code it should work. Just throw in resetting the alarm and it should loop infinitely while the game runs. Also remember the default room speed is 30 steps per second. If its in a spawn object is it in the room?
 
T

tobii

Guest
Are you running that code in the powerup object? If so it will create them exponentially. If its a spawn object and the powerups don't have that code it should work. Just throw in resetting the alarm and it should loop infinitely while the game runs. Also remember the default room speed is 30 steps per second. If its in a spawn object is it in the room?
i am running the code in the powerup object yes, i am using the trial version for now so i am keeping them like that but it seems to work now when i added the last part of your code to it :)
now i will try to add a health power up that adds 1 HP to my ship on pickup should not be to hard since it works now! thank you!
 
Top