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

The following examples show how to use org.newdawn.slick.Graphics#translate() . 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
/**
 * @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void preRender(StateBasedGame game, GameContainer container,
		Graphics g) throws SlickException {
	if (moveBackDone) {
		g.translate(xp1,yp1);
		g.scale(scale1, scale1);
		g.setClip((int) xp1,(int) yp1,(int) (scale1*container.getWidth()),(int) (scale1*container.getHeight()));
		prev.render(container, game, g);
		g.resetTransform();
		g.clearClip();
	}
	
	g.translate(xp2,yp2);
	g.scale(scale2, scale2);
	g.setClip((int) xp2,(int) yp2,(int) (scale2*container.getWidth()),(int) (scale2*container.getHeight()));
}
 
Example 2
/**
 * @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
	g.translate(container.getWidth()/2, container.getHeight()/2);
	g.scale(scale,scale);
	g.rotate(0, 0, ang);
	g.translate(-container.getWidth()/2, -container.getHeight()/2);
	if (background != null) {
		Color c = g.getColor();
		g.setColor(background);
		g.fillRect(0,0,container.getWidth(),container.getHeight());
		g.setColor(c);
	}
	prev.render(container, game, g);
	g.translate(container.getWidth()/2, container.getHeight()/2);
	g.rotate(0, 0, -ang);
	g.scale(1/scale,1/scale);
	g.translate(-container.getWidth()/2, -container.getHeight()/2);
}
 
Example 3
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	g.drawString("T - TGA Snapshot", 10,50);
	g.drawString("J - JPG Snapshot", 10,70);
	g.drawString("P - PNG Snapshot", 10,90);

	g.setDrawMode(Graphics.MODE_ADD);
	g.drawImage(copy, 200, 300);
	g.setDrawMode(Graphics.MODE_NORMAL);
	
	g.drawString(message, 10,400);
	g.drawRect(200,0,400,300);
	g.translate(400, 250);
	fire.render();
	this.g = g;
}
 
Example 4
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer contiainer, Graphics g) {
   g.translate(320,240);
   
   g.translate( -camX * scale, -camY * scale);
   
         
   g.scale(scale, scale);

   g.setColor(Color.red);
   for (int x=0;x<10;x++) {
      for (int y=0;y<10;y++) {
         g.fillRect(-500+(x*100), -500+(y*100), 80, 80);
      }
   }
   
   g.setColor(new Color(1,1,1,0.5f));
   g.fillRect(-320,-240,640,480);
   g.setColor(Color.white);
   g.drawRect(-320,-240,640,480);
}
 
Example 5
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	g.drawString("R - Toggle Rotationg",10,50);
	g.drawImage(image1, 100, 236);
	g.drawImage(image2, 600, 236);
	
	g.translate(0, -150);
	g.rotate(400, 300, ang);
	g.texture(shape, image2);
	g.texture(shape, image1, fill);
	g.resetTransform();
	
	g.translate(0, 150);
	g.rotate(400, 300, ang);
	g.texture(poly, image2);
	g.texture(poly, image1, fill);
	g.resetTransform();
}
 
Example 6
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	image.draw(0,0);
	image.draw(500,0,200,100);
	scaleMe.draw(500,100,200,100);
	scaled.draw(400,500);
	Image flipped = scaled.getFlippedCopy(true, false);
	flipped.draw(520,500);
	Image flipped2 = flipped.getFlippedCopy(false, true);
	flipped2.draw(520,380);
	Image flipped3 = flipped2.getFlippedCopy(true, false);
	flipped3.draw(400,380);
	
	for (int i=0;i<3;i++) {
		subImage.draw(200+(i*30),300);
	}
	
	g.translate(500, 200);
	g.rotate(50, 50, rot);
	g.scale(0.3f,0.3f);
	image.draw();
	g.resetTransform();
}
 
Example 7
/**
	 * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
	 */
	public void render(GameContainer container, Graphics g) throws SlickException {
		g.scale(zoom,zoom);
		g.translate(x, y);
		g.scale(0.3f,0.3f);
		//renderer[0].render(g);
		g.scale(1/0.3f,1/0.3f);
		g.translate(400, 0);
		//renderer[1].render(g);
		g.translate(100, 300);
		g.scale(0.7f,0.7f);
		//renderer[2].render(g);
		g.scale(1/0.7f,1/0.7f);
		
		g.scale(0.5f,0.5f);
		g.translate(-1100, -380);
		renderer[3].render(g);
		g.scale(1/0.5f,1/0.5f);
		
//		g.translate(280, 100);
//		g.scale(0.5f,0.5f);
//		renderer[4].render(g);
		
		g.resetTransform();
	}
 
