mmb.engine.rotate.ChirotatedImageGroup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package mmb.engine.rotate;
import java.awt.image.BufferedImage;
import mmb.NN;
import mmb.engine.texture.BlockDrawer;
import mmb.engine.texture.Textures;
/**
* @author oskar
*
*/
public class ChirotatedImageGroup {
/**
* @param rotation rotation of image
* @param chirality chirality of image
* @return the image with given rotation and chirality
*/
public BlockDrawer get(Rotation rotation, Chirality chirality) {
switch(rotation) {
case S:
return (chirality == Chirality.L) ? Dl : Dr;
case W:
return (chirality == Chirality.L) ? Ll : Lr;
case E:
return (chirality == Chirality.L) ? Rl : Rr;
default:
return (chirality == Chirality.L) ? Ul : Ur;
}
}
public BlockDrawer Ul, Dl, Ll, Rl, Ur, Dr, Lr, Rr;
@NN public static ChirotatedImageGroup create(BufferedImage img) {
ChirotatedImageGroup rig = new ChirotatedImageGroup();
rig.Ur = BlockDrawer.ofImage(img);
BufferedImage progress = RotatedImageGroup.rotate(img);
rig.Rr = BlockDrawer.ofImage(progress);
progress = RotatedImageGroup.rotate(progress);
rig.Dr = BlockDrawer.ofImage(progress);
progress = RotatedImageGroup.rotate(progress);
rig.Lr = BlockDrawer.ofImage(progress);
progress = flip(img);
rig.Ul = BlockDrawer.ofImage(progress);
progress = RotatedImageGroup.rotate(progress);
rig.Rl = BlockDrawer.ofImage(progress);
progress = RotatedImageGroup.rotate(progress);
rig.Dl = BlockDrawer.ofImage(progress);
progress = RotatedImageGroup.rotate(progress);
rig.Ll = BlockDrawer.ofImage(progress);
return rig;
}
@NN public static ChirotatedImageGroup create(String texture) {
return create(Textures.get(texture));
}
static BufferedImage flip(BufferedImage img) {
BufferedImage result = new BufferedImage(32, 32, img.getType());
for(int i = 0; i < 32; i++) {
for(int j = 0; j < 32; j++) {
result.setRGB(31-i, j, img.getRGB(i, j));
}
}
return result;
}
}