Java Code Examples for org.newdawn.slick.Graphics#pushTransform()

The following examples show how to use org.newdawn.slick.Graphics#pushTransform() . These examples are extracted from open source projects. 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
/**
 * Renders this key.
 * @param g the graphics context
 * @param x the x position
 * @param y the y position
 * @param baseImage the key image
 */
public void render(Graphics g, int x, int y, Image baseImage) {
	g.pushTransform();
	float scale = 1f;
	if (downtime > 0) {
		float progress = downtime / (float) ANIMATION_TIME;
		scale -= (1f - ACTIVE_SCALE) * progress;
		g.scale(scale, scale);
		x /= scale;
		y /= scale;
	}
	baseImage.drawCentered(x, y, down ? activeColor : Color.white);
	x -= Fonts.MEDIUMBOLD.getWidth(text) / 2;
	y -= Fonts.MEDIUMBOLD.getLineHeight() / 2;
	/*
	// shadow (TODO)
	g.pushTransform();
	g.scale(1.1f, 1.1f);
	float shadowx = x / 1.1f - Fonts.MEDIUMBOLD.getWidth(text) * 0.05f;
	float shadowy = y / 1.1f - Fonts.MEDIUMBOLD.getLineHeight() * 0.05f;
	Fonts.MEDIUMBOLD.drawString(shadowx, shadowy, text, Color.black);
	g.popTransform();
	*/
	Fonts.MEDIUMBOLD.drawString(x, y, text, Options.getSkin().getInputOverlayText());
	g.popTransform();
}
 
Example 2
Source Project: opsu-dance   File: Circle.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw(Graphics g, int trackPosition, float mirrorAngle) {
	Color orig = color;
	if (mirrorAngle != 0f) {
		color = mirrorColor;
	}

	int timeDiff = hitObject.getTime() - trackPosition;
	final int approachTime = gameState.getApproachTime();
	final int fadeInTime = gameState.getFadeInTime();
	float scale = timeDiff / (float) approachTime;
	float approachScale = 1 + scale * 3;
	float fadeinScale = (timeDiff - approachTime + fadeInTime) / (float) fadeInTime;
	float alpha = Utils.clamp(1 - fadeinScale, 0, 1);

	g.pushTransform();
	if (mirrorAngle != 0f) {
		g.rotate(x, y, mirrorAngle);
	}

	if (GameMod.HIDDEN.isActive()) {
		final int hiddenDecayTime = gameState.getHiddenDecayTime();
		final int hiddenTimeDiff = gameState.getHiddenTimeDiff();
		if (fadeinScale <= 0f && timeDiff < hiddenTimeDiff + hiddenDecayTime) {
			float hiddenAlpha = (timeDiff < hiddenTimeDiff) ? 0f : (timeDiff - hiddenTimeDiff) / (float) hiddenDecayTime;
			alpha = Math.min(alpha, hiddenAlpha);
		}
	}

	float oldAlpha = Colors.WHITE_FADE.a;
	Colors.WHITE_FADE.a = color.a = alpha;

	if (timeDiff >= 0) {
		gameObjectRenderer.renderApproachCircle(x, y, color, approachScale);
	}
	gameObjectRenderer.renderHitCircle(x, y, color, hitObject.getComboNumber(), alpha);

	Colors.WHITE_FADE.a = oldAlpha;

	g.popTransform();
	color = orig;
}
 
Example 3
Source Project: opsu-dance   File: Slider.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws slider ticks.
 * @param g graphics
 * @param trackPosition the track position
 * @param curveAlpha the curve alpha level
 * @param decorationsAlpha the decorations alpha level
 */
private void drawSliderTicks(Graphics g, int trackPosition, float curveAlpha, float decorationsAlpha, float mirrorAngle) {
	float tickScale = 0.5f + 0.5f * AnimationEquation.OUT_BACK.calc(decorationsAlpha);
	Image tick = GameImage.SLIDER_TICK.getImage().getScaledCopy(tickScale);

	// calculate which ticks need to be drawn (don't draw if sliderball crossed it)
	int min = 0;
	int max = ticksT.length;
	if (trackPosition > getTime()) {
		for (int i = 0; i < ticksT.length; ) {
			if (((trackPosition - getTime()) % sliderTime) / sliderTime < ticksT[i]) {
				break;
			}
			min = ++i;
		}
	}
	if (currentRepeats % 2 == 1) {
		max -= min;
		min = 0;
	}

	// calculate the tick alpha level
	float sliderTickAlpha;
	if (currentRepeats == 0) {
		sliderTickAlpha = decorationsAlpha;
	} else {
		float t = getT(trackPosition, false);
		if (currentRepeats % 2 == 1) {
			t = 1f - t;
		}
		sliderTickAlpha = Utils.clamp(t * ticksT.length * 2, 0f, 1f);
	}

	// draw ticks
	Colors.WHITE_FADE.a = Math.min(curveAlpha, sliderTickAlpha);
	for (int i = min; i < max; i++) {
		Vec2f c = curve.pointAt(ticksT[i]);
		g.pushTransform();
		if (mirrorAngle != 0f) {
			g.rotate(c.x, c.y, mirrorAngle);
		}
		tick.drawCentered(c.x, c.y, Colors.WHITE_FADE);
		g.popTransform();
	}
}
 
