Java Code Examples for org.newdawn.slick.SlickException

The following examples show how to use org.newdawn.slick.SlickException. 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
Source Project: opsu   Source File: Options.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the container size and makes the window borderless if the container
 * size is identical to the screen resolution.
 * <p>
 * If the configured resolution is larger than the screen size, the smallest
 * available resolution will be used.
 * @param app the game container
 */
public static void setDisplayMode(Container app) {
	int screenWidth = app.getScreenWidth();
	int screenHeight = app.getScreenHeight();
	boolean fullscreen = isFullscreen();

	// check for larger-than-screen dimensions
	if (screenWidth < resolution.getWidth() || screenHeight < resolution.getHeight())
		resolution = Resolution.RES_800_600;

	// check if fullscreen mode is possible with this resolution
	if (fullscreen && !resolution.hasFullscreenDisplayMode())
		fullscreen = false;

	try {
		app.setDisplayMode(resolution.getWidth(), resolution.getHeight(), fullscreen);
	} catch (SlickException e) {
		ErrorHandler.error("Failed to set display mode.", e, true);
	}

	// set borderless window if dimensions match screen size
	if (!fullscreen) {
		boolean borderless = (screenWidth == resolution.getWidth() && screenHeight == resolution.getHeight());
		System.setProperty("org.lwjgl.opengl.Window.undecorated", Boolean.toString(borderless));
	}
}
 
Example 2
Source Project: opsu-dance   Source File: ImageLoader.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads the image.
 * @param threaded true to load the image data in a new thread
 */
public void load(boolean threaded) {
	if (!file.isFile())
		return;

	if (threaded) {
		if (loaderThread != null && loaderThread.isAlive())
			loaderThread.interrupt();
		loaderThread = new ImageLoaderThread();
		loaderThread.start();
	} else {
		try {
			image = new Image(file.getAbsolutePath());
		} catch (SlickException e) {
			Log.warn(String.format("Failed to load background image '%s'.", file), e);
		}
	}
}
 
Example 3
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	poly.addPoint(120, 120);
	poly.addPoint(420, 100);
	poly.addPoint(620, 420);
	poly.addPoint(300, 320);

	image = new Image("testdata/rocks.png");
	
	texPaint = new TexCoordGenerator() {
		public Vector2f getCoordFor(float x, float y) {
			float tx = (texRect.getX() - x) / texRect.getWidth();
			float ty = (texRect.getY() - y) / texRect.getHeight();
			
			return new Vector2f(tx,ty);
		}
	};
}
 
Example 4
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 5
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 6
/**
 * @see org.newdawn.slick.Game#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	font = new AngelCodeFont("testdata/perffont.fnt","testdata/perffont.png");
	
	for (int j=0;j<2;j++) {
		int lineLen = 90;
		for (int i=0;i<text.length();i+=lineLen) {
			if (i+lineLen > text.length()) {
				lineLen = text.length() - i;
			}
			
			lines.add(text.substring(i, i+lineLen));	
		}
		lines.add("");
	}
}
 
Example 7
/**
 * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
 */
public void update(GameContainer container, int delta) throws SlickException {
	// check the controls, left/right adjust the rotation of the tank, up/down 
	// move backwards and forwards
	if (container.getInput().isKeyDown(Input.KEY_LEFT)) {
		ang -= delta * TANK_ROTATE_SPEED;
		updateMovementVector();
	}
	if (container.getInput().isKeyDown(Input.KEY_RIGHT)) {
		ang += delta * TANK_ROTATE_SPEED;
		updateMovementVector();
	}
	if (container.getInput().isKeyDown(Input.KEY_UP)) {
		if (tryMove(dirX * delta * TANK_MOVE_SPEED, dirY * delta * TANK_MOVE_SPEED)) {
			// if we managed to move update the animation
			player.update(delta);
		}
	}
	if (container.getInput().isKeyDown(Input.KEY_DOWN)) {
		if (tryMove(-dirX * delta * TANK_MOVE_SPEED, -dirY * delta * TANK_MOVE_SPEED)) {
			// if we managed to move update the animation
			player.update(delta);
		}
	}
}
 
Example 8
@Override
protected void renderImpl(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	// Background
	g.drawImage(ResourceHolderSlick.imgTitle, 0, 0);

	// Menu
	NormalFontSlick.printFontGrid(1, 1, "NULLPOMINO", NormalFontSlick.COLOR_ORANGE);
	NormalFontSlick.printFontGrid(1, 2, "VERSION " + GameManager.getVersionString(), NormalFontSlick.COLOR_ORANGE);

	renderChoices(2, 4, CHOICES);

	NormalFontSlick.printTTFFont(16, 432, NullpoMinoSlick.getUIText(UI_TEXT[cursor]));

	if(UpdateChecker.isNewVersionAvailable(GameManager.getVersionMajor(), GameManager.getVersionMinor())) {
		String strTemp = String.format(NullpoMinoSlick.getUIText("Title_NewVersion"),
				UpdateChecker.getLatestVersionFullString(), UpdateChecker.getStrReleaseDate());
		NormalFontSlick.printTTFFont(16, 416, strTemp);
	}
}
 
Example 9
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	SoundStore.get().setMaxSources(32);
	
	myContainer = container;
	sound = new Sound("testdata/restart.ogg");
	charlie = new Sound("testdata/cbrown01.wav");
	try {
		engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
	} catch (IOException e) {
		throw new SlickException("Failed to load engine", e);
	}
	music = musica = new Music("testdata/SMB-X.XM");
	//music = musica = new Music("testdata/theme.ogg", true);
	musicb = new Music("testdata/kirby.ogg", true);
	burp = new Sound("testdata/burp.aif");
	
	music.play();
}
 
Example 10
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public final void init(GameContainer container) throws SlickException {
	this.container = container;
	initStatesList(container);
	
	Iterator gameStates = states.values().iterator();
	
	while (gameStates.hasNext()) {
		GameState state = (GameState) gameStates.next();
	
		state.init(container, this);
	}
	
	if (currentState != null) {
		currentState.enter(container, this);
	}
}
 
Example 11
/** 
 * Create an underlying graphics context for the given image
 * 
 * @param image The image we want to render to
 * @return The graphics context created
 * @throws SlickException
 */
private static Graphics createGraphics(Image image) throws SlickException {
	init();
	
	if (fbo) {
		try {
			return new FBOGraphics(image);
		} catch (Exception e) {
			fbo = false;
			Log.warn("FBO failed in use, falling back to PBuffer");
		}
	}
	
	if (pbuffer) {
		if (pbufferRT) {
			return new PBufferGraphics(image);
		} else {
			return new PBufferUniqueGraphics(image);
		}
	}
	
	throw new SlickException("Failed to create offscreen buffer even though the card reports it's possible");
}
 
Example 12
/**
 * Update the game. BaseGameState will do the common things (such as Framerate Cap or Screen Shot) here.
 * Your code will be in updateImpl, unless if you want do something special.
 */
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
	// Lost the focus
	if(!container.hasFocus()) {
		GameKeySlick.gamekey[0].clear();
		GameKeySlick.gamekey[1].clear();
		if(NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
		return;
	}

	// Do user's code
	updateImpl(container, game, delta);

	// Screenshot button
	if(GameKeySlick.gamekey[0].isPushKey(GameKeySlick.BUTTON_SCREENSHOT)) screenShotFlag = true;
	// Exit button
	if(GameKeySlick.gamekey[0].isPushKey(GameKeySlick.BUTTON_QUIT)) container.exit();

	// Framerate Cap
	if(NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
}
 
Example 13
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
    shapes = new ArrayList();
    rect = new Rectangle(10, 10, 100, 80);
    shapes.add(rect);
    roundRect = new RoundedRectangle(150, 10, 60, 80, 20);
    shapes.add(roundRect);
    ellipse = new Ellipse(350, 40, 50, 30);
    shapes.add(ellipse);
    circle = new Circle(470, 60, 50);
    shapes.add(circle);
    polygon = new Polygon(new float[]{550, 10, 600, 40, 620, 100, 570, 130});
    shapes.add(polygon);
    
    keys = new boolean[256];
    lastChar = new char[256];
    createPoly(200,200);
}
 
