@Override public void update(GameContainer gc, StateBasedGame sbg, int delta) { super.update(gc, sbg, delta); int padding = 80; if (getOwner() instanceof Camera) { Camera camera = (Camera) getOwner(); Input input = gc.getInput(); float speed = 1.5f * delta; if (input.getMouseX() < padding || input.isKeyDown(Input.KEY_A)) { camera.setGlobalX(camera.getGlobalX() - speed); } if (input.getMouseY() < padding || input.isKeyDown(Input.KEY_W)) { camera.setGlobalY(camera.getGlobalY() - speed); } if (input.isKeyDown(Input.KEY_S) || input.getMouseY() > gc.getHeight() - padding && input.getMouseY() < gc.getHeight() - 10) { camera.setGlobalY(camera.getGlobalY() + speed); } if (input.isKeyDown(Input.KEY_D) || input.getMouseX() > gc.getWidth() - padding && input.getMouseX() < gc.getWidth() - 10) { camera.setGlobalX(camera.getGlobalX() + speed); } } }
@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()); }
@Override public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException { Input input = container.getInput(); int mouseX = input.getMouseX(); int mouseY = input.getMouseY(); boolean startGame = false; boolean exitGame = false; if ((mouseX >= menuX && mouseX <= menuX + startGameOption.getWidth()) && (mouseY >= menuY && mouseY <= menuY + startGameOption.getHeight())) { startGame = true; } else if ((mouseX >= menuX && mouseX <= menuX + exitOption.getWidth()) && (mouseY >= menuY + 100 && mouseY <= menuY + 100 + exitOption.getHeight())) { exitGame = true; } if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) { if (startGame) { game.enterState(RunGame.GAMEPLAYSTATE); } else if (exitGame) { container.exit(); } } }
/** * checks and sets the state of this button. * * @param input the current input * @param butPosX the X position of this button * @param butPosY the Y position of this button * @param butWidth the width of this button * @param butHeight the height of this button */ protected void buttonStateCheck( Input input, int butPosX, int butPosY, int butWidth, int butHeight) { if (contains( input.getMouseX(), input.getMouseY(), butPosX, butPosY, butPosX + butWidth, butPosY + butHeight)) { if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && (getState() == STATE_HOVER || getState() == STATE_PRESSED)) { setState(STATE_PRESSED); setClicked(true); } else { if (!input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) { setState(STATE_HOVER); } else { setState(STATE_IDLE); } } } else if (!(input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && getState() == STATE_PRESSED)) { setState(STATE_IDLE); setClicked(false); } }
@Override public void enter(GameContainer container, StateBasedGame game) throws SlickException { UI.enter(); if (!enterNotification) { if (Updater.get().getStatus() == Updater.Status.UPDATE_AVAILABLE) { UI.sendBarNotification("An opsu! update is available."); enterNotification = true; } else if (Updater.get().justUpdated()) { UI.sendBarNotification("opsu! is now up to date!"); enterNotification = true; } } // reset button hover states if mouse is not currently hovering over the button int mouseX = input.getMouseX(), mouseY = input.getMouseY(); if (!logo.contains(mouseX, mouseY, 0.25f)) logo.resetHover(); if (!playButton.contains(mouseX, mouseY, 0.25f)) playButton.resetHover(); if (!optionsButton.contains(mouseX, mouseY, 0.25f)) optionsButton.resetHover(); if (!exitButton.contains(mouseX, mouseY, 0.25f)) exitButton.resetHover(); if (!musicPlay.contains(mouseX, mouseY)) musicPlay.resetHover(); if (!musicPause.contains(mouseX, mouseY)) musicPause.resetHover(); if (!musicNext.contains(mouseX, mouseY)) musicNext.resetHover(); if (!musicPrevious.contains(mouseX, mouseY)) musicPrevious.resetHover(); if (repoButton != null && !repoButton.contains(mouseX, mouseY)) repoButton.resetHover(); if (!updateButton.contains(mouseX, mouseY)) updateButton.resetHover(); if (!downloadsButton.contains(mouseX, mouseY)) downloadsButton.resetHover(); }
@Override public void update(GameContainer gc, int delta) throws SlickException { world.update(gc, null, delta); Camera camera = world.getCamera(); Input input = gc.getInput(); cursorTorch.setGlobalCenterX(input.getMouseX() + camera.getGlobalX()); cursorTorch.setGlobalCenterY(input.getMouseY() + camera.getGlobalY()); }
public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException { resetSelectionBooleans(); int x = input.getMouseX(), y = input.getMouseY(); backgroundX = -419 * x / 528 - 1365; backgroundY = -533 * y / 300 - 1365; if (x > 455 && x < 600 && y > 260 && y < 300) hovering[0] = true; else if (x > 380 && x < 675 && y > 320 && y < 360) hovering[1] = true; else if (x > 455 && x < 600 && y > 380 && y < 420) hovering[2] = true; }
@Override public void update(GameContainer gc, StateBasedGame sbg, int delta) { inventoryBoxes.clear(); int numColumns = (int) (dims.getWidth() / partInterval); int startX = (int) (dims.getX() + (dims.getWidth() % partInterval) / 2); int startY = (int) dims.getY() + offsetY; int x = startX; int y = startY; for (int i = 0; i < parts.size(); i++) { ShipPart tempPart = parts.get(i); Rectangle rect = new Rectangle( x + (partInterval - partSize) / 2, y + (partInterval - partSize) / 2, partSize, partSize); inventoryBoxes.add(new ShipPartBox(tempPart, rect)); if (i % numColumns == numColumns - 1) { x = startX; y += partInterval; } else { x += partInterval; } } Input input = gc.getInput(); hoveredPart = null; for (int i = 0; i < inventoryBoxes.size(); i++) { if (inventoryBoxes.get(i).getRectangle().contains(input.getMouseX(), input.getMouseY())) { if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) { if (inventoryBoxes.get(i).getPart().equals(selectedPart)) { // Deselects if already selected selectedPart = null; } else { // Selects if not already selected selectedPart = inventoryBoxes.get(i).getPart(); } } else { hoveredPart = inventoryBoxes.get(i).getPart(); } break; } } }
@Override public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException { // TODO Auto-generated method stub Input input = container.getInput(); int mouseX = input.getMouseX(); int mouseY = input.getMouseY(); boolean inMenu = false; if (mouseX > 400 && mouseX < 626 && mouseY > 200 && mouseY < 276) inMenu = true; if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && inMenu) { Constant.LEVEL = 0; game.enterState(3); } }
public void update(GameContainer gameContainer, StateBasedGame stateBasedGame, int i) throws SlickException { Input input = gameContainer.getInput(); calendar.tick(); if (counter == 3) { gamePanel.update( input, input.getMouseX(), input.getMouseY(), input.isMousePressed(Input.MOUSE_LEFT_BUTTON)); counter = 0; } counter++; }
/** * Create a new mouse over area * * @param container The container displaying the mouse over area * @param image The normalImage to display * @param shape The shape defining the area of the mouse sensitive zone */ public MouseOverArea(GUIContext container, Image image, Shape shape) { super(container); area = shape; normalImage = image; currentImage = image; mouseOverImage = image; mouseDownImage = image; currentColor = normalColor; state = NORMAL; Input input = container.getInput(); over = area.contains(input.getMouseX(), input.getMouseY()); mouseDown = input.isMouseButtonDown(0); updateImage(); }
@Override public void poll(Input input, float secounds) { if (selected == this || selected == null) { Vector mousePos = this.getEditor().translateMousePos(input.getMouseX(), input.getMouseY()); if (this.wasInCircle) { this.changePosition(mousePos); } if ((this.shape.isPointIn(mousePos) || this.wasInCircle) && input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) { this.wasInCircle = true; selected = this; } else { this.wasInCircle = false; selected = null; } } }
public void check(GameContainer gc, int delta) { int x = this.x * width; int y = this.y * height; Input input = gc.getInput(); int mx = input.getMouseX(); int my = input.getMouseY(); // On Hover if ((mx > ox + x && mx < ox + x + width) && (my > oy + y && my < oy + y + height)) { if (!in) { onHover(); in = true; } } else if (in == true) { in = false; onLeave(); } // On Click if ((mx > ox + x && mx < ox + x + width) && (my > oy + y && my < oy + y + height)) { if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && !clicked) { onClick(Input.MOUSE_LEFT_BUTTON, gc); currentButton = Input.MOUSE_LEFT_BUTTON; clicked = true; } else if (input.isMouseButtonDown(Input.MOUSE_MIDDLE_BUTTON) && !clicked) { onClick(Input.MOUSE_MIDDLE_BUTTON, gc); currentButton = Input.MOUSE_MIDDLE_BUTTON; clicked = true; } else if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON) && !clicked) { onClick(Input.MOUSE_RIGHT_BUTTON, gc); currentButton = Input.MOUSE_RIGHT_BUTTON; clicked = true; } else if (clicked == true && !input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && !input.isMouseButtonDown(Input.MOUSE_MIDDLE_BUTTON) && !input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) { onRelease(currentButton, gc); clicked = false; } } update(gc, delta); }
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException { Input input = gc.getInput(); int mouseX = input.getMouseX(); int mouseY = input.getMouseY(); System.out.println("PAUSED"); if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) { sbg.enterState(SimpleGame.GAMEPLAYSTATE); // GameplayState.currentState = STATES.START_GAME_STATE; // GameplayState.music.loop(1f,.3f); // GameplayState.needReset = true; // GameplayState.playing = false; // GameplayState.health = 100; } if (input.isKeyPressed(Input.KEY_ESCAPE)) { // gc.exit(); } }
@Override public void update(GameContainer gc, StateBasedGame sbg, int arg2) throws SlickException { Input input = gc.getInput(); int mouseX = input.getMouseX(); int mouseY = input.getMouseY(); if (input.isMousePressed((Input.MOUSE_LEFT_BUTTON))) { if (startGameButton.inSpan(mouseX, mouseY)) { changeState(sbg, levelSelectionState); } else if (optionsButton.inSpan(mouseX, mouseY)) { changeState(sbg, optionsState); } else if (loreButton.inSpan(mouseX, mouseY)) { changeState(sbg, loresState); } else if (instructionsButton.inSpan(mouseX, mouseY)) { changeState(sbg, instructionState); } } }
@Override public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException { Input in = gc.getInput(); float mouseX = in.getMouseX(); float mouseY = in.getMouseY(); if (mouseX != lastMouseX || mouseY != lastMouseY) { for (int i = 0; i < buttons.size(); i++) { buttons.get(i).checkMouseHover(new Vector2f(mouseX, mouseY)); } lastMouseX = mouseX; lastMouseY = mouseY; } if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) { for (int i = 0; i < buttons.size(); i++) { boolean temp = buttons.get(i).checkMouseClick(new Vector2f(mouseX, mouseY), 0); if (temp && tf.getText().length() > 0) { int e = buttons.get(i).getButtonID(); Vector2f point = rm.getMap("World_1.tmx").getStartLocation(); int x = (int) point.x; int y = (int) point.y; switch (e) { case 0: p = new Player( Settings.PLAYER_X, Settings.PLAYER_Y, rm.getSprite("knight.png"), tf.getText(), CType.KNIGHT, x, y, rm.getLog()); break; case 1: p = new Player( Settings.PLAYER_X, Settings.PLAYER_Y, rm.getSprite("mage.png"), tf.getText(), CType.MAGE, x, y, rm.getLog()); break; case 2: p = new Player( Settings.PLAYER_X, Settings.PLAYER_Y, rm.getSprite("thief.png"), tf.getText(), CType.THIEF, x, y, rm.getLog()); break; } am = new AtlasMain(p, rm, 2); sbg.addState(am); am.init(gc, sbg); sbg.enterState(2); } } } if (in.isKeyPressed(Input.KEY_ESCAPE)) { System.exit(0); } }
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException { boolean selTitle = false; boolean selStart = false; boolean selOptions = false; boolean selQuit = false; Input input = gc.getInput(); int mouseX = input.getMouseX(); int mouseY = input.getMouseY(); /* Title */ // if ((mouseX >= xTitle && mouseX <= xTitle + imgTitle.getWidth()) // && (mouseY >= yTitle && mouseY <= yTitle + imgTitle.getHeight())) { // selTitle = true; // } // if (selTitle) { // if (sTitle < 1.0f) // sTitle += sTitle * delta; // // if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) { // } // } else { // if (sTitle > 0.8f) // sTitle -= sTitle * delta; // } /* Start */ if ((mouseX >= xStart && mouseX <= xStart + imgStart.getWidth()) && (mouseY >= yStart && mouseY <= yStart + imgStart.getHeight())) { selStart = true; } if (selStart) { if (sStart < 1.25f) sStart += scaleStep * delta; if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) { // sbg.enterState(Pixahl.GAMEPLAYSTATE); } } else { if (sStart > 1.0f) sStart -= scaleStep * delta; } /* Options */ if ((mouseX >= xOptions && mouseX <= xOptions + imgOptions.getWidth()) && (mouseY >= yOptions && mouseY <= yOptions + imgOptions.getHeight())) { selOptions = true; } if (selOptions) { if (sOptions < 1.25f) sOptions += scaleStep * delta; if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {} } else { if (sOptions > 1.0f) sOptions -= scaleStep * delta; } /* Quit */ if ((mouseX >= xQuit && mouseX <= xQuit + imgQuit.getWidth()) && (mouseY >= yQuit && mouseY <= yQuit + imgQuit.getHeight())) { selQuit = true; } if (selQuit) { if (sQuit < 1.25f) sQuit += scaleStep * delta; if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) { gc.exit(); } } else { if (sQuit > 1.0f) sQuit -= scaleStep * delta; } }
@Override public void update(GameContainer gameContainer, StateBasedGame stateBasedGame, int delta) throws SlickException { Input in = gameContainer.getInput(); if (in.isKeyPressed(Input.KEY_C)) { clear(); } gameContainer.setMaximumLogicUpdateInterval(updateInterval); if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) { float x1 = in.getMouseX() / ratio; float y1 = in.getMouseY() / ratio; if (start == null) { start = new Cell((int) x1, (int) y1, ratio, false); start.start = true; cells[start.gridPosX][start.gridPosY].start = true; cellStack.add(cells[start.gridPosX][start.gridPosY]); } else if (goal == null) { goal = new Cell((int) x1, (int) y1, ratio, false); cells[goal.gridPosX][goal.gridPosY].goal = true; } else { changeCellAtPosition((int) x1, (int) y1); } if (start != null && goal != null) { this.wall = cells[(int) x1][(int) y1].wall; } } if (in.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) { if (start != null && goal != null) { mousePressing = true; float x1 = in.getMouseX() / ratio; float y1 = in.getMouseY() / ratio; cells[(int) x1][(int) y1].wall = this.wall; } } else { mousePressing = false; } if (in.isKeyPressed(Input.KEY_ENTER)) { if (mazeSolved && displayingMaze) { clear(); createGraph(); maze = true; } else if (!maze) { this.search = true; } } if (in.isKeyPressed(Input.KEY_M) && !maze) { createGraph(); maze = true; this.logger.initWriter(); } if (in.isKeyPressed(Input.KEY_S)) { clear(); for (int i = 0; i < cells.length; i++) { for (int j = 0; j < cells.length; j++) { Random random = new Random(); if (random.nextInt(3) == 0) { cells[i][j].wall = true; } } } setDefaultStartAndEnd(true); } if (in.isKeyPressed(Input.KEY_ADD)) { if (updateInterval > 1) { updateInterval -= 1; } } if (in.isKeyPressed(Input.KEY_SUBTRACT)) { if (updateInterval < 20) { updateInterval += 1; } } if (in.isKeyPressed(Input.KEY_P)) { if (!gameContainer.isPaused()) { gameContainer.pause(); } else { gameContainer.resume(); } } if (in.isKeyPressed(Input.KEY_D)) { this.diagonal = !this.diagonal; } if (in.isKeyPressed(Input.KEY_ESCAPE)) { stateBasedGame.enterState(1); } if (in.isKeyPressed(Input.KEY_A)) { AnalyzeLog.analyzeBacktracks(AnalyzeLog.FIRST); } if (in.isKeyPressed(Input.KEY_I)) { this.createImage(); } if (this.search) { if (start == null || goal == null) { this.search = false; } else { if (ButtonStates.DFSState) { if (solvingVisited.size() < 1) { solvingVisited.add(cells[start.gridPosX][start.gridPosY]); cells[start.gridPosX][start.gridPosY].solvingVisited = true; currentDFSCell = cells[start.gridPosX][start.gridPosY]; } else { for (int x = 0; x < CELLS; x++) { for (int y = 0; y < CELLS; y++) { cells[x][y].dfsCheckNeighbors(); } } if (currentDFSCell.goal) { this.search = false; this.drawWay = true; this.end = currentDFSCell; getPath(false, null); if (displayingMaze) { mazeSolved = true; } foundSolution = true; } else { if (solvingVisited.size() != (CELLS * CELLS)) { ArrayList<Cell> currentNeighbors = new ArrayList<>(); if (currentDFSCell.dfsNorth != null && !currentDFSCell.dfsNorth.solvingVisited && !currentDFSCell.dfsNorth.wall) { currentNeighbors.add(currentDFSCell.dfsNorth); } else if (currentDFSCell.dfsEast != null && !currentDFSCell.dfsEast.solvingVisited && !currentDFSCell.dfsEast.wall) { currentNeighbors.add(currentDFSCell.dfsEast); } else if (currentDFSCell.dfsSouth != null && !currentDFSCell.dfsSouth.solvingVisited && !currentDFSCell.dfsSouth.wall) { currentNeighbors.add(currentDFSCell.dfsSouth); } else if (currentDFSCell.dfsWest != null && !currentDFSCell.dfsWest.solvingVisited && !currentDFSCell.dfsWest.wall) { currentNeighbors.add(currentDFSCell.dfsWest); } else {; } if (currentNeighbors.size() > 0) { Cell neighbor = currentNeighbors.get(0); neighbor.solvingPrevious = currentDFSCell; neighbor.solvingVisited = true; currentDFSCell = neighbor; } else { dfsBacktracked.add(currentDFSCell); dfsBacktracked.add(currentDFSCell.solvingPrevious); currentDFSCell = currentDFSCell.solvingPrevious; } } } } } else if (ButtonStates.AStarState) { } else if (ButtonStates.BFSState) { if (solvingVisited.size() < 1) { solvingVisited.add(cells[start.gridPosX][start.gridPosY]); cells[start.gridPosX][start.gridPosY].solvingVisited = true; cellStack.add(cells[start.gridPosX][start.gridPosY]); } else { if (!cellStack.isEmpty()) { Cell current = (Cell) cellStack.remove(); Cell child; if (current.goal) { this.end = current; this.drawWay = true; this.search = false; getPath(false, null); if (displayingMaze) { mazeSolved = true; } foundSolution = true; } else { while ((child = getUnvisitedChildCell(current)) != null) { child.solvingVisited = true; child.solvingPrevious = current; solvingVisited.add(child); cellStack.add(child); current.solvingCheckNeighbors(diagonal); getPath(true, child); } } } } } else { try { throw new NoSolvingAlgorithmSelectedException(); } catch (Exception e) { e.printStackTrace(); } } } } if (this.maze) { if (this.logger.used) { this.logger.createNewLogFile(); this.logger.initWriter(); this.logger.used = false; } if (cells.length != 0) { logger.writeInLog("Checking neighbors"); for (int i = 0; i < CELLS; i++) { for (int j = 0; j < CELLS; j++) { cells[i][j].genCheckNeighbors(); } } if (genVisited.size() < 1) { genVisited.add(cells[1][1]); currentGenCell = cells[1][1]; currentGenCell.genVisited = true; logger.writeInLog("Adding Cell X1 and Y1 to visited Cells"); } if (genVisited.size() != totalCells) { ArrayList<Cell> currentNeighbors = new ArrayList<>(); if (currentGenCell.north != null && !currentGenCell.north.genVisited && currentGenCell.north.allWallsIntact) { currentNeighbors.add(currentGenCell.north); logger.writeInLog( "Adding north cell to neighbors at: " + currentGenCell.north.gridPosX + "; " + currentGenCell.north.gridPosY); } if (currentGenCell.east != null && !currentGenCell.east.genVisited && currentGenCell.east.allWallsIntact) { currentNeighbors.add(currentGenCell.east); logger.writeInLog( "Adding east cell to neighbors at: " + currentGenCell.east.gridPosX + "; " + currentGenCell.east.gridPosY); } if (currentGenCell.south != null && !currentGenCell.south.genVisited && currentGenCell.south.allWallsIntact) { currentNeighbors.add(currentGenCell.south); logger.writeInLog( "Adding south cell to neighbors at: " + currentGenCell.south.gridPosX + "; " + currentGenCell.south.gridPosY); } if (currentGenCell.west != null && !currentGenCell.west.genVisited && currentGenCell.west.allWallsIntact) { currentNeighbors.add(currentGenCell.west); logger.writeInLog( "Adding west cell to neighbors at: " + currentGenCell.west.gridPosX + "; " + currentGenCell.west.gridPosY); } if (currentNeighbors.size() > 0) { Random random = new Random(); int randomValue = random.nextInt(currentNeighbors.size()); logger.writeInLog("Generated random number: " + randomValue); Cell neighbor = currentNeighbors.get(randomValue); logger.writeInLog("Picked neighbor: " + neighbor.gridPosX + "; " + neighbor.gridPosY); neighbor.genVisited = true; int wallX = 0; int wallY = 0; // break wall if (neighbor.gridPosX > currentGenCell.gridPosX) { wallX = currentGenCell.gridPosX + 1; } else if (neighbor.gridPosX < currentGenCell.gridPosX) { wallX = currentGenCell.gridPosX - 1; } else { wallX = currentGenCell.gridPosX; } if (neighbor.gridPosY > currentGenCell.gridPosY) { wallY = currentGenCell.gridPosY + 1; } else if (neighbor.gridPosY < currentGenCell.gridPosY) { wallY = currentGenCell.gridPosY - 1; } else { wallY = currentGenCell.gridPosY; } cells[wallX][wallY].wall = false; cells[wallX][wallY].genVisited = true; logger.writeInLog("Breaking wall at: " + wallX + "; " + wallY); genVisited.add(cells[wallX][wallY]); neighbor.genBacktrack = currentGenCell; logger.writeInLog( "Set current cell to backtrack cell at: " + currentGenCell.gridPosX + "; " + currentGenCell.gridPosY); currentGenCell = neighbor; } else { currentGenCell = currentGenCell.genBacktrack; logger.writeInLog( "Backtracking at: " + currentGenCell.genBacktrack.gridPosX + "; " + currentGenCell.genBacktrack.gridPosY); } } else { currentGenCell = null; this.maze = false; setDefaultStartAndEnd(true); displayingMaze = true; if ((this.search = !this.search) == true) { if (this.startSearch == false) { this.search = false; createImage(); } } logger.writeInLog("Done Maze, closing logger."); logger.closeWriter(); if (this.automaticallyGenerateMazes && (generatedMazes < mazesToGenerate)) { generatedMazes += 1; clear(); createGraph(); this.maze = true; } else if (this.logger.stepList.size() != 0) { this.logger.printStepList(); } else {; } } } } char[][] copyOfLevel = new char[CELLS][CELLS]; for (int x = 0; x < cells.length; x++) { for (int y = 0; y < cells.length; y++) { if (cells[x][y].wall) { copyOfLevel[x][y] = 'W'; } else if (!cells[x][y].wall) { copyOfLevel[x][y] = 'D'; } else if (cells[x][y].start) { copyOfLevel[x][y] = 'S'; } else if (cells[x][y].goal) { copyOfLevel[x][y] = 'G'; } else { copyOfLevel[x][y] = 'D'; } } } Level.update(copyOfLevel); }
@Override protected float readX() { return input.getMouseX(); }
@Override public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException { UI.update(delta); if (MusicController.trackEnded()) nextTrack(); // end of track: go to next track int mouseX = input.getMouseX(), mouseY = input.getMouseY(); logo.hoverUpdate(delta, mouseX, mouseY, 0.25f); playButton.hoverUpdate(delta, mouseX, mouseY, 0.25f); optionsButton.hoverUpdate(delta, mouseX, mouseY, 0.25f); exitButton.hoverUpdate(delta, mouseX, mouseY, 0.25f); if (repoButton != null) repoButton.hoverUpdate(delta, mouseX, mouseY); updateButton.hoverUpdate(delta, mouseX, mouseY); downloadsButton.hoverUpdate(delta, mouseX, mouseY); // ensure only one button is in hover state at once boolean noHoverUpdate = musicPositionBarContains(mouseX, mouseY); boolean contains = musicPlay.contains(mouseX, mouseY); musicPlay.hoverUpdate(delta, !noHoverUpdate && contains); musicPause.hoverUpdate(delta, !noHoverUpdate && contains); noHoverUpdate |= contains; musicNext.hoverUpdate(delta, !noHoverUpdate && musicNext.contains(mouseX, mouseY)); musicPrevious.hoverUpdate(delta, !noHoverUpdate && musicPrevious.contains(mouseX, mouseY)); // window focus change: increase/decrease theme song volume if (MusicController.isThemePlaying() && MusicController.isTrackDimmed() == container.hasFocus()) MusicController.toggleTrackDimmed(0.33f); // fade in background if (bgAlpha < BG_MAX_ALPHA) { bgAlpha += delta / 1000f; if (bgAlpha > BG_MAX_ALPHA) bgAlpha = BG_MAX_ALPHA; } // buttons if (logoClicked) { if (logoTimer == 0) { // shifting to left if (logo.getX() > container.getWidth() / 3.3f) logo.setX(logo.getX() - delta); else logoTimer = 1; } else if (logoTimer >= MOVE_DELAY) // timer over: shift back to center logoClicked = false; else { // increment timer logoTimer += delta; if (logoTimer <= 500) { // fade in buttons playButton.getImage().setAlpha(logoTimer / 400f); optionsButton.getImage().setAlpha(logoTimer / 400f); exitButton.getImage().setAlpha(logoTimer / 400f); } } } else { // fade out buttons if (logoTimer > 0) { float alpha = playButton.getImage().getAlpha(); if (alpha > 0f) { playButton.getImage().setAlpha(alpha - (delta / 200f)); optionsButton.getImage().setAlpha(alpha - (delta / 200f)); exitButton.getImage().setAlpha(alpha - (delta / 200f)); } else logoTimer = 0; } // move back to original location if (logo.getX() < container.getWidth() / 2) { logo.setX(logo.getX() + (delta / 3f)); if (logo.getX() > container.getWidth() / 2) logo.setX(container.getWidth() / 2); } } // tooltips if (musicPositionBarContains(mouseX, mouseY)) UI.updateTooltip(delta, "Click to seek to a specific point in the song.", false); else if (musicPlay.contains(mouseX, mouseY)) UI.updateTooltip(delta, (MusicController.isPlaying()) ? "Pause" : "Play", false); else if (musicNext.contains(mouseX, mouseY)) UI.updateTooltip(delta, "Next track", false); else if (musicPrevious.contains(mouseX, mouseY)) UI.updateTooltip(delta, "Previous track", false); else if (Updater.get().showButton() && updateButton.contains(mouseX, mouseY)) UI.updateTooltip(delta, Updater.get().getStatus().getDescription(), true); }
boolean isMouseOver(Input input) { return rectangle.contains(input.getMouseX(), input.getMouseY()); }
private boolean mouseHasMoved(GameContainer gc) { Input input = gc.getInput(); int currentX = input.getMouseX(); int currentY = input.getMouseY(); return currentX != lastKnownMouseX || currentY != lastKnownMouseY; }
@Override public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException { int width = container.getWidth(); int height = container.getHeight(); // draw background Beatmap beatmap = MusicController.getBeatmap(); if (Options.isDynamicBackgroundEnabled() && beatmap != null && beatmap.drawBG(width, height, bgAlpha, true)) ; else { Image bg = GameImage.MENU_BG.getImage(); bg.setAlpha(bgAlpha); bg.draw(); } // top/bottom horizontal bars float oldAlpha = Utils.COLOR_BLACK_ALPHA.a; Utils.COLOR_BLACK_ALPHA.a = 0.2f; g.setColor(Utils.COLOR_BLACK_ALPHA); g.fillRect(0, 0, width, height / 9f); g.fillRect(0, height * 8 / 9f, width, height / 9f); Utils.COLOR_BLACK_ALPHA.a = oldAlpha; // draw downloads button downloadsButton.draw(); // draw buttons if (logoTimer > 0) { playButton.draw(); exitButton.draw(); optionsButton.draw(); } logo.draw(); // draw music buttons if (MusicController.isPlaying()) musicPause.draw(); else musicPlay.draw(); musicNext.draw(); musicPrevious.draw(); // draw music position bar int mouseX = input.getMouseX(), mouseY = input.getMouseY(); g.setColor((musicPositionBarContains(mouseX, mouseY)) ? BG_HOVER : BG_NORMAL); g.fillRoundRect(musicBarX, musicBarY, musicBarWidth, musicBarHeight, 4); g.setColor(Color.white); if (!MusicController.isTrackLoading() && beatmap != null) { float musicBarPosition = Math.min((float) MusicController.getPosition() / MusicController.getDuration(), 1f); g.fillRoundRect(musicBarX, musicBarY, musicBarWidth * musicBarPosition, musicBarHeight, 4); } // draw repository button if (repoButton != null) repoButton.draw(); // draw update button if (Updater.get().showButton()) { Color updateColor = null; switch (Updater.get().getStatus()) { case UPDATE_AVAILABLE: updateColor = Color.red; break; case UPDATE_DOWNLOADED: updateColor = Color.green; break; case UPDATE_DOWNLOADING: updateColor = Color.yellow; break; default: updateColor = Color.white; break; } updateButton.draw(updateColor); } // draw text float marginX = width * 0.015f, topMarginY = height * 0.01f, bottomMarginY = height * 0.015f; g.setFont(Utils.FONT_MEDIUM); float lineHeight = Utils.FONT_MEDIUM.getLineHeight() * 0.925f; g.drawString( String.format( "Loaded %d songs and %d beatmaps.", BeatmapSetList.get().getMapSetCount(), BeatmapSetList.get().getMapCount()), marginX, topMarginY); if (MusicController.isTrackLoading()) g.drawString("Track loading...", marginX, topMarginY + lineHeight); else if (MusicController.trackExists()) { if (Options.useUnicodeMetadata()) // load glyphs Utils.loadGlyphs(Utils.FONT_MEDIUM, beatmap.titleUnicode, beatmap.artistUnicode); g.drawString( (MusicController.isPlaying()) ? "Now Playing:" : "Paused:", marginX, topMarginY + lineHeight); g.drawString( String.format("%s: %s", beatmap.getArtist(), beatmap.getTitle()), marginX + 25, topMarginY + (lineHeight * 2)); } g.drawString( String.format( "opsu! has been running for %s.", Utils.getTimeString((int) (System.currentTimeMillis() - programStartTime) / 1000)), marginX, height - bottomMarginY - (lineHeight * 2)); g.drawString( String.format("It is currently %s.", new SimpleDateFormat("h:mm a").format(new Date())), marginX, height - bottomMarginY - lineHeight); UI.draw(g); }