Java Code Examples for org.newdawn.slick.Image#getSubImage()

The following examples show how to use org.newdawn.slick.Image#getSubImage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageCornerTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	image = new Image("testdata/logo.png");
	
	width = image.getWidth() / 3;
	height = image.getHeight() / 3;
	
	images = new Image[] {
			image.getSubImage(0, 0, width, height), image.getSubImage(width,0,width,height), image.getSubImage(width*2,0,width,height),
			image.getSubImage(0, height, width, height), image.getSubImage(width,height,width,height), image.getSubImage(width*2,height,width,height),
			image.getSubImage(0, height*2, width, height), image.getSubImage(width,height*2,width,height), image.getSubImage(width*2,height*2,width,height),
	};
	
	images[0].setColor(Image.BOTTOM_RIGHT, 0,1,1,1);
	images[1].setColor(Image.BOTTOM_LEFT, 0,1,1,1);
	images[1].setColor(Image.BOTTOM_RIGHT, 0,1,1,1);
	images[2].setColor(Image.BOTTOM_LEFT, 0,1,1,1);
	images[3].setColor(Image.TOP_RIGHT, 0,1,1,1);
	images[3].setColor(Image.BOTTOM_RIGHT, 0,1,1,1);
	
	images[4].setColor(Image.TOP_RIGHT, 0,1,1,1);
	images[4].setColor(Image.TOP_LEFT, 0,1,1,1);
	images[4].setColor(Image.BOTTOM_LEFT, 0,1,1,1);
	images[4].setColor(Image.BOTTOM_RIGHT, 0,1,1,1);
	images[5].setColor(Image.TOP_LEFT, 0,1,1,1);
	images[5].setColor(Image.BOTTOM_LEFT, 0,1,1,1);
	
	images[6].setColor(Image.TOP_RIGHT, 0,1,1,1);
	images[7].setColor(Image.TOP_RIGHT, 0,1,1,1);
	images[7].setColor(Image.TOP_LEFT, 0,1,1,1);
	images[8].setColor(Image.TOP_LEFT, 0,1,1,1);
}
 
Example 2
Source File: Spinner.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw(Graphics g, int trackPosition, float mirrorAngle) {
	if (mirrorAngle != 0f) {
		return;
	}
	// only draw spinners shortly before start time
	int timeDiff = hitObject.getTime() - trackPosition;
	final int fadeInTime = gameState.getFadeInTime();
	if (timeDiff - fadeInTime > 0)
		return;

	boolean spinnerComplete = (rotations >= rotationsNeeded);
	float alpha = Utils.clamp(1 - (float) timeDiff / fadeInTime, 0f, 1f);

	// darken screen
	if (SkinService.skin.isSpinnerFadePlayfield()) {
		float oldAlpha = Colors.BLACK_ALPHA.a;
		if (timeDiff > 0)
			Colors.BLACK_ALPHA.a *= alpha;
		g.setColor(Colors.BLACK_ALPHA);
		g.fillRect(0, 0, width, height);
		Colors.BLACK_ALPHA.a = oldAlpha;
	}

	// rpm
	Image rpmImg = GameImage.SPINNER_RPM.getImage();
	rpmImg.setAlpha(alpha);
	rpmImg.drawCentered(width2, height - rpmImg.getHeight() / 2f);
	if (timeDiff < 0)
		data.drawSymbolString(Integer.toString(drawnRPM), (width + rpmImg.getWidth() * 0.95f) / 2f,
				height - data.getScoreSymbolImage('0').getHeight() * 1.025f, 1f, 1f, true);

	// spinner meter (subimage)
	Image spinnerMetre = GameImage.SPINNER_METRE.getImage();
	int spinnerMetreY = (spinnerComplete) ? 0 : (int) (spinnerMetre.getHeight() * (1 - (rotations / rotationsNeeded)));
	Image spinnerMetreSub = spinnerMetre.getSubImage(
			0, spinnerMetreY,
			spinnerMetre.getWidth(), spinnerMetre.getHeight() - spinnerMetreY
	);
	spinnerMetreSub.setAlpha(alpha);
	spinnerMetreSub.draw(0, height - spinnerMetreSub.getHeight());

	// main spinner elements
	GameImage.SPINNER_CIRCLE.getImage().setAlpha(alpha);
	GameImage.SPINNER_CIRCLE.getImage().setRotation(drawRotation * 360f);
	GameImage.SPINNER_CIRCLE.getImage().drawCentered(width2, height2);
	if (!GameMod.HIDDEN.isActive()) {
		float approachScale = 1 - Utils.clamp(((float) timeDiff / (hitObject.getTime() - hitObject.getEndTime())), 0f, 1f);
		Image approachCircleScaled = GameImage.SPINNER_APPROACHCIRCLE.getImage().getScaledCopy(approachScale);
		approachCircleScaled.setAlpha(alpha);
		approachCircleScaled.drawCentered(width2, height2);
	}
	GameImage.SPINNER_SPIN.getImage().setAlpha(alpha);
	GameImage.SPINNER_SPIN.getImage().drawCentered(width2, height * 3 / 4);

	if (spinnerComplete) {
		GameImage.SPINNER_CLEAR.getImage().drawCentered(width2, height / 4);
		int extraRotations = (int) (rotations - rotationsNeeded);
		if (extraRotations > 0)
			data.drawSymbolNumber(extraRotations * 1000, width2, height * 2 / 3, 1f, 1f);
	}
}
 
