/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; rect = new Rectangle(400,100,200,150); round = new RoundedRectangle(150,100,200,150,50); round2 = new RoundedRectangle(150,300,200,150,50); center = new Rectangle(350,250,100,100); poly = new Polygon(); poly.addPoint(400,350); poly.addPoint(550,320); poly.addPoint(600,380); poly.addPoint(620,450); poly.addPoint(500,450); gradient = new GradientFill(0,-75,Color.red,0,75,Color.yellow,true); gradient2 = new GradientFill(0,-75,Color.blue,0,75,Color.white,true); gradient4 = new GradientFill(-50,-40,Color.green,50,40,Color.cyan,true); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { this.container = container; image1 = new Image("testdata/grass.png"); image2 = new Image("testdata/rocks.png"); fill = new GradientFill(-64,0,new Color(1,1,1,1f),64,0,new Color(0,0,0,0)); shape = new Rectangle(336,236,128,128); poly = new Polygon(); poly.addPoint(320,220); poly.addPoint(350,200); poly.addPoint(450,200); poly.addPoint(480,220); poly.addPoint(420,400); poly.addPoint(400,390); }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { shapes = new ArrayList(); rect = new Rectangle(10, 10, 100, 80); shapes.add(rect); roundRect = new RoundedRectangle(150, 10, 60, 80, 20); shapes.add(roundRect); ellipse = new Ellipse(350, 40, 50, 30); shapes.add(ellipse); circle = new Circle(470, 60, 50); shapes.add(circle); polygon = new Polygon(new float[]{550, 10, 600, 40, 620, 100, 570, 130}); shapes.add(polygon); keys = new boolean[256]; lastChar = new char[256]; createPoly(200,200); }
/** * Set clipping that controls which areas of the world will be drawn to. * Note that world clip is different from standard screen clip in that it's * defined in the space of the current world coordinate - i.e. it's affected * by translate, rotate, scale etc. * * @param x * The x coordinate of the top left corner of the allowed area * @param y * The y coordinate of the top left corner of the allowed area * @param width * The width of the allowed area * @param height * The height of the allowed area */ public void setWorldClip(float x, float y, float width, float height) { predraw(); worldClipRecord = new Rectangle(x, y, width, height); GL.glEnable(SGL.GL_CLIP_PLANE0); worldClip.put(1).put(0).put(0).put(-x).flip(); GL.glClipPlane(SGL.GL_CLIP_PLANE0, worldClip); GL.glEnable(SGL.GL_CLIP_PLANE1); worldClip.put(-1).put(0).put(0).put(x + width).flip(); GL.glClipPlane(SGL.GL_CLIP_PLANE1, worldClip); GL.glEnable(SGL.GL_CLIP_PLANE2); worldClip.put(0).put(1).put(0).put(-y).flip(); GL.glClipPlane(SGL.GL_CLIP_PLANE2, worldClip); GL.glEnable(SGL.GL_CLIP_PLANE3); worldClip.put(0).put(-1).put(0).put(y + height).flip(); GL.glClipPlane(SGL.GL_CLIP_PLANE3, worldClip); postdraw(); }
/** * Tile a rectangle with a pattern specifing the offset from the top corner * that one tile should match * * @param x * The x coordinate of the rectangle * @param y * The y coordinate of the rectangle * @param width * The width of the rectangle * @param height * The height of the rectangle * @param pattern * The image to tile across the rectangle * @param offX * The offset on the x axis from the top left corner * @param offY * The offset on the y axis from the top left corner */ public void fillRect(float x, float y, float width, float height, Image pattern, float offX, float offY) { int cols = ((int) Math.ceil(width / pattern.getWidth())) + 2; int rows = ((int) Math.ceil(height / pattern.getHeight())) + 2; Rectangle preClip = getWorldClip(); setWorldClip(x, y, width, height); predraw(); // Draw all the quads we need for (int c = 0; c < cols; c++) { for (int r = 0; r < rows; r++) { pattern.draw(c * pattern.getWidth() + x - offX, r * pattern.getHeight() + y - offY); } } postdraw(); setWorldClip(preClip); }
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException { sb = sbg; InputProvider provider = new InputProvider(gc.getInput()); provider.addListener(this); fps = new TrueTypeFont(Fonts.fpsCounter.getFont(), true); active = new TrueTypeFont(Fonts.active.getFont(), true); inactive = new TrueTypeFont(Fonts.inactive.getFont(), true); provider.bindCommand(new KeyControl(Input.KEY_UP), up); provider.bindCommand(new KeyControl(Input.KEY_DOWN), down); provider.bindCommand(new KeyControl(Input.KEY_LEFT), left); provider.bindCommand(new KeyControl(Input.KEY_RIGHT), right); provider.bindCommand(new KeyControl(Input.KEY_ENTER), enter); for (int i = 0; i < rect.length; i++) { rect[i] = new Rectangle(20, 20 + (70 * i), statValues[i] * 40, Play.width/30); } }
public Particle(String image_, Color color_, Pair<Float> position_, float velocity_, float theta_, float angularVelocity_, Pair<Float> size_, long lifespan_, long created_) { this.image = image_; this.color = color_; this.position = position_; this.velocity = velocity_; this.theta = theta_; this.angularVelocity = angularVelocity_; this.size = size_; this.lifespan = lifespan_; this.created = created_; this.collision = false; this.bounds = new Rectangle((position.x - (size.x / 2)), (position.y - (size.y / 2)), size.x, size.y); }
@Override public void init(GameContainer gc, StateBasedGame game) throws SlickException { shopBoxes = new Rectangle[SHOP_ROWS][SHOP_COLS]; for(int r = 0; r < SHOP_ROWS; r++) { for(int c = 0; c < SHOP_COLS; c++) { float x = SHOP_CONTAINER.x + 3.0f + ((c * ITEM_BOX_SIZE) + (c * 2.0f)); float y = SHOP_CONTAINER.y + 3.0f + ((r * ITEM_BOX_SIZE) + (c * 2.0f)); shopBoxes[r][c] = new Rectangle(x, y, ITEM_BOX_SIZE, ITEM_BOX_SIZE); } } inventoryBoxes = null; selected = null; selectedInInventory = false; buyButton = new TransactionButton(new Pair<Float>((float)((Globals.WIDTH / 2) - 58.0f), (Globals.HEIGHT - 70.0f)), TransactionButton.Type.BUY); sellButton = new TransactionButton(new Pair<Float>((float)((Globals.WIDTH / 2) + 58.0f), (Globals.HEIGHT - 70.0f)), TransactionButton.Type.SELL); inventorySize = 0; exit = false; }
@Override public void enter(GameContainer gc, StateBasedGame game) { exit = false; if(Globals.player.getInventory().getCapacity() != inventorySize) { // Inventory size has changed. Re-build inventory layout. inventorySize = Globals.player.getInventory().getCapacity(); int cols = SHOP_COLS; int rows = (int)(Math.ceil((float)inventorySize / (float)cols)); if(inventoryBoxes == null) { inventoryBoxes = new Rectangle[rows][cols]; } for(int r = 0; r < rows; r++) { for(int c = 0; c < cols; c++) { float x = INVENTORY_CONTAINER.x + 3.0f + ((c * ITEM_BOX_SIZE) + (c * 2.0f)); float y = INVENTORY_CONTAINER.y + 3.0f + ((r * ITEM_BOX_SIZE) + (c * 2.0f)); inventoryBoxes[r][c] = new Rectangle(x, y, ITEM_BOX_SIZE, ITEM_BOX_SIZE); } } } }
@Override public void render(GameContainer container, Graphics g) throws SlickException { if (canSeePlayer()) { g.drawImage(ResourceManager.getImage(G.SHADOW), x, y); super.render(container, g); int w = (32 * hp) / maxHp; if (w < 0) { w = 0; } else if (w > 32) { w = 32; } hbar = new Rectangle(x, y, w, 3); g.setColor(Color.red); g.fill(hbar); g.resetTransform(); } }
@Override public void init() { selected = 0; amountOptions = 2; image = Sprite.get("menu.png"); try { sfx_select = new Sound(GamePanel.resfolder + "sound" + File.separator + "select.wav"); } catch (SlickException e) { e.printStackTrace(); } Entity.getEntities().clear(); play = new Rectangle(40, 50, 50, 24); quit = new Rectangle(40, 86, 50, 24); }
@Override public void init(GameContainer container, StateBasedGame game) throws SlickException { CHANGE_SEASON_SIZE = 150; CHANGE_SEASON_PADDING = 150; this.initProcessor(container, game); this.pressed = new LinkedList<TouchPosition>(); this.vibration = (Vibrator)AndroidLoader.ANDROID_CONTEXT.getSystemService(Context.VIBRATOR_SERVICE); //Obt�m as imagens dos controles. PackedSpriteSheet pack = new PackedSpriteSheet("data/sprites/control.def", Image.FILTER_NEAREST); this.controls = new Image[3]; this.controls[0] = pack.getSprite("control_left"); this.controls[1] = pack.getSprite("control_right"); this.controls[2] = pack.getSprite("control_up"); //Posi��es dos bot�es do controle. this.left = new Rectangle(5, 347, 80, 128); this.right = new Rectangle(85, 347, 80, 128); this.up = new Rectangle(667, 347, 128, 128); this.lastDragPoint = new Vec2(0,0); }
/** * Delete o tile na posi��o atual do mundo. */ private void deleteTile() { //Verifica se h� algum sprite na posi��o atual. for (int i = this.tiles.size() - 1; i >= 0; i--) { TileData data = this.tiles.get(i); Image sprite = this.packs.get(data.definitionFileId).getSprite(data.spriteName); //Cria um ret�ngulo representando a imagem. float width = this.transform.convertPixelsInWorldScale(sprite.getWidth()); float height = this.transform.convertPixelsInWorldScale(sprite.getHeight()); float x = data.position.x - width / 2; float y = data.position.y - height / 2; Rectangle rec = new Rectangle(x, y, width, height); //Verifica se o ponto est� no ret�ngulo. Vec2 worldPosition = this.transform.screenToWorld(this.currentTilePosition); if (rec.contains(worldPosition.x, worldPosition.y)) { this.tiles.remove(i); break; } } }
/** * Verifica qual a porcentagem de um determinado objeto de um determinado tamanho no viewport. * @param objCenter Centro do corpo, em unidades do mundo. * @param halfWidth Metade da largura do corpo, em unidades do mundo. * @param halfHeight Metade da largura do corpo, em unidades do mundo. * @param offset Extens�es da �rea de avalia��o de som. * @return Porcentagem da �rea do objeto no viewport. */ public float isInViewport(Vec2 objCenter, float halfWidth, float halfHeight, Vec2 offset) { //Por padr�o, o fatro de som � 0. float factor = 0; //O corpo tem suas medidas convertidas para unidades de tela e sua posi��o no canto superior esquerdo. Vec2 wObjCenter = this.worldToScreen(objCenter); Vec2 size = new Vec2(this.convertWorldScaleInPixels(halfWidth), this.convertWorldScaleInPixels(halfHeight)); size.x *= offset.x; size.y *= offset.y; Rectangle body = new Rectangle(wObjCenter.x - size.x, wObjCenter.y - size.y, size.x * 2, size.y * 2); //Primeiramente, verifica se os ret�ngulos interseccionaram. if (Utils.intersect(cam, body)) { /* Caso tenham interseccionado, verifica o fator de som * de acordo com a �rea de r2 em r1.*/ Rectangle overlap = Utils.getOverlapArea(cam, body); factor = (overlap.getWidth() * overlap.getHeight()) / (body.getWidth() * body.getHeight()); //Normaliza o fator. if (factor > 1.0f) factor = 1.0f; } return factor; }
public TileMatrixManager(ArrayList<Rectangle> rectangleList, ArrayList<Tile> savedTileList, int savedScore) { this(rectangleList); score = savedScore; //create the tile matrix for (int y = 0; y < tileMatrix.getMatrixSize(); y++) for (int x = 0; x < tileMatrix.getMatrixSize(); x++) { Tile currentTile = savedTileList.get(y * tileMatrix.getMatrixSize() + x); if (currentTile != null) { tileMatrix.set(x, y, currentTile); currentTile.setX(goodPositions.get(x, y).getX()); tileMatrix.get(x, y).setY(goodPositions.get(x, y).getY()); } } nextTileMatrix = tileMatrix; }
private void initPositionBody() { float border = 10; float currentX = this.body.getMinX(); float width = this.body.getSizeX() / this.table.size(); float currentY = this.body.getMinY(); this.positionBody.clear(); for (Map.Entry<Element, ListElement> entry : this.table.entrySet()) { float height = this.body.getSizeY() - entry.getKey().getAbsoluteHeight() - border; height = (height < 0 ? 0 : height); float widthWithBorder = width - (border * 2); widthWithBorder = (widthWithBorder < 0 ? 0 : widthWithBorder); if (entry.getKey().getType() == EnumOverlayElement.IMAGE) { this.positionBody.put(entry.getKey().getId(), new Pair<>(new BodyRect(new Rectangle(currentX, currentY, widthWithBorder, entry.getKey().getAbsoluteHeight())), new BodyRect(new Rectangle(currentX + border, currentY + entry.getKey().getAbsoluteHeight(), widthWithBorder, height)))); } else if (entry.getKey().getType() == EnumOverlayElement.STRING) { this.positionBody.put(entry.getKey().getId(), new Pair<>(new BodyRect(new Rectangle(currentX + border, currentY, widthWithBorder, entry.getKey().getAbsoluteHeight())), new BodyRect(new Rectangle(currentX + border, currentY + entry.getKey().getAbsoluteHeight(), widthWithBorder, height), ColorTools.get(ColorTools.Colors.TRANSPARENT_GREYBLUE)))); } else if (entry.getKey().getType() == EnumOverlayElement.BUTTON) { this.positionBody.put(entry.getKey().getId(), new Pair<>(new BodyRect(new Rectangle(currentX + border, currentY, widthWithBorder, entry.getKey().getAbsoluteHeight())), new BodyRect(new Rectangle(currentX + border, currentY + entry.getKey().getAbsoluteHeight(), widthWithBorder, height), ColorTools.get(ColorTools.Colors.TRANSPARENT_GREYBLUE)))); } currentX += width; } }
private void initTableMenuSettings() { InterfaceElement tableMenuSettings = this.elements.get(EnumOverlayElement.TABLE_MENU_SETTINGS); float posX = tableMenuSettings.getBody().getMinX(); float posY = tableMenuSettings.getBody().getMinY(); float sizeX = tableMenuSettings.getBody().getSizeX(); tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, sizeX, StringTools.charSizeY())), new StringTimer("Settings"), Color.white, Element.PositionInBody.MIDDLE_MID)); posY += (StringTools.charSizeY() * 2); tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, tableMenuSettings.getBody().getSizeX() / 2, StringTools.charSizeY())), new StringTimer("Sounds"), Color.white, Element.PositionInBody.MIDDLE_MID)); posY += (StringTools.charSizeY() * 2); tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, (int) (tableMenuSettings.getBody().getSizeX() / 1.1), StringTools.charSizeY())), new StringTimer(String.valueOf((int) (SoundController.getVolume() * 100))), Color.black, EnumOverlayElement.SOUNDS_VALUE.getValue(), Element.PositionInBody.RIGHT_MID)); tableMenuSettings.doTask(new ImageElement(new BodyRect(new Rectangle(posX + 10, posY + 4, 202, 12), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLACK)), EnumOverlayElement.SOUNDS_GRAPH.getValue() + EnumOverlayElement.BORDER.getValue(), Element.PositionInBody.LEFT_MID)); tableMenuSettings.doTask(new ImageElement(new BodyRect(new Rectangle(posX + 11, posY + 5, 200, 10), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLUE)), EnumOverlayElement.SOUNDS_GRAPH.getValue(), Element.PositionInBody.LEFT_MID)); posY += 50; tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, tableMenuSettings.getBody().getSizeX() / 2, StringTools.charSizeY())), new StringTimer("Musics"), Color.white, Element.PositionInBody.MIDDLE_MID)); posY += (StringTools.charSizeY() * 2); tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, (int) (tableMenuSettings.getBody().getSizeX() / 1.1), StringTools.charSizeY())), new StringTimer(String.valueOf((int) (MusicController.getVolume() * 100))), Color.black, EnumOverlayElement.MUSICS_VALUE.getValue(), Element.PositionInBody.RIGHT_MID)); tableMenuSettings.doTask(new ImageElement(new BodyRect(new Rectangle(posX + 10, posY + 4, 202, 12), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLACK)), EnumOverlayElement.MUSICS_GRAPH.getValue() + EnumOverlayElement.BORDER.getValue(), Element.PositionInBody.LEFT_MID)); tableMenuSettings.doTask(new ImageElement(new BodyRect(new Rectangle(posX + 11, posY + 5, 200, 10), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLUE)), EnumOverlayElement.MUSICS_GRAPH.getValue(), Element.PositionInBody.LEFT_MID)); tableMenuSettings.doTask(new Pair<>(EnumOverlayElement.SOUNDS_GRAPH, new Pair<>("cutBody", SoundController.getVolume() / SoundController.getMaxVolume()))); tableMenuSettings.doTask(new Pair<>(EnumOverlayElement.MUSICS_GRAPH, new Pair<>("cutBody", MusicController.getVolume() / MusicController.getMaxVolume()))); }
private void initTableMenuSettings() { InterfaceElement tableMenuSettings = this.elements.get(EnumOverlayElement.TABLE_MENU_SETTINGS); float posX = tableMenuSettings.getBody().getMinX(); float posY = tableMenuSettings.getBody().getMinY(); float sizeX = tableMenuSettings.getBody().getSizeX(); tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, sizeX, StringTools.charSizeY())), new StringTimer("Settings"), Color.black, Element.PositionInBody.MIDDLE_MID)); posY += (StringTools.charSizeY() * 2); tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, tableMenuSettings.getBody().getSizeX() / 2, StringTools.charSizeY())), new StringTimer("Sounds"), Color.black, Element.PositionInBody.MIDDLE_MID)); posY += (StringTools.charSizeY() * 2); tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, (int) (tableMenuSettings.getBody().getSizeX() / 1.1), StringTools.charSizeY())), new StringTimer(String.valueOf((int) (SoundController.getVolume() * 100))), Color.black, EnumOverlayElement.SOUNDS_VALUE.getValue(), Element.PositionInBody.RIGHT_MID)); tableMenuSettings.doTask(new ImageElement(new BodyRect(new Rectangle(posX + 10, posY + 4, 202, 12), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLACK)), EnumOverlayElement.SOUNDS_GRAPH.getValue() + EnumOverlayElement.BORDER.getValue(), Element.PositionInBody.LEFT_MID)); tableMenuSettings.doTask(new ImageElement(new BodyRect(new Rectangle(posX + 11, posY + 5, 200, 10), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLUE)), EnumOverlayElement.SOUNDS_GRAPH.getValue(), Element.PositionInBody.LEFT_MID)); posY += 50; tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, tableMenuSettings.getBody().getSizeX() / 2, StringTools.charSizeY())), new StringTimer("Musics"), Color.black, Element.PositionInBody.MIDDLE_MID)); posY += (StringTools.charSizeY() * 2); tableMenuSettings.doTask(new StringElement(new BodyRect(new Rectangle(posX, posY, (int) (tableMenuSettings.getBody().getSizeX() / 1.1), StringTools.charSizeY())), new StringTimer(String.valueOf((int) (MusicController.getVolume() * 100))), Color.black, EnumOverlayElement.MUSICS_VALUE.getValue(), Element.PositionInBody.RIGHT_MID)); tableMenuSettings.doTask(new ImageElement(new BodyRect(new Rectangle(posX + 10, posY + 4, 202, 12), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLACK)), EnumOverlayElement.MUSICS_GRAPH.getValue() + EnumOverlayElement.BORDER.getValue(), Element.PositionInBody.LEFT_MID)); tableMenuSettings.doTask(new ImageElement(new BodyRect(new Rectangle(posX + 11, posY + 5, 200, 10), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLUE)), EnumOverlayElement.MUSICS_GRAPH.getValue(), Element.PositionInBody.LEFT_MID)); tableMenuSettings.doTask(new Pair<>(EnumOverlayElement.SOUNDS_GRAPH, new Pair<>("cutBody", SoundController.getVolume() / SoundController.getMaxVolume()))); tableMenuSettings.doTask(new Pair<>(EnumOverlayElement.MUSICS_GRAPH, new Pair<>("cutBody", MusicController.getVolume() / MusicController.getMaxVolume()))); }
private void initTankIcons(EnumGameObject tankType) { InterfaceElement tableIcon = this.elements.get(EnumOverlayElement.TABLE_ICON); tableIcon.clearData(); List<EnumOverlayElement> values = EnumOverlayElement.getOverlayElementByGameObject(tankType).getSameIndexList(); if (values.size() >= 6) { tableIcon.doTask(new ButtonElement(new ImageElement(new BodyRect(new Rectangle(tableIcon.getBody().getMinX(), tableIcon.getBody().getMinY(), 64, 64)), this.animatorOverlayData.getIconAnimator(values.get(0)), EnumOverlayElement.HIT.getValue(), Element.PositionInBody.MIDDLE_MID), values.get(3))); tableIcon.doTask(new ButtonElement(new ImageElement(new BodyRect(new Rectangle(tableIcon.getBody().getMinX() + 64, tableIcon.getBody().getMinY(), 64, 64)), this.animatorOverlayData.getIconAnimator(values.get(1)), EnumOverlayElement.SPELL.getValue(), Element.PositionInBody.MIDDLE_MID), values.get(4))); tableIcon.doTask(new ButtonElement(new ImageElement(new BodyRect(new Rectangle(tableIcon.getBody().getMinX() + 128, tableIcon.getBody().getMinY(), 64, 64)), this.animatorOverlayData.getIconAnimator(values.get(2)), EnumOverlayElement.BOX.getValue(), Element.PositionInBody.MIDDLE_MID), values.get(5))); tableIcon.doTask(new Pair<>(values.get(3), new StringListElement(new BodyRect(new Rectangle(tableIcon.getBody().getMinX() - 100, tableIcon.getBody().getMinY() - 100, 280, 100), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLACK))))); tableIcon.doTask(new Pair<>(values.get(4), new StringListElement(new BodyRect(new Rectangle(tableIcon.getBody().getMinX() - 100, tableIcon.getBody().getMinY() - 100, 320, 100), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLACK))))); tableIcon.doTask(new Pair<>(values.get(5), new StringListElement(new BodyRect(new Rectangle(tableIcon.getBody().getMinX() - 100, tableIcon.getBody().getMinY() - 100, 300, 100), ColorTools.get(ColorTools.Colors.TRANSPARENT_BLACK))))); tableIcon.doTask(new Pair<>(values.get(3), new StringElement(new StringTimer(this.overlayConfigs.getData(values.get(3))), Color.white, values.get(3).getValue(), Element.PositionInBody.MIDDLE_MID))); tableIcon.doTask(new Pair<>(values.get(4), new StringElement(new StringTimer(this.overlayConfigs.getData(values.get(4))), Color.white, values.get(4).getValue(), Element.PositionInBody.MIDDLE_MID))); tableIcon.doTask(new Pair<>(values.get(5), new StringElement(new StringTimer(this.overlayConfigs.getData(values.get(5))), Color.white, values.get(5).getValue(), Element.PositionInBody.MIDDLE_MID))); } }
@Override protected void updatePosition() { if (this.body != null) { float currentX = this.body.getMinX(); float currentY = this.body.getMaxY(); for (Element element : this.elements) { if (currentY - element.getAbsoluteHeight() >= this.body.getMinY()) { currentY -= element.getAbsoluteHeight(); element.setBody(new BodyRect(new Rectangle(currentX, currentY, this.body.getSizeX(), element.getAbsoluteHeight()))); } else { element.setBody(new BodyRect(new Rectangle(-1f, -1f, this.body.getSizeX(), element.getAbsoluteHeight()))); } } this.changed = false; } }
@Override protected void updatePosition() { if (this.body != null) { float currentX = this.body.getMinX(); float currentY = this.body.getMinY(); for (int i = this.elements.size() - 1; i >= 0; --i) { Element element = this.elements.get(i); if (currentY + element.getAbsoluteHeight() <= this.body.getMaxY()) { currentY += element.getAbsoluteHeight() + this.border; element.setBody(new BodyRect(new Rectangle(currentX, currentY, this.body.getSizeX(), element.getAbsoluteHeight()))); } else { element.setBody(new BodyRect(new Rectangle(-1f, -1f, this.body.getSizeX(), element.getAbsoluteHeight()))); } } this.changed = false; } }
/** * Creates a new player * * @param id * the id to assign to the new player * @param role * the role of the new Player, see * {@link org.javajumper.saboteur.player.Role Role} * @param name * the name to assign to the new player * @param lifepoints * the initial lifepoints of the new player * @param pos * the position to set the player to */ public Player(int id, Role role, String name, int lifepoints, Vector2f pos) { this.id = id; this.role = role; this.name = name; this.lifepoints = lifepoints; this.currentWeapon = 0; this.inventory = new Item[3]; this.pos = pos; this.move = new Vector2f(0, 0); this.lookAngle = 0f; this.sprinting = false; this.dead = false; this.ready = false; collisionBox = new Rectangle(pos.x, pos.y, 32, 32); }
/** * Basic Constructor * @param title * @param xPos * @param yPos * @param width * @param height * @throws SlickException */ public Panel(String title, float xPos, float yPos, float width, float height) throws SlickException { // Basic Attributes this.title = title; this.xPos = xPos; this.yPos = yPos; this.width = width; this.height = height; // As default, it is not visible when it's first created this.visible = false; // Creates the Rectangle forms window = new Rectangle(xPos, yPos, width, height); dropShadow = new Rectangle(xPos + 4f, yPos + 4f, width, height); titleBar = new Rectangle(xPos, yPos, width, LINE_Y_OFFSET + 6f); backgroundColor = new Color(255f, 255f, 255f, 1f); }
protected Panel(String title, float xPos, float yPos, float width, float height, float titleBarHeight) throws SlickException { // Basic Attributes this.title = title; this.xPos = xPos; this.yPos = yPos; this.width = width; this.height = height; // As default, it is not visible when it's first created this.visible = false; // Creates the Rectangle forms window = new Rectangle(xPos, yPos, width, height); dropShadow = new Rectangle(xPos + 4f, yPos + 4f, width, height); titleBar = new Rectangle(xPos, yPos, width, titleBarHeight); backgroundColor = new Color(255f, 255f, 255f, 1f); }
private AStarNode searchPath(Vector2f dest, int availableIterations) { AStarNode node = mNodes.poll(); if (node != null && availableIterations > 0) { for (Vector2f movement : mMovements) { mPositionToStudy.x = node.getPosition().x + movement.x; mPositionToStudy.y = node.getPosition().y + movement.y; Rectangle rect = new Rectangle(mPositionToStudy.x, mPositionToStudy.y, mEntity.getBounds().getWidth(), mEntity.getBounds().getHeight()); if (!mMap.isSomethingBlocking(rect)) { AStarNode newNode = new AStarNode(node, mPositionToStudy); if (newNode.getPosition().equals(dest)) { return newNode; } if (!nodeIsVisisted(newNode)) { mVisitedNodes.add(newNode); mNodes.add(newNode); } } } return (this.searchPath(dest, availableIterations - 1)); } return null; }
public boolean isSomethingBlocking(Rectangle rectangle) { int x = (int)(rectangle.getX() / mTmxMap.getTilewidth()); int y = (int)(rectangle.getY() / mTmxMap.getTileheight()); int endX = (int)((rectangle.getX() + rectangle.getWidth()) / mTmxMap.getTilewidth()); int endY = (int)((rectangle.getY() + rectangle.getHeight()) / mTmxMap.getTileheight()); int mapX = mTmxMap.getWidth(); int mapY = mTmxMap.getHeight(); // System.out.println(mapX + ", " + mapY); if (x >= mapX || y >= mapY) { return true; } for (; x < endX; ++x) { for (; y < endY; ++y) { MapElement m = getMapElement(x, y); if (m != null && m.isBlocking()) { return true; } } } return false; }
/** * Mainly used for debugging purposes. * @param returnNodes The list of nodes. * @return A list of all nodes in the tree */ public ArrayList<Rectangle> getNodes(ArrayList<Rectangle> returnNodes){ if(nodes[0] != null){ nodes[0].getNodes(returnNodes); } if(nodes[1] != null){ nodes[1].getNodes(returnNodes); } if(nodes[2] != null){ nodes[2].getNodes(returnNodes); } if(nodes[3] != null){ nodes[2].getNodes(returnNodes); } returnNodes.add(bounds); return returnNodes; }
/** * Set clipping that controls which areas of the world will be drawn to. Note that world clip is different from * standard screen clip in that it's defined in the space of the current world coordinate - i.e. it's affected by * translate, rotate, scale etc. * * @param x * The x coordinate of the top left corner of the allowed area * @param y * The y coordinate of the top left corner of the allowed area * @param width * The width of the allowed area * @param height * The height of the allowed area */ void setWorldClip(float x, float y, float width, float height) { predraw(); worldClipRecord = new Rectangle(x, y, width, height); GL.glEnable(SGL.GL_CLIP_PLANE0); worldClip.put(1).put(0).put(0).put(-x).flip(); GL.glClipPlane(SGL.GL_CLIP_PLANE0, worldClip); GL.glEnable(SGL.GL_CLIP_PLANE1); worldClip.put(-1).put(0).put(0).put(x + width).flip(); GL.glClipPlane(SGL.GL_CLIP_PLANE1, worldClip); GL.glEnable(SGL.GL_CLIP_PLANE2); worldClip.put(0).put(1).put(0).put(-y).flip(); GL.glClipPlane(SGL.GL_CLIP_PLANE2, worldClip); GL.glEnable(SGL.GL_CLIP_PLANE3); worldClip.put(0).put(-1).put(0).put(y + height).flip(); GL.glClipPlane(SGL.GL_CLIP_PLANE3, worldClip); postdraw(); }