Java Code Examples for org.newdawn.slick.GameContainer#hasFocus()

The following examples show how to use org.newdawn.slick.GameContainer#hasFocus() . 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: StateConfigKeyboard.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
	if(!container.hasFocus()) {
		if(NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
		return;
	}

	frame++;
	if(keyConfigRestFrame > 0) keyConfigRestFrame--;

	// JInput
	if(NullpoMinoSlick.useJInputKeyboard) {
		JInputManager.poll();

		if(frame >= KEYACCEPTFRAME) {
			for(int i = 0; i < JInputManager.MAX_SLICK_KEY; i++) {
				if(JInputManager.isKeyDown(i)) {
					onKey(i);
					frame = 0;
					break;
				}
			}
		}
	}

	if(NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
}
 
Example 2
Source File: BaseGameState.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Draw the screen. BaseGameState will do the common things (such as Framerate Cap or Screen Shot) here.
 * Your code will be in renderImpl, unless if you want do something special.
 */
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	// Lost the focus
	if(!container.hasFocus()) {
		if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
		return;
	}

	// Do user's code
	renderImpl(container, game, g);

	// Do common things
	NullpoMinoSlick.drawFPS(container);		// FPS counter
	NullpoMinoSlick.drawObserverClient();	// Observer
	if(screenShotFlag) {
		// Create a screenshot
		NullpoMinoSlick.saveScreenShot(container, g);
		screenShotFlag = false;
	}

	// Framerate Cap
	if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
}
 
Example 3
Source File: BaseGameState.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 4
Source File: StateConfigJoystickButton.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
	if(!container.hasFocus()) {
		if(NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
		return;
	}

	frame++;

	// Joystick button
	if(frame >= KEYACCEPTFRAME) {
		for(int i = 0; i < ControllerManager.MAX_BUTTONS; i++) {
			try {
				if(ControllerManager.isControllerButton(player, container.getInput(), i)) {
					ResourceHolderSlick.soundManager.play("change");
					buttonmap[keynum] = i;
					frame = 0;
				}
			} catch (Throwable e) {}
		}
	}

	// JInput
	if(NullpoMinoSlick.useJInputKeyboard) {
		JInputManager.poll();

		if(frame >= KEYACCEPTFRAME) {
			for(int i = 0; i < JInputManager.MAX_SLICK_KEY; i++) {
				if(JInputManager.isKeyDown(i)) {
					onKey(i);
					frame = KEYACCEPTFRAME / 2;
					break;
				}
			}
		}
	}

	if(NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
}
 
Example 5
Source File: StateConfigJoystickTest.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	if(!container.hasFocus()) {
		if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
		return;
	}

	ResourceHolderSlick.imgMenu.draw(0, 0);

	NormalFontSlick.printFontGrid(1, 1, "JOYSTICK INPUT TEST (" + (player + 1) + "P)", NormalFontSlick.COLOR_ORANGE);

	if(joyNumber < 0) {
		NormalFontSlick.printFontGrid(1, 3, "NO JOYSTICK", NormalFontSlick.COLOR_RED);
	} else if(frame >= KEYACCEPTFRAME) {
		NormalFontSlick.printFontGrid(1, 3, "JOYSTICK NUMBER:" + joyNumber, NormalFontSlick.COLOR_RED);

		NormalFontSlick.printFontGrid(1, 5, "LAST PRESSED BUTTON:" + ((lastPressButton == -1) ? "NONE" : String.valueOf(lastPressButton)));

		Controller controller = ControllerManager.controllers.get(joyNumber);

		NormalFontSlick.printFontGrid(1, 7, "AXIS X:" + controller.getXAxisValue());
		NormalFontSlick.printFontGrid(1, 8, "AXIS Y:" + controller.getYAxisValue());

		NormalFontSlick.printFontGrid(1, 10, "POV X:" + controller.getPovX());
		NormalFontSlick.printFontGrid(1, 11, "POV Y:" + controller.getPovY());
	}

	if(frame >= KEYACCEPTFRAME) {
		NormalFontSlick.printFontGrid(1, 23, "ENTER/BACKSPACE: EXIT", NormalFontSlick.COLOR_GREEN);
	}

	// FPS
	NullpoMinoSlick.drawFPS(container);
	// Observer
	NullpoMinoSlick.drawObserverClient();
	if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
}
 
