org.newdawn.slick.Input Java Examples

The following examples show how to use org.newdawn.slick.Input. 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: MouseInputSlick.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void update(Input input) {
	mouseX = input.getMouseX();
	mouseY = input.getMouseY();
	if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
		mousePressed[0]++;
	} else {
		mousePressed[0] = 0;
	}
	if (input.isMouseButtonDown(Input.MOUSE_MIDDLE_BUTTON)) {
		mousePressed[1]++;
	} else {
		mousePressed[1] = 0;
	}
	if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
		mousePressed[2]++;
	} else {
		mousePressed[2] = 0;
	}
}
 
Example #2
Source File: SongMenu.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
	// block input
	if (isInputBlocked())
		return;

	// check mouse button
	if (input.isMouseButtonDown(Input.MOUSE_MIDDLE_BUTTON))
		return;

	int diff = newy - oldy;
	if (diff == 0)
		return;

	// score buttons
	if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(oldx, oldy))
		startScorePos.dragged(-diff);

	// song buttons
	else {
		if (songScrolling.isPressed())
			songScrolling.dragged(-diff);
		else if (songScrolling.getSpeedMultiplier() == FAST_SCROLL_SPEED)  // make sure mousePressed() preceded this event
			scrollSongsToPosition(newy);
	}
}
 
Example #3
Source File: BigImageTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
 */
public void update(GameContainer container, int delta) throws SlickException {
	ang += delta * 0.1f;
	
	if (container.getInput().isKeyDown(Input.KEY_LEFT)) {
		x -= delta * 0.1f;
	}
	if (container.getInput().isKeyDown(Input.KEY_RIGHT)) {
		x += delta * 0.1f;
	}
	if (container.getInput().isKeyDown(Input.KEY_UP)) {
		y -= delta * 0.1f;
	}
	if (container.getInput().isKeyDown(Input.KEY_DOWN)) {
		y += delta * 0.1f;
	}
}
 
Example #4
Source File: SongMenu.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Starts the game.
 */
private void startGame() {
	if (MusicController.isTrackLoading())
		return;

	Beatmap beatmap = MusicController.getBeatmap();
	if (focusNode == null || beatmap != focusNode.getSelectedBeatmap()) {
		UI.getNotificationManager().sendBarNotification("Unable to load the beatmap audio.");
		return;
	}

	// turn on "auto" mod if holding "ctrl" key
	if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
		if (!GameMod.AUTO.isActive())
			GameMod.AUTO.toggle(true);
	}

	SoundController.playSound(SoundEffect.MENUHIT);
	MultiClip.destroyExtraClips();
	Game gameState = (Game) game.getState(Opsu.STATE_GAME);
	gameState.loadBeatmap(beatmap);
	gameState.setPlayState(Game.PlayState.FIRST_LOAD);
	gameState.setReplay(null);
	game.enterState(Opsu.STATE_GAME, new EasedFadeOutTransition(), new FadeInTransition());
}
 
Example #5
Source File: Game.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adjusts the beatmap's local music offset.
 * @param sign the sign (multiplier)
 */
private void adjustLocalMusicOffset(int sign) {
	if (pauseTime > -1) {
		UI.getNotificationManager().sendBarNotification("Offset can only be changed while game is not paused.");
		return;
	}

	boolean alt = input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT);
	int diff = sign * (alt ? 1 : 5);
	int newOffset = Utils.clamp(beatmap.localMusicOffset + diff, -1000, 1000);
	UI.getNotificationManager().sendBarNotification(String.format("Local beatmap offset set to %dms", newOffset));
	if (beatmap.localMusicOffset != newOffset) {
		beatmap.localMusicOffset = newOffset;
		BeatmapDB.updateLocalOffset(beatmap);
	}
}
 
Example #6
Source File: Game.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseReleased(int button, int x, int y) {
	if (gameFinished)
		return;

	if (Options.isMouseDisabled())
		return;

	if (button == Input.MOUSE_MIDDLE_BUTTON)
		return;

	int keys = ReplayFrame.KEY_NONE;
	if (button == Input.MOUSE_LEFT_BUTTON)
		keys = ReplayFrame.KEY_M1;
	else if (button == Input.MOUSE_RIGHT_BUTTON)
		keys = ReplayFrame.KEY_M2;
	if (keys != ReplayFrame.KEY_NONE)
		gameKeyReleased(keys, x, y, MusicController.getPosition(true));
}
 
