Java Code Examples for org.newdawn.slick.GameContainer#getWidth()
The following examples show how to use
org.newdawn.slick.GameContainer#getWidth() .
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: Slider.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Initializes the Slider data type with images and dimensions. * @param container the game container * @param circleDiameter the circle diameter * @param beatmap the associated beatmap */ public static void init(GameContainer container, float circleDiameter, Beatmap beatmap) { containerWidth = container.getWidth(); containerHeight = container.getHeight(); diameter = circleDiameter * HitObject.getXMultiplier(); // convert from Osupixels (640x480) int diameterInt = (int) diameter; followRadius = diameter / 2 * 3f; // slider ball if (GameImage.SLIDER_BALL.hasBeatmapSkinImages() || (!GameImage.SLIDER_BALL.hasBeatmapSkinImage() && GameImage.SLIDER_BALL.getImages() != null)) sliderBallImages = GameImage.SLIDER_BALL.getImages(); else sliderBallImages = new Image[]{ GameImage.SLIDER_BALL.getImage() }; for (int i = 0; i < sliderBallImages.length; i++) sliderBallImages[i] = sliderBallImages[i].getScaledCopy(diameterInt * 118 / 128, diameterInt * 118 / 128); GameImage.SLIDER_FOLLOWCIRCLE.setImage(GameImage.SLIDER_FOLLOWCIRCLE.getImage().getScaledCopy(diameterInt * 259 / 128, diameterInt * 259 / 128)); GameImage.REVERSEARROW.setImage(GameImage.REVERSEARROW.getImage().getScaledCopy(diameterInt, diameterInt)); GameImage.SLIDER_TICK.setImage(GameImage.SLIDER_TICK.getImage().getScaledCopy(diameterInt / 4, diameterInt / 4)); sliderMultiplier = beatmap.sliderMultiplier; sliderTickRate = beatmap.sliderTickRate; }
Example 2
Source File: ButtonMenu.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Draws the title and buttons to the graphics context. * @param container the game container * @param game the game * @param g the graphics context */ public void draw(GameContainer container, StateBasedGame game, Graphics g) { // draw title if (actualTitle != null) { float marginX = container.getWidth() * 0.015f, marginY = container.getHeight() * 0.01f; int lineHeight = Fonts.LARGE.getLineHeight(); for (int i = 0, size = actualTitle.size(); i < size; i++) Fonts.LARGE.drawString(marginX, marginY + (i * lineHeight), actualTitle.get(i), Color.white); } // draw buttons for (int i = 0; i < buttons.length; i++) menuButtons[i].draw(buttons[i].getColor()); UI.draw(g); }
Example 3
Source File: ButtonMenu.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * 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 4
Source File: GameRanking.java From opsu with GNU General Public License v3.0 | 6 votes |
@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 5
Source File: HorizontalSplitTransition.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @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 { offset += delta * 1f; if (offset > container.getWidth() / 2) { finish = true; } }
Example 6
Source File: Game.java From opsu with GNU General Public License v3.0 | 5 votes |
@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 7
Source File: ButtonMenu.java From opsu with GNU General Public License v3.0 | 5 votes |
@Override public void draw(GameContainer container, StateBasedGame game, Graphics g) { int width = container.getWidth(); int height = container.getHeight(); // score multiplier (TODO: fade in color changes) float mult = GameMod.getScoreMultiplier(); String multString = String.format("Score Multiplier: %.2fx", mult); Color multColor = (mult == 1f) ? Color.white : (mult > 1f) ? Color.green : Color.red; float multY = Fonts.LARGE.getLineHeight() * 2 + height * 0.06f; Fonts.LARGE.drawString( (width - Fonts.LARGE.getWidth(multString)) / 2f, multY, multString, multColor); // category text for (GameMod.Category category : GameMod.Category.values()) { Fonts.LARGE.drawString(category.getX(), category.getY() - Fonts.LARGE.getLineHeight() / 2f, category.getName(), category.getColor()); } // buttons for (GameMod mod : GameMod.values()) mod.draw(); super.draw(container, game, g); }
Example 8
Source File: ButtonMenu.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Initializes the menu state. * @param container the game container * @param game the game * @param button the center button image * @param buttonL the left button image * @param buttonR the right button image */ public void init(GameContainer container, StateBasedGame game, Image button, Image buttonL, Image buttonR) { float center = container.getWidth() / 2f; float baseY = getBaseY(container, game); float offsetY = button.getHeight() * 1.25f; menuButtons = new MenuButton[buttons.length]; for (int i = 0; i < buttons.length; i++) { MenuButton b = new MenuButton(button, buttonL, buttonR, center, baseY + (i * offsetY)); b.setText(String.format("%d. %s", i + 1, buttons[i].getText()), Fonts.XLARGE, Color.white); b.setHoverFade(); menuButtons[i] = b; } }
Example 9
Source File: ButtonMenu.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Updates the menu state. * @param container the game container * @param delta the delta interval * @param mouseX the mouse x coordinate * @param mouseY the mouse y coordinate */ public void update(GameContainer container, int delta, int mouseX, int mouseY) { float center = container.getWidth() / 2f; boolean centerOffsetUpdated = centerOffset.update(delta); float centerOffsetX = centerOffset.getValue(); for (int i = 0; i < buttons.length; i++) { menuButtons[i].hoverUpdate(delta, mouseX, mouseY); // move button to center if (centerOffsetUpdated) menuButtons[i].setX((i % 2 == 0) ? center + centerOffsetX : center - centerOffsetX); } }
Example 10
Source File: GameRanking.java From opsu with GNU General Public License v3.0 | 5 votes |
@Override public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException { int width = container.getWidth(); int height = container.getHeight(); int mouseX = input.getMouseX(), mouseY = input.getMouseY(); Beatmap beatmap = MusicController.getBeatmap(); // background float parallaxX = 0, parallaxY = 0; if (Options.isParallaxEnabled()) { int offset = (int) (height * (GameImage.PARALLAX_SCALE - 1f)); parallaxX = -offset / 2f * (mouseX - width / 2) / (width / 2); parallaxY = -offset / 2f * (mouseY - height / 2) / (height / 2); } if (!beatmap.drawBackground(width, height, parallaxX, parallaxY, 0.5f, true)) { Image bg = GameImage.MENU_BG.getImage(); if (Options.isParallaxEnabled()) { bg = bg.getScaledCopy(GameImage.PARALLAX_SCALE); bg.setAlpha(0.5f); bg.drawCentered(width / 2 + parallaxX, height / 2 + parallaxY); } else { bg.setAlpha(0.5f); bg.drawCentered(width / 2, height / 2); bg.setAlpha(1f); } } // ranking screen elements data.drawRankingElements(g, beatmap, animationProgress.getTime()); // buttons replayButton.draw(); if (data.isGameplay() && !GameMod.AUTO.isActive()) retryButton.draw(); UI.getBackButton().draw(g); UI.draw(g); }
Example 11
Source File: Scroller.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { // load the sprites and tiles, note that underneath the texture // will be shared between the sprite sheet and tilemap SpriteSheet sheet = new SpriteSheet("testdata/scroller/sprites.png",32,32); // load the tilemap created the TileD tool map = new TiledMap("testdata/scroller/map.tmx"); // build a collision map based on tile properties in the TileD map blocked = new boolean[map.getWidth()][map.getHeight()]; for (int x=0;x<map.getWidth();x++) { for (int y=0;y<map.getHeight();y++) { int tileID = map.getTileId(x, y, 0); String value = map.getTileProperty(tileID, "blocked", "false"); if ("true".equals(value)) { blocked[x][y] = true; } } } // caculate some layout values for rendering the tilemap. How many tiles // do we need to render to fill the screen in each dimension and how far is // it from the centre of the screen widthInTiles = container.getWidth() / TILE_SIZE; heightInTiles = container.getHeight() / TILE_SIZE; topOffsetInTiles = heightInTiles / 2; leftOffsetInTiles = widthInTiles / 2; // create the player sprite based on a set of sprites from the sheet loaded // above (tank tracks moving) player = new Animation(); for (int frame=0;frame<7;frame++) { player.addFrame(sheet.getSprite(frame,1), 150); } player.setAutoUpdate(false); // update the vector of movement based on the initial angle updateMovementVector(); Log.info("Window Dimensions in Tiles: "+widthInTiles+"x"+heightInTiles); }
Example 12
Source File: BlobbyTransition.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Create a new blob * * @param container The container for dimensions */ public Blob(GameContainer container) { x = (float) (Math.random() * container.getWidth()); y = (float) (Math.random() * container.getWidth()); growSpeed = (float) (1f + (Math.random() * 1f)); }
Example 13
Source File: SelectTransition.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @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 (!init) { init = true; xp2 = (container.getWidth()/2)+50; yp2 = (container.getHeight()/4); } if (!moveBackDone) { if (scale1 > 0.4f) { scale1 -= delta * 0.002f; if (scale1 <= 0.4f) { scale1 = 0.4f; } xp1 += delta * 0.3f; if (xp1 > 50) { xp1 = 50; } yp1 += delta * 0.5f; if (yp1 > (container.getHeight()/4)) { yp1 = (container.getHeight()/4); } } else { moveBackDone = true; } } else { pause -= delta; if (pause > 0) { return; } if (scale2 < 1) { scale2 += delta * 0.002f; if (scale2 >= 1) { scale2 = 1f; } xp2 -= delta * 1.5f; if (xp2 < 0) { xp2 = 0; } yp2 -= delta * 0.5f; if (yp2 < 0) { yp2 = 0; } } else { finish = true; } } }
Example 14
Source File: Utils.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * 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 15
Source File: UserSelectOverlay.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * 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 16
Source File: OptionsOverlay.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * 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 17
Source File: Spinner.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * Initializes the Spinner data type with images and dimensions. * @param container the game container * @param difficulty the map's overall difficulty value */ public static void init(GameContainer container, float difficulty) { width = container.getWidth(); height = container.getHeight(); overallDifficulty = difficulty; }