Java Code Examples for org.newdawn.slick.state.StateBasedGame

The following examples show how to use org.newdawn.slick.state.StateBasedGame. 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: ButtonMenu.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Processes a state enter request.
 * @param container the game container
 * @param game the game
 */
public void enter(GameContainer container, StateBasedGame game) {
	float center = container.getWidth() / 2f;
	float centerOffsetX = container.getWidth() * OFFSET_WIDTH_RATIO;
	centerOffset = new AnimatedValue(700, centerOffsetX, 0, AnimationEquation.OUT_BOUNCE);
	for (int i = 0; i < buttons.length; i++) {
		menuButtons[i].setX(center + ((i % 2 == 0) ? centerOffsetX : centerOffsetX * -1));
		menuButtons[i].resetHover();
	}

	// create title string list
	actualTitle = new ArrayList<String>();
	String[] title = getTitle(container, game);
	int maxLineWidth = (int) (container.getWidth() * 0.96f);
	for (int i = 0; i < title.length; i++) {
		// wrap text if too long
		if (Fonts.LARGE.getWidth(title[i]) > maxLineWidth) {
			List<String> list = Fonts.wrap(Fonts.LARGE, title[i], maxLineWidth, false);
			actualTitle.addAll(list);
		} else
			actualTitle.add(title[i]);
	}
}
 
Example 2
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 3
@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 4
/**
 * 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 5
/**
 * 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 6
/**
 * @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void preRender(StateBasedGame game, GameContainer container,
		Graphics g) throws SlickException {
	prev.render(container, game, g);
	
	MaskUtil.defineMask();
	for (int i=0;i<blobs.size();i++) {
		((Blob) blobs.get(i)).render(g);
	}
	MaskUtil.finishDefineMask();

	MaskUtil.drawOnMask();
	if (background != null) {
		Color c = g.getColor();
		g.setColor(background);
		g.fillRect(0,0,container.getWidth(),container.getHeight());
		g.setColor(c);
	}
}
 
Example 7
@Override
protected boolean onDecide(GameContainer container, StateBasedGame game, int delta) {
	ResourceHolderSlick.soundManager.play("decide");

	if(isTopLevel && (cursor == list.length - 1)) {
		// More...
		NullpoMinoSlick.propGlobal.setProperty("name.mode.toplevel", list[cursor]);
		game.enterState(StateSelectModeFolder.ID);
	} else {
		// Go to rule selector
		if(isTopLevel) {
			NullpoMinoSlick.propGlobal.setProperty("name.mode.toplevel", list[cursor]);
		}
		if(strCurrentFolder.length() > 0) {
			NullpoMinoSlick.propGlobal.setProperty("name.mode." + strCurrentFolder, list[cursor]);
		}
		NullpoMinoSlick.propGlobal.setProperty("name.mode", list[cursor]);
		NullpoMinoSlick.saveConfig();
		game.enterState(StateSelectRuleFromList.ID);
	}

	return false;
}
 
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
@Override
public void enter(GameContainer container, StateBasedGame game) throws SlickException {
	strFileList = getRuleFileList();
	createRuleEntries(strFileList, style);
	strRuleNameList = extractRuleNameListFromRuleEntries();
	strRuleFileList = extractFileNameListFromRuleEntries();
	list = strRuleNameList;
	maxCursor = list.length-1;

	if(style == 0) {
		strCurrentFileName = NullpoMinoSlick.propGlobal.getProperty(player + ".rulefile", "");
		strCurrentRuleName = NullpoMinoSlick.propGlobal.getProperty(player + ".rulename", "");
	} else {
		strCurrentFileName = NullpoMinoSlick.propGlobal.getProperty(player + ".rulefile." + style, "");
		strCurrentRuleName = NullpoMinoSlick.propGlobal.getProperty(player + ".rulename." + style, "");
	}

	cursor = 0;
	for(int i = 0; i < ruleEntries.size(); i++) {
		if(ruleEntries.get(i).filename.equals(strCurrentFileName)) {
			cursor = i;
		}
	}
}
 
Example 10
Source Project: opsu   Source File: GameRanking.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void enter(GameContainer container, StateBasedGame game)
		throws SlickException {
	UI.enter();
	Display.setTitle(game.getTitle());
	if (!data.isGameplay()) {
		if (!MusicController.isTrackDimmed())
			MusicController.toggleTrackDimmed(0.5f);
		replayButton.setY(retryY);
		animationProgress.setTime(animationProgress.getDuration());
	} else {
		SoundController.playSound(SoundEffect.APPLAUSE);
		retryButton.resetHover();
		if (GameMod.AUTO.isActive()) {
			replayButton.setY(retryY);
			animationProgress.setTime(animationProgress.getDuration());
		} else {
			replayButton.setY(replayY);
			animationProgress.setTime(0);
		}
	}
	replayButton.resetHover();
	loadReplay();
}
 
Example 11
/**
 * @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 {
	if (blobs.size() == 0) {
		for (int i=0;i<blobCount;i++) {
			blobs.add(new Blob(container));
		}
	}
	
	for (int i=0;i<blobs.size();i++) {
		((Blob) blobs.get(i)).update(delta);
	}
	
	timer -= delta;
	if (timer < 0) {
		finish = true;
	}
}
 
Example 12
@Override
protected boolean onDecide(GameContainer container, StateBasedGame game, int delta) {
	if (cursor == 0) {
		for(int i = 0; i < GameKeySlick.MAX_BUTTON; i++) {
			GameKeySlick.gamekey[player].keymapNav[i] = GameKeySlick.gamekey[player].keymap[i];
		}
	} else if (cursor == 1) {
		NullpoMinoSlick.stateConfigKeyboard.player = player;
		NullpoMinoSlick.stateConfigKeyboard.isNavSetting = true;
		game.enterState(StateConfigKeyboard.ID);
		return true;
	}

	GameKeySlick.gamekey[player].saveConfig(NullpoMinoSlick.propConfig);
	NullpoMinoSlick.saveConfig();

	ResourceHolderSlick.soundManager.play("decide");
	gameObj.enterState(StateConfigMainMenu.ID);
	return true;
}
 
Example 13
Source Project: opsu   Source File: ButtonMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void click(GameContainer container, StateBasedGame game) {
	SoundController.playSound(SoundEffect.MENUCLICK);
	for (GameMod mod : GameMod.values()) {
		if (mod.isActive())
			mod.toggle(false);
	}
}
 
Example 14
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 15
/**
 * @see org.newdawn.slick.state.BasicGameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, StateBasedGame game, Graphics g) {
	g.setFont(font);
	g.setColor(Color.green);
	g.drawString("This is State 2", 200, 50);
	
	g.rotate(400,300,ang);
	g.drawImage(image,400-(image.getWidth()/2),300-(image.getHeight()/2));
}
 
Example 16
@Override
protected void onChange(GameContainer container, StateBasedGame game, int delta, int change) {
	player += change;
	if(player < 0) player = 1;
	if(player > 1) player = 0;
	ResourceHolderSlick.soundManager.play("change");
}
 
Example 17
@Override
protected boolean onDecide(GameContainer container, StateBasedGame game, int delta) {
	ResourceHolderSlick.soundManager.play("decide");
	GameKeySlick.gamekey[player].loadDefaultKeymap(cursor);
	GameKeySlick.gamekey[player].saveConfig(NullpoMinoSlick.propConfig);
	NullpoMinoSlick.saveConfig();
	game.enterState(StateConfigMainMenu.ID);
	return false;
}
 
Example 18
@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 19
@Override
public void enter(GameContainer container, StateBasedGame game) throws SlickException {
	list = getReplayFileList();
	
	if (list != null)
		maxCursor = list.length-1;
	
	setReplayRuleAndModeList();
}
 
Example 20
@Override
protected void renderImpl(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	// Background
	g.drawImage(ResourceHolderSlick.imgMenu, 0, 0);

	// Menu
	NormalFontSlick.printFontGrid(1, 1, "SELECT " + (player+1) + "P STYLE", NormalFontSlick.COLOR_ORANGE);

	NormalFontSlick.printFontGrid(1, 3 + cursor, "b", NormalFontSlick.COLOR_RED);

	for(int i = 0; i < GameEngine.MAX_GAMESTYLE; i++) {
		NormalFontSlick.printFontGrid(2, 3 + i, GameEngine.GAMESTYLE_NAMES[i], (cursor == i));
	}
}
 
Example 21
Source Project: opsu   Source File: ButtonMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Processes a mouse click action.
 * @param container the game container
 * @param game the game
 * @param cx the x coordinate
 * @param cy the y coordinate
 */