Example #7
Source File: DownloadsMenu.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
	// block input during beatmap importing
	if (importThread != null)
		return;

	// check mouse button
	if (!input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON) &&
		!input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON))
		return;

	int diff = newy - oldy;
	if (diff == 0)
		return;
	startDownloadIndexPos.dragged(-diff);
	startResultPos.dragged(-diff);
}
 
Example #8
Source File: UserSelectOverlay.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mousePressed(int button, int x, int y) {
	if (!active)
		return;

	if (!contains(x, y)) {
		if (consumeAndClose) {
			consumeEvent();
			listener.close(false);
		}
		return;
	}

	consumeEvent();

	if (button == Input.MOUSE_MIDDLE_BUTTON)
		return;

	scrolling.pressed();
	mousePressY = y;

	if (state == State.USER_SELECT)
		selectedButton = getButtonAtPosition(x, y);
}
 
Example #9
Source File: ButtonMenu.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void keyPressed(int key, char c) {
	if (UI.globalKeyPressed(key))
		return;

	switch (key) {
	case Input.KEY_ESCAPE:
		if (menuState != null)
			menuState.leave(container, game);
		break;
	default:
		if (menuState != null)
			menuState.keyPress(container, game, key, c);
		break;
	}
}
 
Example #10
Source File: InputTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
 */
public void update(GameContainer container, int delta) {
       lshift = container.getInput().isKeyDown(Input.KEY_LSHIFT);
       rshift = container.getInput().isKeyDown(Input.KEY_RSHIFT);
       space = container.getInput().isKeyDown(Input.KEY_SPACE); 
       
	if (controllerLeft[0]) {
		x -= delta * 0.1f;
	}
	if (controllerRight[0]) {
		x += delta * 0.1f;
	}
	if (controllerUp[0]) {
		y -= delta * 0.1f;
	}
	if (controllerDown[0]) {
		y += delta * 0.1f;
	}
}
 
Example #11
Source File: GUITest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	if (key == Input.KEY_ESCAPE) {
		System.exit(0);
	}
	if (key == Input.KEY_F2) {
		app.setDefaultMouseCursor();
	}
	if (key == Input.KEY_F1) {
		if (app != null) {
			try {
				app.setDisplayMode(640,480,false);		
			} catch (SlickException e) {
				Log.error(e);
			}
		}
	}
}
 
Example #12
Source File: TestState3.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.state.BasicGameState#keyReleased(int, char)
 */
