Java Code Examples for org.newdawn.slick.GameContainer

The following examples show how to use org.newdawn.slick.GameContainer. 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.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	
	g.rotate(400, 300, ang);
	g.fill(rect, gradient);
	g.fill(round, gradient);
	g.fill(poly, gradient2);
	g.fill(center, gradient4);

	g.setAntiAlias(true);
	g.setLineWidth(10);
	g.draw(round2, gradient2);
	g.setLineWidth(2);
	g.draw(poly, gradient);
	g.setAntiAlias(false);
	
	g.fill(center, gradient4);
	g.setAntiAlias(true);
	g.setColor(Color.black);
	g.draw(center);
	g.setAntiAlias(false);
}
 
Example 2
Source Project: opsu   Source File: GameRanking.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void enter(GameContainer container, StateBasedGame game)
		throws SlickException {
	UI.enter();
	Display.setTitle(game.getTitle());
	if (!data.isGameplay()) {
		if (!MusicController.isTrackDimmed())
			MusicController.toggleTrackDimmed(0.5f);
		replayButton.setY(retryY);
		animationProgress.setTime(animationProgress.getDuration());
	} else {
		SoundController.playSound(SoundEffect.APPLAUSE);
		retryButton.resetHover();
		if (GameMod.AUTO.isActive()) {
			replayButton.setY(retryY);
			animationProgress.setTime(animationProgress.getDuration());
		} else {
			replayButton.setY(replayY);
			animationProgress.setTime(0);
		}
	}
	replayButton.resetHover();
	loadReplay();
}
 
Example 3
@Override
protected boolean onDecide(GameContainer container, StateBasedGame game, int delta) {
	ResourceHolderSlick.soundManager.play("decide");

	if(isTopLevel && (cursor == list.length - 1)) {
		// More...
		NullpoMinoSlick.propGlobal.setProperty("name.mode.toplevel", list[cursor]);
		game.enterState(StateSelectModeFolder.ID);
	} else {
		// Go to rule selector
		if(isTopLevel) {
			NullpoMinoSlick.propGlobal.setProperty("name.mode.toplevel", list[cursor]);
		}
		if(strCurrentFolder.length() > 0) {
			NullpoMinoSlick.propGlobal.setProperty("name.mode." + strCurrentFolder, list[cursor]);
		}
		NullpoMinoSlick.propGlobal.setProperty("name.mode", list[cursor]);
		NullpoMinoSlick.saveConfig();
		game.enterState(StateSelectRuleFromList.ID);
	}

	return false;
}
 
Example 4
@Override
protected void renderImpl(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	// Background
	g.drawImage(ResourceHolderSlick.imgMenu, 0, 0);

	// Menu
	NormalFontSlick.printFontGrid(1, 1, (player + 1) + "P AI SETTING", NormalFontSlick.COLOR_ORANGE);

	NormalFontSlick.printFontGrid(1, 3 + cursor, "b", NormalFontSlick.COLOR_RED);

	String aiName = "";
	if(aiID < 0) aiName = "(DISABLE)";
	else aiName = aiNameList[aiID].toUpperCase();
	NormalFontSlick.printFontGrid(2, 3, "AI TYPE:" + aiName, (cursor == 0));
	NormalFontSlick.printFontGrid(2, 4, "AI MOVE DELAY:" + aiMoveDelay, (cursor == 1));
	NormalFontSlick.printFontGrid(2, 5, "AI THINK DELAY:" + aiThinkDelay, (cursor == 2));
	NormalFontSlick.printFontGrid(2, 6, "AI USE THREAD:" + GeneralUtil.getONorOFF(aiUseThread), (cursor == 3));
	NormalFontSlick.printFontGrid(2, 7, "AI SHOW HINT:" + GeneralUtil.getONorOFF(aiShowHint), (cursor == 4));
	NormalFontSlick.printFontGrid(2, 8, "AI PRE-THINK:" + GeneralUtil.getONorOFF(aiPrethink), (cursor == 5));
	NormalFontSlick.printFontGrid(2, 9, "AI SHOW INFO:" + GeneralUtil.getONorOFF(aiShowState), (cursor == 6));

	NormalFontSlick.printFontGrid(1, 28, "A:OK B:CANCEL", NormalFontSlick.COLOR_GREEN);
}
 