Example 6
Source File: StateConfigJoystickTest.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
	if(!container.hasFocus()) {
		if(NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
		return;
	}

	frame++;

	// Joystick button
	if(frame >= KEYACCEPTFRAME) {
		for(int i = 0; i < buttonCount; i++) {
			try {
				if(ControllerManager.isControllerButton(player, container.getInput(), i)) {
					ResourceHolderSlick.soundManager.play("change");
					lastPressButton = i;
				}
			} catch (Throwable e) {}
		}
	}

	// JInput
	if(NullpoMinoSlick.useJInputKeyboard) {
		JInputManager.poll();

		if(frame >= KEYACCEPTFRAME) {
			for(int i = 0; i < JInputManager.MAX_SLICK_KEY; i++) {
				if(JInputManager.isKeyDown(i)) {
					onKey(i);
					break;
				}
			}
		}
	}

	if(NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
}
 
Example 7
Source File: StateConfigKeyboard.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	if(!container.hasFocus()) {
		if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
		return;
	}

	g.drawImage(ResourceHolderSlick.imgMenu, 0, 0);

	if(!isNavSetting) {
		NormalFontSlick.printFontGrid(1, 1, "KEYBOARD SETTING (" + (player + 1) + "P)", NormalFontSlick.COLOR_ORANGE);
	} else {
		NormalFontSlick.printFontGrid(1, 1, "KEYBOARD NAVIGATION SETTING (" + (player + 1) + "P)", NormalFontSlick.COLOR_ORANGE);
	}
	if(!NullpoMinoSlick.useJInputKeyboard) {
		NormalFontSlick.printFontGrid(1, 2, "SLICK NATIVE MODE", NormalFontSlick.COLOR_CYAN);
	} else {
		NormalFontSlick.printFontGrid(1, 2, "JINPUT MODE", NormalFontSlick.COLOR_PINK);
	}

	NormalFontSlick.printFontGrid(2,  4, "UP          : " + getKeyName(keymap[GameKeySlick.BUTTON_UP]), (keynum == 0));
	NormalFontSlick.printFontGrid(2,  5, "DOWN        : " + getKeyName(keymap[GameKeySlick.BUTTON_DOWN]), (keynum == 1));
	NormalFontSlick.printFontGrid(2,  6, "LEFT        : " + getKeyName(keymap[GameKeySlick.BUTTON_LEFT]), (keynum == 2));
	NormalFontSlick.printFontGrid(2,  7, "RIGHT       : " + getKeyName(keymap[GameKeySlick.BUTTON_RIGHT]), (keynum == 3));
	if(!isNavSetting) {
		NormalFontSlick.printFontGrid(2,  8, "A (L/R-ROT) : " + getKeyName(keymap[GameKeySlick.BUTTON_A]), (keynum == 4));
		NormalFontSlick.printFontGrid(2,  9, "B (R/L-ROT) : " + getKeyName(keymap[GameKeySlick.BUTTON_B]), (keynum == 5));
		NormalFontSlick.printFontGrid(2, 10, "C (L/R-ROT) : " + getKeyName(keymap[GameKeySlick.BUTTON_C]), (keynum == 6));
		NormalFontSlick.printFontGrid(2, 11, "D (HOLD)    : " + getKeyName(keymap[GameKeySlick.BUTTON_D]), (keynum == 7));
		NormalFontSlick.printFontGrid(2, 12, "E (180-ROT) : " + getKeyName(keymap[GameKeySlick.BUTTON_E]), (keynum == 8));
	} else {
		NormalFontSlick.printFontGrid(2,  8, "A (SELECT)  : " + getKeyName(keymap[GameKeySlick.BUTTON_A]), (keynum == 4));
		NormalFontSlick.printFontGrid(2,  9, "B (CANCEL)  : " + getKeyName(keymap[GameKeySlick.BUTTON_B]), (keynum == 5));
		NormalFontSlick.printFontGrid(2, 10, "C           : " + getKeyName(keymap[GameKeySlick.BUTTON_C]), (keynum == 6));
		NormalFontSlick.printFontGrid(2, 11, "D           : " + getKeyName(keymap[GameKeySlick.BUTTON_D]), (keynum == 7));
		NormalFontSlick.printFontGrid(2, 12, "E           : " + getKeyName(keymap[GameKeySlick.BUTTON_E]), (keynum == 8));
	}
	NormalFontSlick.printFontGrid(2, 13, "F           : " + getKeyName(keymap[GameKeySlick.BUTTON_F]), (keynum == 9));
	NormalFontSlick.printFontGrid(2, 14, "QUIT        : " + getKeyName(keymap[GameKeySlick.BUTTON_QUIT]), (keynum == 10));
	NormalFontSlick.printFontGrid(2, 15, "PAUSE       : " + getKeyName(keymap[GameKeySlick.BUTTON_PAUSE]), (keynum == 11));
	NormalFontSlick.printFontGrid(2, 16, "GIVEUP      : " + getKeyName(keymap[GameKeySlick.BUTTON_GIVEUP]), (keynum == 12));
	NormalFontSlick.printFontGrid(2, 17, "RETRY       : " + getKeyName(keymap[GameKeySlick.BUTTON_RETRY]), (keynum == 13));
	NormalFontSlick.printFontGrid(2, 18, "FRAME STEP  : " + getKeyName(keymap[GameKeySlick.BUTTON_FRAMESTEP]), (keynum == 14));
	NormalFontSlick.printFontGrid(2, 19, "SCREEN SHOT : " + getKeyName(keymap[GameKeySlick.BUTTON_SCREENSHOT]), (keynum == 15));
	NormalFontSlick.printFontGrid(2, 20, "[SAVE & EXIT]", (keynum == 16));

	NormalFontSlick.printFontGrid(1, 4 + keynum, "b", NormalFontSlick.COLOR_RED);

	if(frame >= KEYACCEPTFRAME) {
		if(keyConfigRestFrame > 0) {
			NormalFontSlick.printFontGrid(1, 22, "PUSH KEY... " + GeneralUtil.getTime(keyConfigRestFrame), NormalFontSlick.COLOR_PINK);
		} else if(keynum < NUM_KEYS) {
			NormalFontSlick.printFontGrid(1, 22, "UP/DOWN:   MOVE CURSOR", NormalFontSlick.COLOR_GREEN);
			NormalFontSlick.printFontGrid(1, 23, "ENTER:     SET KEY", NormalFontSlick.COLOR_GREEN);
			NormalFontSlick.printFontGrid(1, 24, "DELETE:    SET TO NONE", NormalFontSlick.COLOR_GREEN);
			NormalFontSlick.printFontGrid(1, 25, "BACKSPACE: CANCEL", NormalFontSlick.COLOR_GREEN);
		} else {
			NormalFontSlick.printFontGrid(1, 22, "UP/DOWN:   MOVE CURSOR", NormalFontSlick.COLOR_GREEN);
			NormalFontSlick.printFontGrid(1, 23, "ENTER:     SAVE & EXIT", NormalFontSlick.COLOR_GREEN);
			NormalFontSlick.printFontGrid(1, 24, "BACKSPACE: CANCEL", NormalFontSlick.COLOR_GREEN);
		}
	}

	// FPS
	NullpoMinoSlick.drawFPS(container);
	// Observer
	NullpoMinoSlick.drawObserverClient();
	if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
}
 
