In my game that I am creating, I am using blocks. To simplify my life, I created a class that accepts an array of blocks, and adds them to the block set for me.
Block set (in World class):
Set<Block> blocks = new HashSet<Block>();
BlockCollection class:
public class BlockCollection
{
private World world;
Set<Block> blocks = new HashSet<Block>();
public BlockCollection(World world, Vector2 position, Block[] blocks)
{
this.world = world;
for (Block block : blocks)
this.blocks.add(new Block(new Vector2(block.position.x + position.x, block.position.y + position.y)));
}
public void flip()
{
//Flip the set
}
public void add()
{
world.blocks.addAll(blocks);
}
}
(The library that I am using is libgdx, the Vector2 class is basically a vector with an X float and a Y float)
I added an array of blocks that looks like this:
Block[] spike = {
new Block(new Vector2(0, 0)),
new Block(new Vector2(1, 0)),
new Block(new Vector2(2, 0)),
new Block(new Vector2(3, 0)),
new Block(new Vector2(1, 1)),
new Block(new Vector2(2, 1)),
new Block(new Vector2(3, 1)),
new Block(new Vector2(1, 2)),
new Block(new Vector2(2, 2)),
new Block(new Vector2(1, 3)),
new Block(new Vector2(2, 3)),
new Block(new Vector2(1, 4)),
};
It works, but now I'm trying to add functionality to flip the set of blocks in the flip() method of the BlockCollection class. It would help me not need to hardcode every single variation of every single object I make with blocks.
Can anyone share any insight, maybe an equation, of how to do this? Any help is much appriciated.
EDIT: By flip, I mean flip the shape along the x axis, similarly to flipping an image. Example:
Original vs. Flipped
00100 | 11111
01110 | 01110
11111 | 00100