public void keyReleased(int key, char c) {
	if (key == Input.KEY_DOWN) {
		selected++;
		if (selected >= options.length) {
			selected = 0;
		}
	}
	if (key == Input.KEY_UP) {
		selected--;
		if (selected < 0) {
			selected = options.length - 1;
		}
	}
	if (key == Input.KEY_1) {
		game.enterState(TestState1.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
	}
	if (key == Input.KEY_2) {
		game.enterState(TestState2.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
	}
}
 
Example #13
Source File: GeomAccuracyTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	if (key == Input.KEY_ESCAPE) {
		System.exit(0);
	}
	
	if(key == Input.KEY_N) {
		curTest++;
		curTest %= NUMTESTS;
	}
	
	if(key == Input.KEY_C) {
		colorIndex++;
		
		colorIndex %= 4;
		setColors();
	}
	
	if(key == Input.KEY_T) {
		hideOverlay = !hideOverlay;
	}

}
 
Example #14
Source File: Scroller.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @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 #15
Source File: UI.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Processes global hotkey actions.
 * @param key the key code that was pressed
 * @return {@code true} if a global hotkey was pressed
 */
public static boolean globalKeyPressed(int key) {
	switch (key) {
	case Input.KEY_F7:
		Options.setNextFPS(container);
		break;
	case Input.KEY_F10:
		Options.toggleMouseDisabled();
		break;
	case Input.KEY_F12:
		Utils.takeScreenShot();
		break;
	default:
		return false;
	}
	return true;
}
 
Example #16
Source File: DropdownMenu.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void mousePressed(int button, int x, int y) {
	if (!active)
		return;

	if (button == Input.MOUSE_MIDDLE_BUTTON)
		return;

	int idx = getIndexAt(x, y);
	if (idx == -2) {
		this.expanded = false;
		return;
	}
	if (!menuClicked(idx))
		return;
	this.expanded = (idx == -1) ? !expanded : false;
	if (idx >= 0 && itemIndex != idx) {
		this.itemIndex = idx;
		itemSelected(idx, items[idx]);
	}
	blockClick = true;
	consumeEvent();
}
 
Example #17
Source File: TestState1.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.state.BasicGameState#keyReleased(int, char)
 */
public void keyReleased(int key, char c) {
	
	if (key == Input.KEY_2) {
		GameState target = game.getState(TestState2.ID);
		
		final long start = System.currentTimeMillis();
		CrossStateTransition t = new CrossStateTransition(target) {				
			public boolean isComplete() {
				return (System.currentTimeMillis() - start) > 2000;
			}

			public void init(GameState firstState, GameState secondState) {
			}
		};
		
		game.enterState(TestState2.ID, t, new EmptyTransition());
	}
	if (key == Input.KEY_3) {
		game.enterState(TestState3.ID, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
	}
}
 
Example #18
Source File: ControllerManager.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Joystick If you hold ontrue
 * @param player Player number
 * @param input InputClass (container.getInput()Can be obtained by)
 * @return Press down on thetrue
 */
public static boolean isControllerUp(int player, Input input) {
	try {
		int controller = controllerID[player];

		if(controller < 0) return false;

		if(method == CONTROLLER_METHOD_SLICK_DEFAULT) {
			return input.isControllerUp(controller);
		} else if(method == CONTROLLER_METHOD_SLICK_ALTERNATE) {
			return input.isControllerUp(controller) || (!ignoreAxis[player] && (input.getAxisValue(controller, 1) < -border[player]));
		} else if(method == CONTROLLER_METHOD_LWJGL) {
			if((controller >= 0) && (controller < controllers.size())) {
				float axisValue = controllers.get(controller).getYAxisValue();
				float povValue = controllers.get(controller).getPovY();
				return (!ignoreAxis[player] && (axisValue < -border[player])) || (!ignorePOV[player] && (povValue < -border[player]));
			}
		}
	} catch (Throwable e) {
		log.debug("Exception on isControllerUp", e);
	}
	return false;
}
 
Example #19
Source File: ControllerManager.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Joystick When I press the bottom of thetrue
 * @param player Player number
 * @param input InputClass (container.getInput()Can be obtained by)
 * @return If you hold undertrue
 */
public static boolean isControllerDown(int player, Input input) {
	try {
		int controller = controllerID[player];

		if(controller < 0) return false;

		if(method == CONTROLLER_METHOD_SLICK_DEFAULT) {
			return input.isControllerDown(controller);
		} else if(method == CONTROLLER_METHOD_SLICK_ALTERNATE) {
			return input.isControllerDown(controller) || (!ignoreAxis[player] && (input.getAxisValue(controller, 1) > border[player]));
		} else if(method == CONTROLLER_METHOD_LWJGL) {
			if((controller >= 0) && (controller < controllers.size())) {
				float axisValue = controllers.get(controller).getYAxisValue();
				float povValue = controllers.get(controller).getPovY();
				return (!ignoreAxis[player] && (axisValue > border[player])) || (!ignorePOV[player] && (povValue > border[player]));
			}
		}
	} catch (Throwable e) {
		log.debug("Exception on isControllerDown", e);
	}
	return false;
}
 
Example #20
Source File: ControllerManager.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Joystick When I press the righttrue
 * @param player Player number
 * @param input InputClass (container.getInput()Can be obtained by)
 * @return If you hold the righttrue
 */
public static boolean isControllerRight(int player, Input input) {
	try {
		int controller = controllerID[player];

		if(controller < 0) return false;

		if(method == CONTROLLER_METHOD_SLICK_DEFAULT) {
			return input.isControllerRight(controller);
		} else if(method == CONTROLLER_METHOD_SLICK_ALTERNATE) {
			return input.isControllerRight(controller) || (!ignoreAxis[player] && (input.getAxisValue(controller, 0) > border[player]));
		} else if(method == CONTROLLER_METHOD_LWJGL) {
			if((controller >= 0) && (controller < controllers.size())) {
				float axisValue = controllers.get(controller).getXAxisValue();
				float povValue = controllers.get(controller).getPovX();
				return (!ignoreAxis[player] && (axisValue > border[player])) || (!ignorePOV[player] && (povValue > border[player]));
			}
		}
	} catch (Throwable e) {
		log.debug("Exception on isControllerRight", e);
	}
	return false;
}
 
Example #21
Source File: AnimationTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	if (key == Input.KEY_ESCAPE) {
		container.exit();
	}
	if (key == Input.KEY_SPACE) {
		limited.restart();
	}
}
 
Example #22
Source File: TransformTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	if (key == Input.KEY_ESCAPE) {
		System.exit(0);
	}
	if (key == Input.KEY_Q) {
		scaleUp = true;
	}
	if (key == Input.KEY_A) {
		scaleDown = true;
	}
}
 
