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

The following examples show how to use org.newdawn.slick.GameContainer#getInput() . 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: GameRanking.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void init(GameContainer container, StateBasedGame game)
		throws SlickException {
	this.game = game;
	this.input = container.getInput();

	int width = container.getWidth();
	int height = container.getHeight();

	// buttons
	Image retry = GameImage.PAUSE_RETRY.getImage();
	Image replay = GameImage.PAUSE_REPLAY.getImage();
	replayY = (height * 0.985f) - replay.getHeight() / 2f;
	retryY = replayY - (replay.getHeight() / 2f) - (retry.getHeight() / 1.975f);
	retryButton = new MenuButton(retry, width - (retry.getWidth() / 2f), retryY);
	replayButton = new MenuButton(replay, width - (replay.getWidth() / 2f), replayY);
	retryButton.setHoverFade();
	replayButton.setHoverFade();
}
 
Example 2
Source File: UI.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes UI data.
 * @param container the game container
 * @param game the game object
 */
public static void init(GameContainer container, StateBasedGame game) {
	UI.container = container;
	UI.game = game;
	UI.input = container.getInput();

	// cursor
	Cursor.init(container, game);
	cursor.hide();

	// back button
	backButton = new BackButton(container);

	// notification manager
	notificationManager = new NotificationManager(container);
}
 
Example 3
Source File: GamePauseMenu.java    From opsu with 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();
	this.gameState = (Game) game.getState(Opsu.STATE_GAME);
}
 
Example 4
Source File: Game.java    From opsu with 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;
	input = container.getInput();

	int width = container.getWidth();
	int height = container.getHeight();

	// create offscreen graphics
	offscreen = new Image(width, height);
	gOffscreen = offscreen.getGraphics();
	gOffscreen.setBackground(Color.black);

	// initialize music position bar location
	musicBarX = width * 0.01f;
	musicBarY = height * 0.05f;
	musicBarWidth = Math.max(width * 0.005f, 7);
	musicBarHeight = height * 0.9f;

	// initialize scoreboard star stream
	scoreboardStarStream = new StarStream(0, height * 2f / 3f, width / 4, 0, 0);
	scoreboardStarStream.setPositionSpread(height / 20f);
	scoreboardStarStream.setDirectionSpread(10f);
	scoreboardStarStream.setDurationSpread(700, 100);

	// create the associated GameData object
	data = new GameData(width, height);
}
 
Example 5
Source File: ButtonMenu.java    From opsu with 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 6
Source File: Cursor.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes the class.
 * @param container the game container
 * @param game the game object
 */
public static void init(GameContainer container, StateBasedGame game) {
	Cursor.container = container;
	Cursor.game = game;
	Cursor.input = container.getInput();

	// create empty cursor to simulate hiding the cursor
	try {
		int min = org.lwjgl.input.Cursor.getMinCursorSize();
		IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
		emptyCursor = new org.lwjgl.input.Cursor(min, min, min/2, min/2, 1, tmp, null);
	} catch (LWJGLException e) {
		ErrorHandler.error("Failed to create hidden cursor.", e, true);
	}
}
 
Example 7
Source File: InputProviderTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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 8
Source File: InputTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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 9
Source File: OptionsOverlay.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the options overlay.
 * @param container the game container
 * @param groups the option groups
 * @param listener the event listener
 */
public OptionsOverlay(GameContainer container, OptionGroup[] groups, OptionsOverlayListener listener) {
	super(container);
	this.container = container;
	this.groups = groups;
	this.listener = listener;

	this.input = container.getInput();
	this.containerWidth = container.getWidth();
	this.containerHeight = container.getHeight();

	// control images
	this.iconSize = (int) (18 * GameImage.getUIscale());
	this.sliderBallImg = GameImage.CONTROL_SLIDER_BALL.getImage().getScaledCopy(iconSize, iconSize);
	this.checkOnImg = GameImage.CONTROL_CHECK_ON.getImage().getScaledCopy(iconSize, iconSize);
	this.checkOffImg = GameImage.CONTROL_CHECK_OFF.getImage().getScaledCopy(iconSize, iconSize);
	int searchImgSize = (int) (Fonts.LARGE.getLineHeight() * 0.75f);
	this.searchImg = GameImage.SEARCH.getImage().getScaledCopy(searchImgSize, searchImgSize);

	boolean isWidescreen = (int) (container.getAspectRatio() * 1000) > 1500; // 1333 = 4:3, 1777 = 16:9

	// overlay positions
	this.x = 0;
	this.y = 0;
	this.targetWidth = (int) (containerWidth * (isWidescreen ? 0.4f : 0.5f));
	this.height = containerHeight;

	// option positions
	float navIconWidthRatio = isWidescreen ? 0.046875f : 0.065f; // non-widescreen ratio is not accurate
	navButtonSize = (int) (container.getWidth() * navIconWidthRatio);
	navIndicatorWidth = navButtonSize / 10;
	navTargetWidth = (int) (targetWidth * 0.45f) - navButtonSize;
	this.paddingRight = (int) (containerWidth * 0.009375f); // not so accurate
	this.paddingLeft = navButtonSize + (int) (containerWidth * 0.0180f); // not so accurate
	this.paddingTextLeft = paddingLeft + LINE_WIDTH + (int) (containerWidth * 0.00625f); // not so accurate
	this.optionStartX = paddingTextLeft;
	this.textOptionsY = Fonts.LARGE.getLineHeight() * 2;
	this.textChangeY = textOptionsY + Fonts.LARGE.getLineHeight();
	this.searchY = textChangeY + Fonts.MEDIUM.getLineHeight() * 2;
	this.textSearchYOffset = Fonts.MEDIUM.getLineHeight() / 2;
	this.optionStartY = searchY + Fonts.MEDIUM.getLineHeight() + Fonts.LARGE.getLineHeight();
	int paddingX = 24;
	this.optionWidth = targetWidth - paddingX * 2;
	this.optionHeight = (int) (Fonts.MEDIUM.getLineHeight() * 1.3f);
	this.optionGroupPadding = (int) (Fonts.LARGE.getLineHeight() * 1.5f);
	this.optionTextOffsetY = (int) ((optionHeight - Fonts.MEDIUM.getLineHeight()) / 2f);
	this.controlImageSize = (int) (Fonts.MEDIUM.getLineHeight() * 0.7f);
	this.controlImagePadding = (optionHeight - controlImageSize) / 2;

	// back button
	int backSize = Fonts.XLARGE.getLineHeight() * 2 / 3;
	Image backArrow = GameImage.CHEVRON_LEFT.getImage().getScaledCopy(backSize, backSize);
	this.backButton = new MenuButton(backArrow, 0, 0);
	backButton.setHoverExpand(1.5f);

	// restart button
	Image restartImg = GameImage.UPDATE.getImage().getScaledCopy(backSize, backSize);
	this.restartButton = new MenuButton(restartImg, 0, 0);
	restartButton.setHoverAnimationDuration(2000);
	restartButton.setHoverRotate(360);

	// search field
	this.searchField = new TextField(container, null, 0, 0, 0, 0);
	searchField.setMaxLength(20);

	// kinetic scrolling
	this.scrolling = new KineticScrolling();
	scrolling.setAllowOverScroll(true);

	// calculate offset for navigation bar icons
	int navTotalHeight = 0;
	for (OptionGroup group : groups) {
		if (group.getOptions() == null) {
			navTotalHeight += navButtonSize;
		}
	}
	navStartY = (height - navTotalHeight) / 2;
}
 
Example 10
Source File: UserSelectOverlay.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the user selection overlay.
 * @param container the game container
 * @param listener the event listener
 */
public UserSelectOverlay(GameContainer container, UserSelectOverlayListener listener) {
	super(container);
	this.listener = listener;

	this.input = container.getInput();
	this.containerWidth = container.getWidth();
	this.containerHeight = container.getHeight();

	// overlay positions
	this.x = containerWidth / 3;
	this.y = 0;
	this.width = containerWidth / 3;
	this.height = containerHeight;

	// user positions
	this.titleY = Fonts.LARGE.getLineHeight() * 2;
	this.usersStartX = (width - UserButton.getWidth()) / 2;
	this.usersStartY = (int) (titleY + Fonts.XLARGE.getLineHeight() * 1.5f);
	this.usersPaddingY = UserButton.getHeight() / 10;

	// new user
	this.newUser = new User("", UserList.DEFAULT_ICON);
	this.newUserButton = new UserButton(
		(int) (this.x + usersStartX),
		(int) (this.y + usersStartY + Fonts.MEDIUMBOLD.getLineHeight()),
		Color.white
	);
	newUserButton.setUser(newUser);
	newUserButton.setHoverAnimationDuration(400);
	newUserButton.setHoverAnimationEquation(AnimationEquation.LINEAR);

	// new user text field
	this.textField = new TextField(container, null, 0, 0, 0, 0);
	textField.setMaxLength(UserList.MAX_USER_NAME_LENGTH);

	// user icons
	this.userIcons = new MenuButton[UserButton.getIconCount()];
	for (int i = 0; i < userIcons.length; i++) {
		userIcons[i] = new MenuButton(UserButton.getIconImage(i), 0, 0);
		userIcons[i].setHoverFade(0.5f);
	}

	// edit user
	this.editUserButton = new UserButton(
		(int) (this.x + usersStartX),
		(int) (this.y + usersStartY),
		Color.white
	);

	// delete user
	deleteUserButton = new UserButton(
		(int) (this.x + usersStartX),
		(int) (this.y + usersStartY + UserButton.getHeight() + usersPaddingY),
		Colors.RED_HOVER
	);
	deleteUserButton.setHoverAnimationBase(0.5f);

	// kinetic scrolling
	this.scrolling = new KineticScrolling();
	scrolling.setAllowOverScroll(true);
}
 
Example 11
Source File: Utils.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initializes game settings and class data.
 * @param container the game container
 * @param game the game object
 */
public static void init(GameContainer container, StateBasedGame game) {
	input = container.getInput();
	int width = container.getWidth();
	int height = container.getHeight();

	// game settings
	container.setTargetFrameRate(Options.getTargetFPS());
	container.setVSync(Options.getTargetFPS() == 60);
	container.setMusicVolume(Options.getMusicVolume() * Options.getMasterVolume());
	container.setShowFPS(false);
	container.getInput().enableKeyRepeat();
	container.setAlwaysRender(true);
	container.setUpdateOnlyWhenVisible(false);

	// record OpenGL version
	ErrorHandler.setGlString();

	// calculate UI scale
	GameImage.init(width, height);

	// create fonts
	try {
		Fonts.init();
	} catch (Exception e) {
		ErrorHandler.error("Failed to load fonts.", e, true);
	}

	// load skin
	Options.loadSkin();

	// initialize game images
	for (GameImage img : GameImage.values()) {
		if (img.isPreload())
			img.setDefaultImage();
	}

	// initialize game mods
	GameMod.init(width, height);

	// initialize playback buttons
	PlaybackSpeed.init(width, height);

	// initialize hit objects
	HitObject.init(width, height);

	// initialize download nodes
	DownloadNode.init(width, height);

	// initialize UI components
	UI.init(container, game);

	// build user list
	UserList.create();

	// initialize user button
	UserButton.init(width, height);

	// warn about software mode
	if (((Container) container).isSoftwareMode()) {
		UI.getNotificationManager().sendNotification(
			"WARNING:\n" +
			"Running in OpenGL software mode.\n" +
			"You may experience severely degraded performance.\n\n" +
			"This can usually be resolved by updating your graphics drivers.",
			Color.red
		);
	}
}
 
Example 12
Source File: KeyRepeatTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	input = container.getInput();
	input.enableKeyRepeat(300,100);
}