Example 4
Source Project: opsu   File: Game.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws hit objects, hit results, and follow points.
 * @param g the graphics context
 * @param trackPosition the track position
 */
private void drawHitObjects(Graphics g, int trackPosition) {
	// draw result objects (under)
	data.drawHitResults(trackPosition, false);

	// include previous object in follow points
	int lastObjectIndex = -1;
	if (objectIndex > 0 && objectIndex < beatmap.objects.length &&
	    trackPosition < beatmap.objects[objectIndex].getTime() && !beatmap.objects[objectIndex - 1].isSpinner())
		lastObjectIndex = objectIndex - 1;

	boolean loseState = (playState == PlayState.LOSE);
	if (loseState)
		trackPosition = failTrackTime + (int) (System.currentTimeMillis() - failTime);

	// draw merged slider
	if (!loseState && mergedSlider != null && Options.isExperimentalSliderMerging()) {
		mergedSlider.draw(Color.white);
		mergedSlider.clearPoints();
	}

	// get hit objects in reverse order, or else overlapping objects are unreadable
	Stack<Integer> stack = new Stack<Integer>();
	int spinnerIndex = -1;  // draw spinner first (assume there can only be 1...)
	for (int index : passedObjects) {
		if (beatmap.objects[index].isSpinner()) {
			if (spinnerIndex == -1)
				spinnerIndex = index;
		} else
			stack.add(index);
	}
	for (int index = objectIndex; index < gameObjects.length && beatmap.objects[index].getTime() < trackPosition + approachTime; index++) {
		if (beatmap.objects[index].isSpinner()) {
			if (spinnerIndex == -1)
				spinnerIndex = index;
		} else
			stack.add(index);

		// draw follow points
		if (Options.isFollowPointEnabled() && !loseState)
			lastObjectIndex = drawFollowPointsBetween(objectIndex, lastObjectIndex, trackPosition);
	}
	if (spinnerIndex != -1)
		stack.add(spinnerIndex);

	// draw hit objects
	while (!stack.isEmpty()){
		int idx = stack.pop();
		GameObject gameObj = gameObjects[idx];

		// normal case
		if (!loseState)
			gameObj.draw(g, trackPosition);

		// death: make objects "fall" off the screen
		else {
			// time the object began falling
			int objTime = Math.max(beatmap.objects[idx].getTime() - approachTime, failTrackTime);
			float dt = (trackPosition - objTime) / (float) (MUSIC_FADEOUT_TIME);

			// would the object already be visible?
			if (dt <= 0)
				continue;

			// generate rotation speeds for each objects
			final float rotSpeed;
			if (rotations.containsKey(gameObj)) {
				rotSpeed = rotations.get(gameObj);
			} else {
				rotSpeed = (float) (2.0f * (Math.random() - 0.5f) * MAX_ROTATION);
				rotations.put(gameObj, rotSpeed);
			}

			g.pushTransform();

			// translate and rotate the object
			g.translate(0, dt * dt * container.getHeight());
			Vec2f rotationCenter = gameObj.getPointAt((beatmap.objects[idx].getTime() + beatmap.objects[idx].getEndTime()) / 2);
			g.rotate(rotationCenter.x, rotationCenter.y, rotSpeed * dt);
			gameObj.draw(g, trackPosition);

			g.popTransform();
		}
	}

	// draw result objects (over)
	data.drawHitResults(trackPosition, true);
}
 
Example 5
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	g.setColor(Color.white);
	g.drawString("Red indicates a collision, green indicates no collision", 50, 420);
       g.drawString("White are the targets", 50, 435);

       g.pushTransform();
       g.translate(100,100);
       g.pushTransform();
       g.translate(-50,-50);
       g.scale(10, 10);
       g.setColor(Color.red);
       g.fillRect(0,0,5,5);
       g.setColor(Color.white);
       g.drawRect(0,0,5,5);
       g.popTransform();
       g.setColor(Color.green);
       g.fillRect(20,20,50,50);
       g.popTransform();
       
	g.setColor(Color.white);
	g.draw(rect);
	g.draw(circle);
	
	g.setColor(rect1.intersects(rect) ? Color.red : Color.green);
	g.draw(rect1);
	g.setColor(rect2.intersects(rect) ? Color.red : Color.green);
	g.draw(rect2);
       g.setColor(roundRect.intersects(rect) ? Color.red : Color.green);
       g.draw(roundRect);
	g.setColor(circle1.intersects(rect) ? Color.red : Color.green);
	g.draw(circle1);
	g.setColor(circle2.intersects(rect) ? Color.red : Color.green);
	g.draw(circle2);
	g.setColor(circle3.intersects(circle) ? Color.red : Color.green);
	g.fill(circle3);
	g.setColor(circle4.intersects(circle) ? Color.red : Color.green);
	g.draw(circle4);

       g.fill(roundRect2);
	g.setColor(Color.blue);
       g.draw(roundRect2);
	g.setColor(Color.blue);
	g.draw(new Circle(100,100,50));
	g.drawRect(50,50,100,100);
       
}