Example 14
@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 15
Source Project: opsu   Source File: Fonts.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads a Unicode font and its ASCII glyphs.
 * @param font the font to load
 * @param effect the font effect
 * @param backup the backup font
 * @throws SlickException if the glyphs could not be loaded
 */
@SuppressWarnings("unchecked")
private static void loadFont(UnicodeFont font, Effect effect, UnicodeFont backup) throws SlickException {
	font.addBackupFont(backup);
	font.addAsciiGlyphs();
	font.getEffects().add(effect);
	font.loadGlyphs();
}
 
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 render(GameContainer container, StateBasedGame game, Graphics g)
		throws SlickException {
	g.setBackground(Color.black);
	if (menuState != null)
		menuState.draw(container, game, g);
}
 
Example 17
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);
}
 
Example 18
/**
 * @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
 */
public void update(StateBasedGame game, GameContainer container, int delta)
		throws SlickException {
	offset += delta * 1f;
	if (offset > container.getWidth() / 2) {
		finish = true;
	}
}
 
Example 19
@Override
public void enter(GameContainer container, StateBasedGame game) throws SlickException {
	currentAI = NullpoMinoSlick.propGlobal.getProperty(player + ".ai", "");
	aiMoveDelay = NullpoMinoSlick.propGlobal.getProperty(player + ".aiMoveDelay", 0);
	aiThinkDelay = NullpoMinoSlick.propGlobal.getProperty(player + ".aiThinkDelay", 0);
	aiUseThread = NullpoMinoSlick.propGlobal.getProperty(player + ".aiUseThread", true);
	aiShowHint = NullpoMinoSlick.propGlobal.getProperty(player+ ".aiShowHint", false);
	aiPrethink = NullpoMinoSlick.propGlobal.getProperty(player+ ".aiPrethink", false);
	aiShowState = NullpoMinoSlick.propGlobal.getProperty(player+ ".aiShowState", false);

	aiID = -1;
	for(int i = 0; i < aiPathList.length; i++) {
		if(currentAI.equals(aiPathList[i])) aiID = i;
	}
}
 
Example 20
/**
 * @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 21
/**
 * Entry point to our test
 * 
 * @param argv
 *            The arguments passed to the test
 */
public static void main(String[] argv) {
	try {
		AppGameContainer container = new AppGameContainer(
				new MorphSVGTest());
		container.setDisplayMode(800, 600, false);
		container.start();
	} catch (SlickException e) {
		e.printStackTrace();
	}
}
 
Example 22
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	testImage = new Image("testdata/logo.png");
	preloaded = new Image("testdata/logo.png");
	testFont = new AngelCodeFont("testdata/hiero.fnt","testdata/hiero.png");
	target = new Image(400,300);
	cut = new Image(100,100);
	gTarget = target.getGraphics();
	offscreenPreload = preloaded.getGraphics();
	
	offscreenPreload.drawString("Drawing over a loaded image", 5, 15);
	offscreenPreload.setLineWidth(5);
	offscreenPreload.setAntiAlias(true);
	offscreenPreload.setColor(Color.blue.brighter());
	offscreenPreload.drawOval(200, 30, 50, 50);
	offscreenPreload.setColor(Color.white);
	offscreenPreload.drawRect(190,20,70,70);
	offscreenPreload.flush();
	
	if (GraphicsFactory.usingFBO()) {
		using = "FBO (Frame Buffer Objects)";
	} else if (GraphicsFactory.usingPBuffer()) {
		using = "Pbuffer (Pixel Buffers)";
	}
	
	System.out.println(preloaded.getColor(50,50));
}
 
Example 23
/**
 * @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 24
/**
 * Write an image out to a file on the local file system. The format of the output
 * is determined based on the file name extension
 * 
 * @param image The image to be written out
 * @param dest The destination path to write to
 * @param writeAlpha True if we should write the alpha channel out (some formats don't support this, like JPG)
 * @throws SlickException Indicates a failure to write the image in the determined format
 */
public static void write(Image image, String dest, boolean writeAlpha) throws SlickException {
	try {
		int ext = dest.lastIndexOf('.');
		if (ext < 0) {
			throw new SlickException("Unable to determine format from: "+dest);
		}
		
		String format = dest.substring(ext+1);
		write(image, format, new FileOutputStream(dest), writeAlpha);
	} catch (IOException e) {
		throw new SlickException("Unable to write to the destination: "+dest, e);
	}
}
 