Example 5
public void init(GameContainer container) throws SlickException {
   // detect what endian we have
   if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
          endian = "Big endian";
       } else if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
          endian = "Little endian";
       } else
          endian = "no idea";
   
   redImageBuffer = new ImageBuffer(100,100);
   fillImageBufferWithColor(redImageBuffer, Color.red, 100, 100);
   
   blueImageBuffer = new ImageBuffer(100,100);
   fillImageBufferWithColor(blueImageBuffer, Color.blue, 100, 100);
   
   fromRed = redImageBuffer.getImage();
   fromBlue = blueImageBuffer.getImage();
}
 
Example 6
@Override
protected boolean onDecide(GameContainer container, StateBasedGame game, int delta) {
	ResourceHolderSlick.soundManager.play("decide");

	RuleEntry entry = ruleEntries.get(cursor);
	if(style == 0) {
		NullpoMinoSlick.propGlobal.setProperty(player + ".rule", entry.filepath);
		NullpoMinoSlick.propGlobal.setProperty(player + ".rulefile", entry.filename);
		NullpoMinoSlick.propGlobal.setProperty(player + ".rulename", entry.rulename);
	} else {
		NullpoMinoSlick.propGlobal.setProperty(player + ".rule." + style, entry.filepath);
		NullpoMinoSlick.propGlobal.setProperty(player + ".rulefile." + style, entry.filename);
		NullpoMinoSlick.propGlobal.setProperty(player + ".rulename." + style, entry.rulename);
	}

	NullpoMinoSlick.saveConfig();

	game.enterState(StateConfigRuleStyleSelect.ID);
	return true;
}
 