Example 8
public void render(Graphics g)
{
	Rectangle oldClip = g.getClip();
	g.setWorldClip(x,y,width, height);
	
	// Someone could have set a color for me to blend...
	Color clr = g.getColor();

	if (backgroundCol != null) {
		g.setColor(backgroundCol.multiply(clr));
		g.fillRect(x, y, width, height);
	}
	g.setColor(textCol.multiply(clr));
	Font temp = g.getFont();

	int cursorpos = font.getWidth(value);
	int tx = 0;
	if (cursorpos > width) {
		tx = width - cursorpos - font.getWidth("_");
	}

	g.translate(tx + 2, 0);
	g.setFont(font);
	g.drawString(value, x + 1, y + 1);

	if (focused) {
		g.drawString("|", x + cursorpos, y + 1);
	}

	g.translate(-tx - 2, 0);

	if (borderCol != null) {
		g.setColor(borderCol.multiply(clr));
		g.drawRect(x, y, width, height);
	}
	g.setColor(clr);
	g.setFont(temp);
	g.clearWorldClip();
	g.setClip(oldClip);
}
 
Example 9
/**
 * @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
	g.resetTransform();
	
	if (!moveBackDone) {
		g.translate(xp1,yp1);
		g.scale(scale1, scale1);
		g.setClip((int) xp1,(int) yp1,(int) (scale1*container.getWidth()),(int) (scale1*container.getHeight()));
		prev.render(container, game, g);
		g.resetTransform();
		g.clearClip();
	}
}
 
Example 10
/**
 * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) throws SlickException {
	// draw the appropriate section of the tilemap based on the centre (hence the -(TANK_SIZE/2)) of
	// the player
	int playerTileX = (int) playerX;
	int playerTileY = (int) playerY;
	
	// caculate the offset of the player from the edge of the tile. As the player moves around this
	// varies and this tells us how far to offset the tile based rendering to give the smooth
	// motion of scrolling
	int playerTileOffsetX = (int) ((playerTileX - playerX) * TILE_SIZE);
	int playerTileOffsetY = (int) ((playerTileY - playerY) * TILE_SIZE);
	
	// render the section of the map that should be visible. Notice the -1 and +3 which renders
	// a little extra map around the edge of the screen to cope with tiles scrolling on and off
	// the screen
	map.render(playerTileOffsetX - (TANK_SIZE / 2), playerTileOffsetY - (TANK_SIZE / 2), 
			   playerTileX - leftOffsetInTiles - 1, 
			   playerTileY - topOffsetInTiles - 1,
			   widthInTiles + 3, heightInTiles + 3);
	
	// draw entities relative to the player that must appear in the centre of the screen
	g.translate(400 - (int) (playerX * 32), 300 - (int) (playerY * 32));
	
	drawTank(g, playerX, playerY, ang);
	// draw other entities here if there were any
	
	g.resetTransform();
}
 
Example 11
/**
 * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g)
		throws SlickException {
	String text = "abc";
	font.drawString(610,100,text);
	
	GL11.glDisable(GL11.GL_BLEND);
	GL11.glEnable(GL11.GL_ALPHA_TEST);
	GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5f);
	font.drawString(610,150,text);
	GL11.glDisable(GL11.GL_ALPHA_TEST);
	GL11.glEnable(GL11.GL_BLEND);
	
	g.translate(-50,-130);
	g.scale(10,10);
	font.drawString(0,0,text);

	GL11.glDisable(GL11.GL_BLEND);
	GL11.glEnable(GL11.GL_ALPHA_TEST);
	GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5f);
	font.drawString(0,26,text);
	GL11.glDisable(GL11.GL_ALPHA_TEST);
	GL11.glEnable(GL11.GL_BLEND);
	
	g.resetTransform();
	g.setColor(Color.lightGray);
	g.drawString("Original Size on Sheet", 620, 210);
	g.drawString("10x Scale Up", 40, 575);
	
	g.setColor(Color.darkGray);
	g.drawRect(40, 40, 560,530);
	g.drawRect(610, 105, 150,100);

	g.setColor(Color.white);
	g.drawString("512x512 Font Sheet", 620, 300);
	g.drawString("NEHE Charset", 620, 320);
	g.drawString("4096x4096 (8x) Source Image", 620, 340);
	g.drawString("ScanSize = 20", 620, 360);
}
 
Example 12
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	for (int i=0;i<100;i++) {
		g.translate(1,1);
		system.render();
	}
	g.resetTransform();
	g.drawString("Press space to toggle blending mode", 200, 500);
	g.drawString("Particle Count: "+(system.getParticleCount()*100), 200, 520);
}
 
Example 13
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	((ConfigurableEmitter) trail.getEmitter(0)).setPosition(rx+14,ry+35);
	trail.render();
	image.draw((int) rx,(int) ry);
	
	g.translate(400, 300);
	fire.render();
}
 
Example 14
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	g.drawRect(0,0,image.getWidth(),image.getHeight());
	image.draw(0,0);
	image.draw(500,0,200,100);
	scaleMe.draw(500,100,200,100);
	scaled.draw(400,500);
	Image flipped = scaled.getFlippedCopy(true, false);
	flipped.draw(520,500);
	Image flipped2 = flipped.getFlippedCopy(false, true);
	flipped2.draw(520,380);
	Image flipped3 = flipped2.getFlippedCopy(true, false);
	flipped3.draw(400,380);
	
	for (int i=0;i<3;i++) {
		subImage.draw(200+(i*30),300);
	}
	
	g.translate(500, 200);
	g.rotate(50, 50, rot);
	g.scale(0.3f,0.3f);
	image.draw();
	g.resetTransform();
       
       rotImage.setRotation(rot);
       rotImage.draw(100, 200);
}
 
Example 15
/**
 * Render the tile map and lighting to the game window
 * 
 * @param container The container the game is running in
 * @param g The graphics context to which we can render
 */