Example 25
/**
 * @see BasicGame#init(GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	base = InkscapeLoader.load("testdata/svg/walk1.svg");
	morph = new SVGMorph(base);
	morph.addStep(InkscapeLoader.load("testdata/svg/walk2.svg"));
	morph.addStep(InkscapeLoader.load("testdata/svg/walk3.svg"));
	morph.addStep(InkscapeLoader.load("testdata/svg/walk4.svg"));
	
	container.setVSync(true);
}
 
Example 26
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	provider = new InputProvider(container.getInput());
	provider.addListener(this);
	
	provider.bindCommand(new KeyControl(Input.KEY_LEFT), run);
	provider.bindCommand(new KeyControl(Input.KEY_A), run);
	provider.bindCommand(new ControllerDirectionControl(0, ControllerDirectionControl.LEFT), run);
	provider.bindCommand(new KeyControl(Input.KEY_UP), jump);
	provider.bindCommand(new KeyControl(Input.KEY_W), jump);
	provider.bindCommand(new ControllerDirectionControl(0, ControllerDirectionControl.UP), jump);
	provider.bindCommand(new KeyControl(Input.KEY_SPACE), attack);
	provider.bindCommand(new MouseButtonControl(0), attack);
	provider.bindCommand(new ControllerButtonControl(0, 1), attack);
}
 
Example 27
/**
 * Entry point to our test
 * 
 * @param argv The arguments passed to the test
 */
public static void main(String[] argv) {
	try {
		Renderer.setRenderer(Renderer.VERTEX_ARRAY_RENDERER);
		
		AppGameContainer container = new AppGameContainer(new GeomTest());
		container.setDisplayMode(800,600,false);
		container.start();
	} catch (SlickException e) {
		e.printStackTrace();
	}
}
 
Example 28
/**
 * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
 */
public final void update(GameContainer container, int delta) throws SlickException {
	preUpdateState(container, delta);
	
	if (leaveTransition != null) {
		leaveTransition.update(this, container, delta);
		if (leaveTransition.isComplete()) {
			currentState.leave(container, this);
			GameState prevState = currentState;
			currentState = nextState;
			nextState = null;
			leaveTransition = null;
			currentState.enter(container, this);
			if (enterTransition != null) {
				enterTransition.init(currentState, prevState);
			}
		} else {
			return;
		}
	}
	
	if (enterTransition != null) {
		enterTransition.update(this, container, delta);
		if (enterTransition.isComplete()) {
			enterTransition = null;
		} else {
			return;
		}
	}
	
	currentState.update(container, this, delta);
	
	postUpdateState(container, delta);
}
 
Example 29
/**
 * Entry point to the test
 * 
 * @param args The arguments passed into the test
 */
public static void main(String[] args) {
   try {
      AppGameContainer container = new AppGameContainer(new ImageBufferEndianTest());
      container.setDisplayMode(800,600,false);
      container.start();
   } catch (SlickException e) {
      e.printStackTrace();
   }
}
 
Example 30
/**
 * @see BasicGame#update(GameContainer, int)
 */
public void update(GameContainer container, int delta)
		throws SlickException {
	if (container.getInput().isKeyPressed(Input.KEY_SPACE)) {
		dynamic = !dynamic;
	}
	if (container.getInput().isKeyPressed(Input.KEY_ENTER)) {
		union = !union;
		makeBoolean();
	}
	if (container.getInput().isKeyPressed(Input.KEY_1)) {
		cut = circle;
		circle.setCenterX(xp);
		circle.setCenterY(yp);
		makeBoolean();
	}
	if (container.getInput().isKeyPressed(Input.KEY_2)) {
		cut = rect;
		rect.setCenterX(xp);
		rect.setCenterY(yp);
		makeBoolean();
	}
	if (container.getInput().isKeyPressed(Input.KEY_3)) {
		cut = star;
		star.setCenterX(xp);
		star.setCenterY(yp);
		makeBoolean();
	}
	
	if (dynamic) {
		xp = container.getInput().getMouseX();
		yp = container.getInput().getMouseY();
		makeBoolean();
	}
}