Example 3
Source File: Spinner.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw(Graphics g, int trackPosition) {
	// only draw spinners shortly before start time
	int timeDiff = hitObject.getTime() - trackPosition;
	final int fadeInTime = game.getFadeInTime();
	if (timeDiff - fadeInTime > 0)
		return;

	boolean spinnerComplete = (rotations >= rotationsNeeded);
	float alpha = Utils.clamp(1 - (float) timeDiff / fadeInTime, 0f, 1f);

	// darken screen
	if (Options.getSkin().isSpinnerFadePlayfield()) {
		float oldAlpha = Colors.BLACK_ALPHA.a;
		if (timeDiff > 0)
			Colors.BLACK_ALPHA.a *= alpha;
		g.setColor(Colors.BLACK_ALPHA);
		g.fillRect(0, 0, width, height);
		Colors.BLACK_ALPHA.a = oldAlpha;
	}

	// rpm
	Image rpmImg = GameImage.SPINNER_RPM.getImage();
	rpmImg.setAlpha(alpha);
	rpmImg.drawCentered(width / 2f, height - rpmImg.getHeight() / 2f);
	if (timeDiff < 0)
		data.drawSymbolString(Integer.toString(drawnRPM), (width + rpmImg.getWidth() * 0.95f) / 2f,
				height - data.getScoreSymbolImage('0').getHeight() * 1.025f, 1f, 1f, true);

	// spinner meter (subimage)
	Image spinnerMetre = GameImage.SPINNER_METRE.getImage();
	int spinnerMetreY = (spinnerComplete) ? 0 : (int) (spinnerMetre.getHeight() * (1 - (rotations / rotationsNeeded)));
	Image spinnerMetreSub = spinnerMetre.getSubImage(
			0, spinnerMetreY,
			spinnerMetre.getWidth(), spinnerMetre.getHeight() - spinnerMetreY
	);
	spinnerMetreSub.setAlpha(alpha);
	spinnerMetreSub.draw(0, height - spinnerMetreSub.getHeight());

	// main spinner elements
	GameImage.SPINNER_CIRCLE.getImage().setAlpha(alpha);
	GameImage.SPINNER_CIRCLE.getImage().setRotation(drawRotation * 360f);
	GameImage.SPINNER_CIRCLE.getImage().drawCentered(width / 2, height / 2);
	if (!GameMod.HIDDEN.isActive()) {
		float approachScale = 1 - Utils.clamp(((float) timeDiff / (hitObject.getTime() - hitObject.getEndTime())), 0f, 1f);
		Image approachCircleScaled = GameImage.SPINNER_APPROACHCIRCLE.getImage().getScaledCopy(approachScale);
		approachCircleScaled.setAlpha(alpha);
		approachCircleScaled.drawCentered(width / 2, height / 2);
	}
	GameImage.SPINNER_SPIN.getImage().setAlpha(alpha);
	GameImage.SPINNER_SPIN.getImage().drawCentered(width / 2, height * 3 / 4);

	if (spinnerComplete) {
		GameImage.SPINNER_CLEAR.getImage().drawCentered(width / 2, height / 4);
		int extraRotations = (int) (rotations - rotationsNeeded);
		if (extraRotations > 0)
			data.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1f, 1f);
	}
}