public void render(GameContainer container, Graphics g)
		throws SlickException {
	// display some instructions on how to use the example
	g.setColor(Color.white);
	g.drawString("Lighting Example", 440, 5);
	g.drawString("Press L to toggle light", 80, 560);
	g.drawString("Press C to toggle coloured lights", 80, 575);
	g.drawString("Click or Drag to move the main light", 80, 545);
	
	// move the display to nicely position the tilemap
	g.translate(64,50);
	
	tiles.startUse();
	// cycle round every tile in the map
	for (int y=0;y<HEIGHT;y++) {
		for (int x=0;x<WIDTH;x++) {
			// get the appropriate image to draw for the current tile
			int tile = map[x][y];
			Image image = tiles.getSubImage(tile % 4, tile / 4);
			
			if (lightingOn) {
				// if lighting is on apply the lighting values we've 
				// calculated for each vertex to the image. We can apply
				// colour components here as well as just a single value.
				image.setColor(Image.TOP_LEFT, lightValue[x][y][0], lightValue[x][y][1], lightValue[x][y][2], 1);
				image.setColor(Image.TOP_RIGHT, lightValue[x+1][y][0], lightValue[x+1][y][1], lightValue[x+1][y][2], 1);
				image.setColor(Image.BOTTOM_RIGHT, lightValue[x+1][y+1][0], lightValue[x+1][y+1][1], lightValue[x+1][y+1][2], 1);
				image.setColor(Image.BOTTOM_LEFT, lightValue[x][y+1][0], lightValue[x][y+1][1], lightValue[x][y+1][2], 1);
			} else {
				// if lighting is turned off then use "1" for every value
				// so we just have full colour everywhere.
				float light = 1;
				image.setColor(Image.TOP_LEFT, light, light, light, 1);
				image.setColor(Image.TOP_RIGHT, light, light, light, 1);
				image.setColor(Image.BOTTOM_RIGHT, light, light, light, 1);
				image.setColor(Image.BOTTOM_LEFT, light, light, light, 1);
			}
						
			// draw the image with it's newly declared vertex colours
			// to the display
			image.drawEmbedded(x*32,y*32,32,32);
		}
	}
	tiles.endUse();
}
 
