Legacy GM Dnd Refreshing Instances

J

Jac Thiebeau (Cyberhroom)

Guest
What would be a good solution to make blocks in a breakout/pong game respawn when the ball goes off screen or if y is less than 0. I got it right now where the instance is destroyed when the ball touches a breakable block but trying to recreate the instance with alarms is troublesome. Dnd is preferred but code also works.

Thanks in advance!
 

chamaeleon

Member
What would be a good solution to make blocks in a breakout/pong game respawn when the ball goes off screen or if y is less than 0. I got it right now where the instance is destroyed when the ball touches a breakable block but trying to recreate the instance with alarms is troublesome. Dnd is preferred but code also works.

Thanks in advance!
You could have an invisible controller object that keeps track of whether an instance of the desired type exist or not, and if it detects there is none, start a timer that controls how long to wait until spawning a new instance.
 

FrostyCat

Redemption Seeker
Start with an empty list at the beginning of the game:
Code:
global.destroyed_blocks = ds_list_create();
Then in the Destroy event of blocks, add its coordinates and object_index to the list as an array:
Code:
var entry = array_create(3);
entry[0] = x;
entry[1] = y;
entry[2] = object_index;
ds_list_add(global.destroyed_blocks, entry);
When the ball goes off the screen, loop through that list and recreate the instances as listed and clear the list (make sure NOT to trigger this continuously):
Code:
for (var i = ds_list_size(global.destroyed_blocks)-1; i >= 0; i--) {
  var entry = global.destroyed_blocks[| i];
  instance_create(entry[0], entry[1], entry[2]);
}
ds_list_clear(global.destroyed_blocks);
Remember to call ds_list_clear(global.destroyed_blocks); to wipe the list whenever the currently remembered blocks no longer apply (e.g. when starting a new level).
 
Top