• 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!

Brick breaking shrinks bricks

T

Toxicosis

Guest
Greetings again.

So, I kept working on an object-based destructible terrain, and this came up. I created a terrain that does not require a large workload to be destroyed. Let me copy the script inside the breakable's collision event.

Code:
/*This one should soften the load and create only 11 bricks.
3 to surround, and 8 in the middle. Good for ground stuff. We need 44 values, though...
First, create one object on the corner, as big as necessary to split the object in two.

Let's instead use a 4-value thing that evaluates generating one of 8 bricks, so as to account for hit area, heh.
Then generate 9, no, just 4 bricks in the center of it.

No, wait, here's a better idea, create a series of values and a smaller bounding box.
If these values are outside the object's bounding box, their object is not generated.
If they are, these objects are generated.

Once we've done that, we can generate the creamy center in the middle.*/

var edge = 256;
var top, right, left, bottom, xx, yy;
var top_block, right_block, left_block, bottom_block;
//Don't be shy with the variables.

xx = other.x;
yy = other.y;
//Where the hitting instance lies.

if xx < bbox_left xx = bbox_left;
if xx > bbox_right xx = bbox_right;
if yy < bbox_top yy = bbox_top;
if yy > bbox_bottom yy = bbox_bottom;
//Correct hitting instance so weird bugs don't show up if your shattering element is not really within the bounding box.

top = yy-bbox_top-edge;
bottom = bbox_bottom-yy-edge;
left = xx-bbox_left-edge;
right = bbox_right-xx-edge;
//The amount of room left on each side. We want the blocks created to be at least 256 units wide.

top_block = true;
bottom_block = true;
left_block = true;
right_block = true;

if top < edge top_block = false;
if bottom < edge bottom_block = false;
if left < edge left_block = false;
if right < edge right_block = false;
//If there's not enough room on any of the sides to create a block, do not create blocks on those sides.

if top_block == false top = 0;
if bottom_block == false bottom = 0;
if left_block == false left = 0;
if right_block == false right = 0;
//Adjust the other blocks to make sure there's no gaps.

//with other instance_destroy(); //Delete the punching instance so as to avoid bugs with the others.

var xleft, xmiddle, xright, ytop, ymiddle, ybottom;
xleft = bbox_left;
xmiddle = bbox_left+left;
xright = bbox_right-right;
ytop = bbox_top;
ymiddle = bbox_top+top;
ybottom = bbox_bottom-bottom;
//6 values of x and y. They will split the brick into 9 zones, each of which will generate//not generate a brick.

var sizeleft, sizemiddle, sizeright, sizetop, sizecenter, sizebottom;

sizeleft = left/sprite_get_width(sprite_index);
sizetop = top/sprite_get_height(sprite_index);
sizemiddle = (sprite_width-left-right)/sprite_get_width(sprite_index);
sizeright = right/sprite_get_width(sprite_index);
sizecenter = (sprite_height-top-bottom)/sprite_get_height(sprite_index);
sizebottom = bottom/sprite_get_height(sprite_index);
//6 scales. Each will be used in 3 bricks, if created.

//Now create each of those instances needed.
if top_block
{
  with instance_create(xmiddle,ytop,obj_break_hard)
  {
  image_xscale = sizemiddle;
  image_yscale = sizetop;
  }
  if !left_block && !right_block
  instance_create(xmiddle,ymiddle,obj_brick); //*
  if left_block
  {
  with instance_create(xleft,ytop,obj_break_hard)
  {
  image_xscale = sizeleft;
  image_yscale = sizetop;
  }
  instance_create(xmiddle,ymiddle,obj_brick); //*
  }
  if right_block
  {
  with instance_create(xright,ytop,obj_break_hard)
  {
  image_xscale = sizeright;
  image_yscale = sizetop;
  instance_create(xx,ymiddle,obj_brick); //*
  }
  }
}
if left_block
{
  with instance_create(xleft,ymiddle,obj_break_hard)
  {
  image_xscale = sizeleft;
  image_yscale = sizecenter;
  }
  if !top_block && !bottom_block
  instance_create(xmiddle,ymiddle,obj_brick); //*

}
if right_block
{
  with instance_create(xright,ymiddle,obj_break_hard)
  {
  image_xscale = sizeright;
  image_yscale = sizecenter;
  }
  if !top_block && !bottom_block
  instance_create(xx,ymiddle,obj_brick); //*
}
if bottom_block
{
  with instance_create(xmiddle,ybottom,obj_break_hard)
  {
  image_xscale = sizemiddle;
  image_yscale = sizebottom;
  }
  if !left_block && !right_block
  instance_create(xmiddle,yy,obj_brick); //*
  if left_block
  {
  with instance_create(xleft,ybottom,obj_break_hard)
  {
  image_xscale = sizeleft;
  image_yscale = sizebottom;
  instance_create(xmiddle,yy,obj_brick); //*
  }
  }
  if right_block
  {
  with instance_create(xright,ybottom,obj_break_hard)
  {
  image_xscale = sizeright;
  image_yscale = sizebottom;
  instance_create(xx,yy,obj_brick); //*
  }
  }
}


//Finally, destroy the calling block.
instance_destroy();

//Use sprite_get_height for the sprite itself, sprite_height for the current.
My problem is that when I hit one of those bricks from the left or the top, the right edge of the right block and the bottom edge of the bottom block both lose one pixel. That is extremely annoying, and if I don't fix it, then upon destruction, the bricks have this "light" on the edge that makes it too easy to remember the game's just a program. Furthermore, the gap compounds: I've gone punching through a long wall, and by the time I'm near the end, the right side of the brick I'm eating through is several pixels away from the next brick.

Is there any way in which I could make sure the bricks don't form gaps while being broken up? I don't want them to be aligned to the right side either, or else the gap would show up right where the player is looking.

I'm gonna try adding 1 pixel to the right and bottom sides, and see what happens. In the meantime, anyone had a problem like this?

EDIT: the extra pixel was exactly what I needed, nevermind.
 
Last edited by a moderator:
Top