All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mmb.engine.rotate.RotatedImageGroup Maven / Gradle / Ivy

Go to download

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<

There is a newer version: 0.6
Show newest version
/**
 * 
 */
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 RotatedImageGroup {
	@NN public final BlockDrawer U, D, L ,R;
	public RotatedImageGroup(BlockDrawer u, BlockDrawer d, BlockDrawer l, BlockDrawer r) {
		U = u;
		D = d;
		L = l;
		R = r;
	}
	public BlockDrawer get(Rotation r) {
		switch(r) {
		case S:
			return D;
		case W:
			return L;
		case E:
			return R;
		default:
			return U;
		}
	}
	@NN public static RotatedImageGroup create(BufferedImage img) {
		BlockDrawer U = BlockDrawer.ofImage(img);
		BufferedImage progress = rotate(img);
		BlockDrawer R = BlockDrawer.ofImage(progress);
		progress = rotate(progress);
		BlockDrawer D = BlockDrawer.ofImage(progress);
		progress = rotate(progress);
		BlockDrawer L = BlockDrawer.ofImage(progress);
		return new RotatedImageGroup(U, D, L, R);
	}
	/**
	 * Rotates this rotated image group backwards
	 * @return sbackwards RIG
	 */
	@NN public RotatedImageGroup flip() {
		return new RotatedImageGroup(D, U, R, L);
	}
	@NN public static RotatedImageGroup create(String texture) {
		return create(Textures.get(texture));
	}
	static BufferedImage rotate(BufferedImage img) {
		int type = img.getType();
		if(type == 0) type = 5;
		BufferedImage result = new BufferedImage(32, 32, type);
		for(int i = 0; i < 32; i++) {
			for(int j = 0; j < 32; j++) {
				result.setRGB(31-j, i, img.getRGB(i, j));
			}
		}
		return result;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy