Java Code Examples for org.newdawn.slick.Input

The following examples show how to use org.newdawn.slick.Input. 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
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
/**
 * @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 3
/**
 * 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 4
/**
 * 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 5
/**
 * 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 6
Source Project: opsu   Source File: UserSelectOverlay.java    License: 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 7
Source Project: opsu   Source File: Game.java    License: 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 8
Source Project: opsu   Source File: Game.java    License: 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 9
/**
 * @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 10
Source Project: opsu   Source File: SongMenu.java    License: 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 11
Source Project: opsu   Source File: SongMenu.java    License: 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 12
Source Project: opsu   Source File: DownloadsMenu.java    License: 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 13
Source Project: opsu   Source File: ButtonMenu.java    License: 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 14
Source Project: opsu   Source File: DropdownMenu.java    License: 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 15
Source Project: opsu   Source File: UI.java    License: 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
/**
 * @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 17
/**
 * @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 18
/**
 * @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 19
/**
 * @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 20
/**
 * @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 21
/**
 * @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) {
		clip = !clip;
	}
}
 
Example 22
/**
 * When a key is pressed
 * @param key Keycode
 */
protected void onKey(int key) {
	if(frame >= KEYACCEPTFRAME) {
		// Backspace & Enter/Return
		if((key == Input.KEY_BACK) || (key == Input.KEY_RETURN)) {
			gameObj.enterState(StateConfigJoystickMain.ID);
		}
	}
}
 
Example 23
/**
 * Update button input status
 * @param input Slick's Input class (You can get it with container.getInput())
 * @param ingame true if ingame
 */
public void update(Input input, boolean ingame) {
	if((player == 0) && (NullpoMinoSlick.useJInputKeyboard)) {
		JInputManager.poll();
	}

	for(int i = 0; i < MAX_BUTTON; i++) {
		int[] kmap = ingame ? keymap : keymapNav;

		boolean flag = false;
		if(kmap[i] != 0) {
			flag = NullpoMinoSlick.useJInputKeyboard ?
					JInputManager.isKeyDown(kmap[i]) : input.isKeyDown(kmap[i]);
		}

		switch(i) {
		case BUTTON_UP:
			flag |= ControllerManager.isControllerUp(player, input);
			break;
		case BUTTON_DOWN:
			flag |= ControllerManager.isControllerDown(player, input);
			break;
		case BUTTON_LEFT:
			flag |= ControllerManager.isControllerLeft(player, input);
			break;
		case BUTTON_RIGHT:
			flag |= ControllerManager.isControllerRight(player, input);
			break;
		default:
			flag |= ControllerManager.isControllerButton(player, input, buttonmap[i]);
			break;
		}

		if(flag){
			inputstate[i]++;
		}
		else inputstate[i] = 0;
	}
}
 
Example 24
Source Project: opsu   Source File: UserSelectOverlay.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(int key, char c) {
	if (!active)
		return;

	consumeEvent();

	// esc: close overlay or clear text
	if (key == Input.KEY_ESCAPE) {
		if (state == State.CREATE_USER && !textField.getText().isEmpty()) {
			textField.setText("");
			newUser.setName("");
		} else
			listener.close(false);
		return;
	}

	if (UI.globalKeyPressed(key))
		return;

	// key entry
	if (state == State.CREATE_USER) {
		// enter: create user
		if (key == Input.KEY_ENTER) {
			createNewUser();
			return;
		}

		textField.setFocus(true);
		textField.keyPressed(key, c);
		textField.setFocus(false);
		newUser.setName(textField.getText());
		if (c > 255 && Character.isLetterOrDigit(c)) {
			Fonts.loadGlyphs(Fonts.LARGE, c);
			Fonts.loadGlyphs(Fonts.MEDIUM, c);
		}
	}
}
 
Example 25
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	if (key == Input.KEY_1) {
		world = false;
		clip = false;
	}
	if (key == Input.KEY_2) {
		world = false;
		clip = true;
	}
	if (key == Input.KEY_3) {
		world = true;
		clip = false;
	}
}
 
Example 26
/**
 * Update the game
 * 
 * @param container The container the game is running in
 * @param delta The amount of time that passed since last update (in seconds)
 */
public void update(GameContainer container, int delta)
		throws SlickException {
	// toggle the lighting on/off
	if (container.getInput().isKeyPressed(Input.KEY_L)){
		lightingOn = !lightingOn;
	}
	// toggle the use of coloured lighting on/off
	if (container.getInput().isKeyPressed(Input.KEY_C)){
		colouredLights = !colouredLights;
		// we need to recaculate the lighting values because
		// colours may now be involved
		updateLightMap();
	}
}
 
Example 27
Source Project: opsu   Source File: SongMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mousePressed(int button, int x, int y) {
	// check mouse button
	if (button == Input.MOUSE_MIDDLE_BUTTON)
		return;

	// block input
	if (isInputBlocked())
		return;

	if (showOptionsOverlay || !optionsOverlayProgress.isFinished() ||
	    showUserOverlay || !userOverlayProgress.isFinished())
		return;

	if (isScrollingToFocusNode)
		return;

	if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
		songScrolling.setSpeedMultiplier(FAST_SCROLL_SPEED);

		// check if anything was clicked
		for (BeatmapGroup group : BeatmapGroup.values()) {
			if (group.contains(x, y))
				return;
		}
		if (UI.getBackButton().contains(x, y) ||
		    selectModsButton.contains(x, y) || selectRandomButton.contains(x, y) ||
		    selectMapOptionsButton.contains(x, y) || selectOptionsButton.contains(x, y) ||
		    focusNode == null || getNodeAtPosition(x, y) != null ||
		    footerLogoButton.contains(x, y, 0.25f) || ScoreData.areaContains(x, y))
			return;

		// scroll to the mouse position on the screen
		scrollSongsToPosition(y);
	} else
		songScrolling.pressed();
	startScorePos.pressed();
}
 
Example 28
Source Project: opsu   Source File: DownloadsMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mouseReleased(int button, int x, int y) {
	// check mouse button
	if (button == Input.MOUSE_MIDDLE_BUTTON)
		return;

	startDownloadIndexPos.released();
	startResultPos.released();
}
 
Example 29
Source Project: opsu   Source File: Splash.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(int key, char c) {
	if (key == Input.KEY_ESCAPE) {
		// close program
		if (++escapeCount >= 3)
			container.exit();

		// stop parsing beatmaps by sending interrupt to BeatmapParser
		else if (thread != null)
			thread.interrupt();
	}
}
 
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 mousePressed(int button, int x, int y) {
	// check mouse button
	if (button == Input.MOUSE_MIDDLE_BUTTON)
		return;

	if (menuState != null)
		menuState.click(container, game, x, y);
}