public void click(GameContainer container, StateBasedGame game, int cx, int cy) {
	for (int i = 0; i < buttons.length; i++) {
		if (menuButtons[i].contains(cx, cy)) {
			buttons[i].click(container, game);
			break;
		}
	}
}
 
Example 22
Source Project: opsu   Source File: ButtonMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
		throws SlickException {
	UI.update(delta);
	MusicController.loopTrackIfEnded(false);
	if (menuState != null)
		menuState.update(container, delta, input.getMouseX(), input.getMouseY());
}
 
Example 23
Source Project: opsu   Source File: Game.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
	public void leave(GameContainer container, StateBasedGame game)
			throws SlickException {
//		container.setMouseGrabbed(false);

		// re-hide cursor
		if (GameMod.AUTO.isActive() || isReplay)
			UI.getCursor().hide();

		// replays
		if (isReplay)
			GameMod.loadModState(previousMods);
	}
 
Example 24
@Override
public void init(GameContainer container, StateBasedGame game) throws SlickException {
	if(container instanceof AppGameContainer) {
		appContainer = (AppGameContainer)container;
	} else {
		log.error("This container isn't AppGameContainer");
	}
}
 
Example 25
Source Project: opsu   Source File: Splash.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);
	GameImage.MENU_LOGO.getImage().drawCentered(container.getWidth() / 2, container.getHeight() / 2);
	UI.drawLoadingProgress(g, Options.isLoadVerbose() ? 1f : progressAlpha.getValue());
}
 
Example 26
/**
 * @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 {
       for (int i=0;i<transitions.size();i++) {
       	Transition t = (Transition) transitions.get(i);
       	
       	if (!t.isComplete()) {
       		t.update(game, container, delta);
       	}
       }
}
 
Example 27
/**
 * @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void postRender(StateBasedGame game, GameContainer container, Graphics g) {
	Color old = g.getColor();
	g.setColor(color);
	g.fillRect(0, 0, container.getWidth() * 2, container.getHeight() * 2);
	g.setColor(old);
}
 
Example 28
@Override
protected void onRenderSuccess (GameContainer container, StateBasedGame game, Graphics graphics)  {
	String title = "SELECT " + (player + 1) + "P RULE (" + (cursor + 1) + "/" + (list.length) + ")";
	NormalFontSlick.printFontGrid(1, 1, title, NormalFontSlick.COLOR_ORANGE);

	NormalFontSlick.printFontGrid(1, 25, "CURRENT:" + strCurrentRuleName.toUpperCase(), NormalFontSlick.COLOR_BLUE);
	NormalFontSlick.printFontGrid(9, 26, strCurrentFileName.toUpperCase(), NormalFontSlick.COLOR_BLUE);

	NormalFontSlick.printFontGrid(1, 28, "A:OK B:CANCEL D:TOGGLE-VIEW", NormalFontSlick.COLOR_GREEN);
}
 
Example 29
Source Project: opsu   Source File: GamePauseMenu.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();
	this.gameState = (Game) game.getState(Opsu.STATE_GAME);
}
 
Example 30
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();
}