how do I make it so that a power up object appears only once in the room?

pixeltroid

Member
So my game has a number of interconnected rooms and requires the player to backtrack a few times through the same room. Some rooms have power ups strewn about. The thing is, I dont want players to repeatedly re-enter the room to pick up the power ups over and over again.

Is there a way to make it so that the power up object is destroyed once its collected?
 

Bluetail7

Member
save a variable that destroys the object when going back.
another thing could be the use of persistent rooms, but I haven't tried out in a while.
 

Jakylgamer

Member
just use a global array that holds the powerup collection data
example:
Code:
global.powerup[0] = false
then change that to true on collecting it.
then in the powerup object do
Code:
if global.powerup[0] == true {
   instance_destroy()
}
 
D

deem93

Guest
The way I do it, I add an instance of an item object to a ds list, once picked up. Then, I check the list and destroy all the instances of items that happen to be on that list.
 
T

Taddio

Guest
No need for persistent rooms. Just assign an ID to each your room, and use an array like @Jakylgamer said. It doesn't even need to be global, you can just put it in a controller object.

Then you do
Code:
if(collectable_array[level_id] == 0) {
     //Spawn a collectible in that level
}
And when you collide with the collectable you do in obj_player's collision with collectable event
Code:
with(obj_containing_the_array) {
     collectible_array[level_id] = 1;
}
with(other) {
     instance_destroy();
}

score_ += collectable_score;
 
Top