Example 7
/**
 * @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 8
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	this.container = container;
	
	image1 = new Image("testdata/grass.png");
	image2 = new Image("testdata/rocks.png");
	
	fill = new GradientFill(-64,0,new Color(1,1,1,1f),64,0,new Color(0,0,0,0));
	shape = new Rectangle(336,236,128,128);
    poly = new Polygon();
	poly.addPoint(320,220);
	poly.addPoint(350,200);
	poly.addPoint(450,200);
	poly.addPoint(480,220);
	poly.addPoint(420,400);
	poly.addPoint(400,390);
}
 
Example 9
/**
 * @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 10
@Override
protected void renderImpl(GameContainer container, StateBasedGame game, Graphics graphics) throws SlickException {
	// Background
	graphics.drawImage(ResourceHolderSlick.imgMenu, 0, 0);

	// Menu
	if(list == null) {
		NormalFontSlick.printFontGrid(1, 1, nullError, NormalFontSlick.COLOR_RED);
	} else if(list.length == 0) {
		NormalFontSlick.printFontGrid(1, 1, emptyError, NormalFontSlick.COLOR_RED);
	} else {
		if (cursor >= list.length)
			cursor = 0;
		if (cursor < minentry)
			minentry = cursor;
		int maxentry = minentry + pageHeight - 1;
		if (cursor >= maxentry)
		{
			maxentry = cursor;
			minentry = maxentry - pageHeight + 1;
		}
		drawMenuList(graphics);
		onRenderSuccess(container, game, graphics);
	}
}
 
Example 11
Source Project: opsu   Source File: GamePauseMenu.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
		throws SlickException {
	// get background image
	GameImage bg = (gameState.getPlayState() == Game.PlayState.LOSE) ?
			GameImage.FAIL_BACKGROUND : GameImage.PAUSE_OVERLAY;

	// don't draw default background if button skinned and background unskinned
	boolean buttonsSkinned =
		GameImage.PAUSE_CONTINUE.hasBeatmapSkinImage() ||
		GameImage.PAUSE_RETRY.hasBeatmapSkinImage() ||
		GameImage.PAUSE_BACK.hasBeatmapSkinImage();
	if (!buttonsSkinned || bg.hasBeatmapSkinImage())
		bg.getImage().drawCentered(container.getWidth() / 2, container.getHeight() / 2);
	else
		g.setBackground(Color.black);

	// draw buttons
	if (gameState.getPlayState() != Game.PlayState.LOSE)
		continueButton.draw();
	retryButton.draw();
	backButton.draw();

	UI.draw(g);
}
 
Example 12
/**
	 * @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 13
Source Project: opsu   Source File: ButtonMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void click(GameContainer container, StateBasedGame game) {
	SoundController.playSound(SoundEffect.MENUHIT);
	BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode();
	MenuState ms = (node.beatmapIndex == -1 || node.getBeatmapSet().size() == 1) ?
			MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT;
	((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(ms, node);
	game.enterState(Opsu.STATE_BUTTONMENU);
}
 
Example 14
Source Project: opsu   Source File: ButtonMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPress(GameContainer container, StateBasedGame game, int key, char c) {
	super.keyPress(container, game, key, c);
	for (GameMod mod : GameMod.values()) {
		if (key == mod.getKey()) {
			mod.toggle(true);
			break;
		}
	}
}
 
Example 15
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	if (container instanceof AppGameContainer) {
		app = (AppGameContainer) container;
	}
	
	input = container.getInput();
	x = 300;
	y = 300;
}
 
Example 16
Source Project: opsu   Source File: ButtonMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void click(GameContainer container, StateBasedGame game) {
	SoundController.playSound(SoundEffect.MENUHIT);
	ScoreData scoreData = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getScoreData();
	((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.SCORE, scoreData);
	game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition());
}
 
Example 17
Source Project: opsu   Source File: GameRanking.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
		throws SlickException {
	int width = container.getWidth();
	int height = container.getHeight();
	int mouseX = input.getMouseX(), mouseY = input.getMouseY();

	Beatmap beatmap = MusicController.getBeatmap();

	// background
	float parallaxX = 0, parallaxY = 0;
	if (Options.isParallaxEnabled()) {
		int offset = (int) (height * (GameImage.PARALLAX_SCALE - 1f));
		parallaxX = -offset / 2f * (mouseX - width / 2) / (width / 2);
		parallaxY = -offset / 2f * (mouseY - height / 2) / (height / 2);
	}
	if (!beatmap.drawBackground(width, height, parallaxX, parallaxY, 0.5f, true)) {
		Image bg = GameImage.MENU_BG.getImage();
		if (Options.isParallaxEnabled()) {
			bg = bg.getScaledCopy(GameImage.PARALLAX_SCALE);
			bg.setAlpha(0.5f);
			bg.drawCentered(width / 2 + parallaxX, height / 2 + parallaxY);
		} else {
			bg.setAlpha(0.5f);
			bg.drawCentered(width / 2, height / 2);
			bg.setAlpha(1f);
		}
	}

	// ranking screen elements
	data.drawRankingElements(g, beatmap, animationProgress.getTime());

	// buttons
	replayButton.draw();
	if (data.isGameplay() && !GameMod.AUTO.isActive())
		retryButton.draw();
	UI.getBackButton().draw(g);

	UI.draw(g);
}
 
Example 18
/**
 * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
 */
public void update(GameContainer container, int delta) {
	r += delta * 0.4f;
	if (r > 900) {
		r = -500;
	}
	
	ang += delta * 0.1f;
}
 
Example 19
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(final GameContainer container) throws SlickException {
	operations = new Runnable() {
		public void run() {
			for (int i=0;i<100;i++) {
				int c = i+100;
				container.getGraphics().setColor(new Color(c,c,c,c));
				container.getGraphics().drawOval((i*5)+50,(i*3)+50,100,100);
			}
		}
	};
	
	cached = new CachedRender(operations);
}
 
Example 20
public void init(GameContainer container) throws SlickException {
	container.getInput().addListener(listener);
	container.setShowFPS(false);
	
	system = new ParticleSystem("org/newdawn/slick/data/particle.tga", 2000);
	system.setBlendingMode(ParticleSystem.BLEND_ADDITIVE);
	system.setRemoveCompletedEmitters(false);

	for (int i = 0; i < waiting.size(); i++) {
		system.addEmitter((ParticleEmitter) waiting.get(i));
	}
	waiting.clear();
}
 
Example 21
@Override
public void enter(GameContainer container, StateBasedGame game) throws SlickException {
	list = getReplayFileList();
	
	if (list != null)
		maxCursor = list.length-1;
	
	setReplayRuleAndModeList();
}
 