Example 8
Source File: StateConfigJoystickButton.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	if(!container.hasFocus()) {
		if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
		return;
	}

	g.drawImage(ResourceHolderSlick.imgMenu, 0, 0);

	NormalFontSlick.printFontGrid(1, 1, "JOYSTICK SETTING (" + (player + 1) + "P)", NormalFontSlick.COLOR_ORANGE);

	if(joyNumber < 0)
		NormalFontSlick.printFontGrid(1, 3, "NO JOYSTICK", NormalFontSlick.COLOR_RED);
	else
		NormalFontSlick.printFontGrid(1, 3, "JOYSTICK NUMBER:" + joyNumber, NormalFontSlick.COLOR_RED);

	//NormalFont.printFontGrid(2, 3, "UP             : " + String.valueOf(buttonmap[GameKey.BUTTON_UP]), (keynum == 0));
	//NormalFont.printFontGrid(2, 4, "DOWN           : " + String.valueOf(buttonmap[GameKey.BUTTON_DOWN]), (keynum == 1));
	//NormalFont.printFontGrid(2, 5, "LEFT           : " + String.valueOf(buttonmap[GameKey.BUTTON_LEFT]), (keynum == 2));
	//NormalFont.printFontGrid(2, 6, "RIGHT          : " + String.valueOf(buttonmap[GameKey.BUTTON_RIGHT]), (keynum == 3));
	NormalFontSlick.printFontGrid(2, 5, "A (L/R-ROT)    : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_A]), (keynum == 4));
	NormalFontSlick.printFontGrid(2, 6, "B (R/L-ROT)    : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_B]), (keynum == 5));
	NormalFontSlick.printFontGrid(2, 7, "C (L/R-ROT)    : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_C]), (keynum == 6));
	NormalFontSlick.printFontGrid(2, 8, "D (HOLD)       : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_D]), (keynum == 7));
	NormalFontSlick.printFontGrid(2, 9, "E (180-ROT)    : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_E]), (keynum == 8));
	NormalFontSlick.printFontGrid(2, 10, "F              : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_F]), (keynum == 9));
	NormalFontSlick.printFontGrid(2, 11, "QUIT           : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_QUIT]), (keynum == 10));
	NormalFontSlick.printFontGrid(2, 12, "PAUSE          : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_PAUSE]), (keynum == 11));
	NormalFontSlick.printFontGrid(2, 13, "GIVEUP         : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_GIVEUP]), (keynum == 12));
	NormalFontSlick.printFontGrid(2, 14, "RETRY          : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_RETRY]), (keynum == 13));
	NormalFontSlick.printFontGrid(2, 15, "FRAME STEP     : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_FRAMESTEP]), (keynum == 14));
	NormalFontSlick.printFontGrid(2, 16, "SCREEN SHOT    : " + String.valueOf(buttonmap[GameKeySlick.BUTTON_SCREENSHOT]), (keynum == 15));

	NormalFontSlick.printFontGrid(1, 5 + keynum - 4, "b", NormalFontSlick.COLOR_RED);
	if(frame >= KEYACCEPTFRAME) {
		NormalFontSlick.printFontGrid(1, 20, "UP/DOWN:   MOVE CURSOR", NormalFontSlick.COLOR_GREEN);
		NormalFontSlick.printFontGrid(1, 21, "ENTER:     OK",     NormalFontSlick.COLOR_GREEN);
		NormalFontSlick.printFontGrid(1, 22, "DELETE:    NO SET", NormalFontSlick.COLOR_GREEN);
		NormalFontSlick.printFontGrid(1, 23, "BACKSPACE: CANCEL", NormalFontSlick.COLOR_GREEN);
	}

	// FPS
	NullpoMinoSlick.drawFPS(container);
	// Observer
	NullpoMinoSlick.drawObserverClient();
	if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep();
}
 
Example 9
Source File: StateInGame.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	if(!container.hasFocus()) {
		if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep(true);
		return;
	}

	// Game screen
	if(gameManager != null) {
		gameManager.renderAll();

		if((gameManager.engine.length > 0) && (gameManager.engine[0] != null)) {
			int offsetX = gameManager.receiver.getFieldDisplayPositionX(gameManager.engine[0], 0);
			int offsetY = gameManager.receiver.getFieldDisplayPositionY(gameManager.engine[0], 0);

			// Pause menu
			if(pause && !enableframestep && !pauseMessageHide) {
				NormalFontSlick.printFont(offsetX + 12, offsetY + 188 + (cursor * 16), "b", NormalFontSlick.COLOR_RED);

				NormalFontSlick.printFont(offsetX + 28, offsetY + 188, "CONTINUE", (cursor == 0));
				NormalFontSlick.printFont(offsetX + 28, offsetY + 204, "RETRY", (cursor == 1));
				NormalFontSlick.printFont(offsetX + 28, offsetY + 220, "END", (cursor == 2));
				if(gameManager.replayMode && !gameManager.replayRerecord)
					NormalFontSlick.printFont(offsetX + 28, offsetY + 236, "RERECORD", (cursor == 3));
			}

			// Fast forward
			if(fastforward != 0)
				NormalFontSlick.printFont(offsetX, offsetY + 376, "e" + (fastforward + 1), NormalFontSlick.COLOR_ORANGE);
			if(gameManager.replayShowInvisible)
				NormalFontSlick.printFont(offsetX, offsetY + 392, "SHOW INVIS", NormalFontSlick.COLOR_ORANGE);
		}
	}

	// FPS
	NullpoMinoSlick.drawFPS(container, true);
	// Observer
	NullpoMinoSlick.drawObserverClient();
	// Screenshot
	if(ssflag) {
		NullpoMinoSlick.saveScreenShot(container, g);
		ssflag = false;
	}

	if(!NullpoMinoSlick.alternateFPSTiming) NullpoMinoSlick.alternateFPSSleep(true);
}