public MapDisplay( String level, String picpath, String shadowpath, int col, int row, GamePanel p) { tiles = new Vector<Tile>(); parent = (Game) p; loadLevelData(level); control = ImageControl.getInstance(); control.setSourceImage(picpath, col, row); control.setShadowImage(shadowpath, col, row); display = new Rectangle2D.Double(0, 0, parent.getWidth(), parent.getHeight()); }
private int position(String edge, boolean horiz) { float ratio = 0.0f; if ("top".equals(edge) && !horiz) { ratio = 1.0f; } else if ("bottom".equals(edge) && !horiz) { ratio = 0.0f; } else if ("left".equals(edge) && horiz) { ratio = 0.0f; } else if ("right".equals(edge) && horiz) { ratio = 1.0f; } else if ("mid".equals(edge)) { ratio = 0.5f; } else if (edge.endsWith("%")) { ratio = Float.parseFloat(edge.substring(0, edge.length() - 2)) / 100.0f; } else { System.out.println("Illegal anchor specified: " + edge + "/" + d); ratio = 0.0f; } if (horiz) { return ((int) (Game.getWidth() * ratio)) + d; } else { return ((int) (Game.getHeight() * ratio)) + d; } }
/* * (non-Javadoc) * @see net.puppygames.applet.Tickable#update() */ @Override public final void update() { calculateScreenPosition(); if (sprite != null) { // Firstly, if we're significantly offscreen, hide all the sprites. if (getScreenX() < -48.0f || getScreenX() >= Game.getWidth() + 48 || getScreenY() < -48.0f - getZ() || getScreenY() >= Game.getHeight() + 48 + getZ()) { for (Sprite element : sprite) { element.setVisible(false); } doUpdate(); return; } else { for (Sprite element : sprite) { element.setVisible(visible); } } boolean searchForChildOffsets = false; for (Sprite element : sprite) { element.setLocation(screenX, screenY, 0); if (element.getLayer() > Layers.SHADOW) { element.setFlash(flash); } // shall we bother checking anims for childOffset stuff? if (element.isDoChildOffset()) { searchForChildOffsets = true; } } if (searchForChildOffsets) { float xOffset = 0; float yOffset = 0; yOffsetTotal = 0; xOffsetTotal = 0; for (int i = 0; i < sprite.length; i++) { boolean doOffset = false; // check for offset if (sprite[i].getChildXOffset() != 0) { xOffset = sprite[i].getChildXOffset(); xOffset *= FPMath.floatValue(sprite[0].getXScale()); if (isMirrored() && xOffset != 0) { // chaz hack! - if we've got any <offset anim commands they'd need to be mirrored too // so for now will disable mirroring of childOffset if <offset x=""/> present if (sprite[i].getOffset(null).x == 0) { xOffset = -xOffset; } } xOffsetTotal += xOffset; doOffset = true; } if (sprite[i].getChildYOffset() != 0) { yOffset = sprite[i].getChildYOffset(); yOffset *= FPMath.floatValue(sprite[0].getYScale()); yOffsetTotal += yOffset; doOffset = true; } // if we've found an offset apply this to any sprites after where we found the offset if (doOffset) { for (int j = i + 1; j < sprite.length; j++) { if (sprite[j].isDoChildOffset()) { sprite[j].setLocation(screenX + xOffsetTotal, screenY + yOffsetTotal, 0); sprite[j].setYSortOffset( -yOffsetTotal - j); // the '-j' is chaz hack! budge layers YSortOffset a tad to force // render ok } } } } } LayersFeature currentAppearance = getCurrentAppearance(); float cx = getMapX() + getCollisionX(); float cy = getMapY() + getCollisionY(); if (currentAppearance != null && (GameScreen.isDiddlerOpen() || hackyTick > 0 || cx != oldX || cy != oldY || currentAppearance != oldAppearance)) { currentAppearance.updateColors(sprite, cx, cy); if (hackyTick > 0) { hackyTick--; } } oldX = cx; oldY = cy; oldAppearance = currentAppearance; } doUpdate(); }
private static void setScreenMode(Game game) { setScreenMode( game.getTitle(), game.resources, game.getWidth(), game.getHeight(), game.isResizable()); }
public void move() { if (x + vx > 0 && x + vx < game.getWidth() - WIDTH && y + vy > 0 && y + vy < game.getHeight()) { x = x + vx; y = y + vy; } }