Example 22
/**
 * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
 */
public void update(GameContainer container, int delta) {
	int mx = container.getInput().getMouseX();
	int my = container.getInput().getMouseY();
	
	if ((mx >= 100) && (my >= 100) && (mx < 200) && (my < 200)) {
		read[4] = image.getColor(mx-100,my-100);
	} else {
		read[4] = Color.black;
	}
	
	read[5] = g.getPixel(mx, my);
}
 
Example 23
Source Project: opsu   Source File: ButtonMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void update(GameContainer container, int delta, int mouseX, int mouseY) {
	super.update(container, delta, mouseX, mouseY);
	GameMod hoverMod = null;
	for (GameMod mod : GameMod.values()) {
		mod.hoverUpdate(delta, mod.isActive());
		if (hoverMod == null && mod.contains(mouseX, mouseY))
			hoverMod = mod;
	}

	// tooltips
	if (hoverMod != null)
		UI.updateTooltip(delta, hoverMod.getDescription(), true);
}
 
Example 24
Source Project: opsu   Source File: ButtonMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void click(GameContainer container, StateBasedGame game) {
	SoundController.playSound(SoundEffect.MENUHIT);
	try {
		Desktop.getDesktop().browse(OpsuConstants.REPOSITORY_URI);
	} catch (Exception e) {
		UI.getNotificationManager().sendNotification("The web page could not be opened.", Color.red);
	}
	game.enterState(Opsu.STATE_MAINMENU, new EmptyTransition(), new FadeInTransition());
}
 
Example 25
@Override
protected boolean onDecide(GameContainer container, StateBasedGame game, int delta) {
	ResourceHolderSlick.soundManager.play("decide");
	NullpoMinoSlick.stateConfigRuleSelect.player = player;
	NullpoMinoSlick.stateConfigRuleSelect.style = cursor;
	game.enterState(StateConfigRuleSelect.ID);
	return false;
}
 
Example 26
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	background.draw(0, 0, 800, 500);
	
	for (int i=0;i<4;i++) {
		areas[i].render(container, g);
	}
	field.render(container, g);
	field2.render(container, g);
	
	g.setFont(font);
	g.drawString(message, 200, 550);
}
 
Example 27
Source Project: opsu   Source File: Circle.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes the Circle data type with map modifiers, images, and dimensions.
 * @param container the game container
 * @param circleDiameter the circle diameter
 */
public static void init(GameContainer container, float circleDiameter) {
	diameter = circleDiameter * HitObject.getXMultiplier();  // convert from Osupixels (640x480)
	int diameterInt = (int) diameter;
	GameImage.HITCIRCLE.setImage(GameImage.HITCIRCLE.getImage().getScaledCopy(diameterInt, diameterInt));
	GameImage.HITCIRCLE_OVERLAY.setImage(GameImage.HITCIRCLE_OVERLAY.getImage().getScaledCopy(diameterInt, diameterInt));
	GameImage.APPROACHCIRCLE.setImage(GameImage.APPROACHCIRCLE.getImage().getScaledCopy(diameterInt, diameterInt));
}
 
Example 28
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	this.container = container;
	
	geomColor = Color.magenta;
	overlayColor = Color.white;
	
	magImage = new Image(21, 21);
}
 
Example 29
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	image = new Image("testdata/testcard.png");
	read[0] = image.getColor(0, 0);
	read[1] = image.getColor(30, 40);
	read[2] = image.getColor(55, 70);
	read[3] = image.getColor(80, 90);
}
 
Example 30
Source Project: opsu   Source File: ButtonMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void init(GameContainer container, StateBasedGame game)
		throws SlickException {
	this.container = container;
	this.game = game;
	this.input = container.getInput();

	// initialize buttons
	Image button = GameImage.MENU_BUTTON_MID.getImage();
	button = button.getScaledCopy(container.getWidth() / 2, button.getHeight());
	Image buttonL = GameImage.MENU_BUTTON_LEFT.getImage();
	Image buttonR = GameImage.MENU_BUTTON_RIGHT.getImage();
	for (MenuState ms : MenuState.values())
		ms.init(container, game, button, buttonL, buttonR);
}