Example #23
Source File: TransformTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyReleased(int, char)
 */
public void keyReleased(int key, char c) {
	if (key == Input.KEY_Q) {
		scaleUp = false;
	}
	if (key == Input.KEY_A) {
		scaleDown = false;
	}
}
 
Example #24
Source File: ImageOutTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
 */
public void update(GameContainer container, int delta) throws SlickException {
	fire.update(delta);
	
	if (container.getInput().isKeyPressed(Input.KEY_P)) {
		writeTo(System.getProperty("java.io.tmpdir") + File.separator + "ImageOutTest.png");
	}
	if (container.getInput().isKeyPressed(Input.KEY_J)) {
		writeTo(System.getProperty("java.io.tmpdir") + File.separator + "ImageOutTest.jpg");
	}
	if (container.getInput().isKeyPressed(Input.KEY_T)) {
		writeTo(System.getProperty("java.io.tmpdir") + File.separator + "ImageOutTest.tga");
	}
}
 
Example #25
Source File: KeyRepeatTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	count++;
	if (key == Input.KEY_SPACE) {
		if (input.isKeyRepeatEnabled()) {
			input.disableKeyRepeat();
		} else {
			input.enableKeyRepeat(300,100);
		}
	}
}
 
Example #26
Source File: UI.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Processes global mouse wheel actions.
 * @param delta the amount the wheel has moved
 * @param requiresAlt if the "ALT" key must be pressed
 * @return {@code true} if a global mouse wheel action was processed
 */
public static boolean globalMouseWheelMoved(int delta, boolean requiresAlt) {
	if (!requiresAlt || (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT))) {
		UI.changeVolume((delta < 0) ? -1 : 1);
		return true;
	}
	return false;
}
 
Example #27
Source File: Utils.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns true if a game input key is pressed (mouse/keyboard left/right).
 * @return true if pressed
 */
public static boolean isGameKeyPressed() {
	boolean mouseDown = !Options.isMouseDisabled() && (
			input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ||
			input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON));
	return (mouseDown ||
			input.isKeyDown(Options.getGameKeyLeft()) ||
			input.isKeyDown(Options.getGameKeyRight()));
}
 
Example #28
Source File: NavMeshTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Update data map etc
 */
public void update(GameContainer container, int delta)
		throws SlickException {
	if (container.getInput().isKeyPressed(Input.KEY_1)) {
		showLinks = !showLinks;
	}
	if (container.getInput().isKeyPressed(Input.KEY_2)) {
		showSpaces = !showSpaces;
	}
}
 
Example #29
Source File: ParticleTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	if (key == Input.KEY_ESCAPE) {
		System.exit(0);
	}
	if (key == Input.KEY_SPACE) {
		mode = ParticleSystem.BLEND_ADDITIVE == mode ? ParticleSystem.BLEND_COMBINE : ParticleSystem.BLEND_ADDITIVE;
		system.setBlendingMode(mode);
	}
}
 
Example #30
Source File: FontTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	if (key == Input.KEY_ESCAPE) {
		System.exit(0);
	}
	if (key == Input.KEY_SPACE) {
		try {
			container.setDisplayMode(640, 480, false);
		} catch (SlickException e) {
			Log.error(e);
		}
	}
}