Example 16
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 17
/**
 * @see org.newdawn.slick.gui.AbstractComponent#render(org.newdawn.slick.gui.GUIContext,
 *      org.newdawn.slick.Graphics)
 */
public void render(GUIContext container, Graphics g) {
	if (lastKey != -1) {
		if (input.isKeyDown(lastKey)) {
			if (repeatTimer < System.currentTimeMillis()) {
				repeatTimer = System.currentTimeMillis() + KEY_REPEAT_INTERVAL;
				keyPressed(lastKey, lastChar);
			}
		} else {
			lastKey = -1;
		}
	}
	Rectangle oldClip = g.getClip();
	g.setWorldClip(x,y,width, height);
	
	// Someone could have set a color for me to blend...
	Color clr = g.getColor();

	if (background != null) {
		g.setColor(background.multiply(clr));
		g.fillRect(x, y, width, height);
	}
	g.setColor(text.multiply(clr));
	Font temp = g.getFont();

	int cpos = font.getWidth(value.substring(0, cursorPos));
	int tx = 0;
	if (cpos > width) {
		tx = width - cpos - font.getWidth("_");
	}

	g.translate(tx + 2, 0);
	g.setFont(font);
	g.drawString(value, x + 1, y + 1);

	if (hasFocus() && visibleCursor) {
		g.drawString("_", x + 1 + cpos + 2, y + 1);
	}

	g.translate(-tx - 2, 0);

	if (border != null) {
		g.setColor(border.multiply(clr));
		g.drawRect(x, y, width, height);
	}
	g.setColor(clr);
	g.setFont(temp);
	g.clearWorldClip();
	g.setClip(oldClip);
}
 
Example 18
/**
 * @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);
       
}
 
Example 19
/**
 * @see org.newdawn.slick.Game#render(GameContainer, Graphics)
 */
public void render(GameContainer container, Graphics g)
		throws SlickException {
	g.translate(x, 0);
	SimpleDiagramRenderer.render(g, morph);
}
 
Example 20
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) throws SlickException {
	g.setColor(Color.white);
	
	g.setAntiAlias(true);
	for (int x=0;x<360;x+=10) {
		g.drawLine(700,100,(int) (700+(Math.cos(Math.toRadians(x))*100)),
						   (int) (100+(Math.sin(Math.toRadians(x))*100)));
	}
	g.setAntiAlias(false);
	
	g.setColor(Color.yellow);
	g.drawString("The Graphics Test!", 300, 50);
	g.setColor(Color.white);
	g.drawString("Space - Toggles clipping", 400, 80);
	g.drawString("Frame rate capped to 100", 400, 120);
	
	if (clip) {
		g.setColor(Color.gray);
		g.drawRect(100,260,400,100);
		g.setClip(100,260,400,100);
	}

	g.setColor(Color.yellow);
	g.translate(100, 120);
	g.fill(poly);
	g.setColor(Color.blue);
	g.setLineWidth(3);
	g.draw(poly);
	g.setLineWidth(1);
	g.translate(0, 230);
	g.draw(poly);
	g.resetTransform();
	
	g.setColor(Color.magenta);
	g.drawRoundRect(10, 10, 100, 100, 10);
	g.fillRoundRect(10, 210, 100, 100, 10);
	
	g.rotate(400, 300, ang);
	g.setColor(Color.green);
	g.drawRect(200,200,200,200);
	g.setColor(Color.blue);
	g.fillRect(250,250,100,100);

	g.drawImage(image, 300,270);
	
	g.setColor(Color.red);
	g.drawOval(100,100,200,200);
	g.setColor(Color.red.darker());
	g.fillOval(300,300,150,100);
	g.setAntiAlias(true);
	g.setColor(Color.white);
	g.setLineWidth(5.0f);
	g.drawOval(300,300,150,100);
	g.setAntiAlias(true);
	g.resetTransform();
	
	if (clip) {
		g.clearClip();
	}
}