@Override public void render(Graphics g) { int sx = 0; int sy = 0; if (moving() && onGround()) { sx = frame % nb_sprites; sy = 0; } else if (onGround()) { sx = 0; sy = 0; } // get the appropriate sprite Image image = walk.getSprite(sx, sy); image = image.getFlippedCopy(true, false); // if we're facing the other direction, flip the sprite over if (facingRight()) { image = image.getFlippedCopy(true, false); } image.draw(getX() - width / 2, getY() - height / 2, width, height + 4); permanentSound(); }
public void render(Graphics g) { // work out which animation we're showing based // on the state of the actor SpriteSheet sheet = jump; int sx = 0; int sy = 0; if (jumping()) { sheet = jump; sx = 0; sy = 0; } else if (falling()) { sheet = jump; sx = 0; sy = 0; } /*else if(waiting()) { sheet = jump; sx = 0; sy = 0; } */ else if (moving() && onGround()) { sheet = walk; sx = frame % NB_SPRITES_WALK; sy = Y_OFFSET_WALK; } else if (onGround() || waiting()) { sheet = walk; sx = 0; sy = Y_OFFSET_WALK; } // get the appropriate sprite Image image = sheet.getSprite(sx, sy); image = image.getFlippedCopy(true, false); // if we're facing the other direction, flip the sprite over if (facingRight()) { image = image.getFlippedCopy(true, false); } // image.drawCentered(getX(), getY()-12); if (!Globals.invulnerable || Globals.invulnerableTimer % 2 == 1) image.draw(getX() - width / 2, getY() - height / 2, width, height + 2); }
public void fly() { if (!isFlying()) { return; } setRotation(getRotation() % 360); if (remainingFuel <= 0) { setFlying(false); return; } remainingFuel -= fuelConsumptionRate; remainingFuel = (remainingFuel < 0) ? 0 : remainingFuel; float theRot = (float) Math.toRadians(getRotation()); float xVec, yVec; xVec = (float) Math.sin(theRot) * 10000; yVec = (float) Math.cos(theRot) * (-800); if (getRotation() <= 180 || getRotation() >= 270) { yVec = (yVec > -600) ? -600 : yVec; } else { yVec -= 200; } this.applyForce(xVec, yVec - 200); sprayImage = sprayImage.getFlippedCopy(true, false); theRot = (float) Math.toRadians(getRotation()); sprayImage.setRotation(theRot); float oldX = getVisualX(); float oldY = getVisualY(); float newX; float newY; try { AffineTransform transformer = AffineTransform.getRotateInstance(theRot, oldX, oldY); Point2D before = new Point2D.Double(oldX, oldY + 60); Point2D after = new Point2D.Double(); after = transformer.transform(before, after); newX = (float) after.getX(); newY = (float) after.getY(); sprayX = newX; sprayY = newY; } catch (Exception e) { System.out.println(e); } }
public void render( GameContainer container, Graphics g, float offsetX, float offsetY, Actor actor) { float zoneWidth = actor.zoneBox.getWidth(); Image image = frames[currentFrame].getImage(); offsetY = offsetY + frames[currentFrame].getOffsetY(); // TODO Image decompression. // image.draw(x,y,scale); if (actor.isFacingLeft) g.drawImage( image.getFlippedCopy(true, false), offsetX + zoneWidth / 2 - frames[currentFrame].getOffsetX() + (zoneWidth - image.getWidth()), offsetY); else g.drawImage(image, offsetX - zoneWidth / 2 + frames[currentFrame].getOffsetX(), offsetY); }
@Override public void render(GameContainer gc, Graphics g) throws SlickException { if (!isMoving()) { setImage(sheet.getSprite("little_robot_00.png")); initialImage = getImage(); } if (isJumping()) { currentState = "Jumping"; } else if (isFalling()) { currentState = "Falling"; } else if (isOnGround()) { if (isMoving()) currentState = "isMoving"; else { currentState = "OnGround"; } } setImage(initialImage); if (!isFacingRight()) { setImage(initialImage.getFlippedCopy(true, false)); } if (isMoving() && isOnGround()) { currentState = "rotating -> " + getRotation(); } getImage().setRotation(getRotation()); getImage().drawCentered(getVisualX(), getVisualY()); if (isFlying()) { sprayImage.setRotation(getRotation()); sprayImage.drawCentered(sprayX, sprayY); } }
public LogControl(GUIContext container, Font font) { super(container); this.font = font; output = new TextOutput(container, font, ""); maxLinesCountMinimized = textAreaHeightMinimized / font.getLineHeight(); maxLinesCountMaximized = textAreaHeightMaximized / font.getLineHeight(); Image arrowImage = ResourceManager.getInstance().getImage("LOG_ARROW"); arrowUp = new Picture(container, arrowImage); arrowDown = new Picture(container, arrowImage.getFlippedCopy(false, true)); arrowUp.onMouseClickedAdd( new MouseClickedAction() { @Override public void execute(AbstractControl sender, MouseClickedEventArgs e) { LogControl log = ((LogControl) sender.getParent()); if (log.startDisplayIndex > 0) { log.startDisplayIndex--; refreshOutput(); } } }); arrowDown.onMouseClickedAdd( new MouseClickedAction() { @Override public void execute(AbstractControl sender, MouseClickedEventArgs e) { LogControl log = ((LogControl) sender.getParent()); if (messages.size() > maxLinesCount && log.startDisplayIndex < messages.size() - maxLinesCount) { log.startDisplayIndex++; refreshOutput(); } } }); minBackground = new Picture(container, ResourceManager.getInstance().getImage("LOG_BACKGROUND_MIN")); maxBackground = new Picture(container, ResourceManager.getInstance().getImage("LOG_BACKGROUND_MAX")); minimize = new Picture(container, ResourceManager.getInstance().getImage("LOG_BUTTON_MINIMIZE")); maximize = new Picture(container, ResourceManager.getInstance().getImage("LOG_BUTTON_MAXIMIZE")); minimize.onMouseClickedAdd( new MouseClickedAction() { @Override public void execute(AbstractControl sender, MouseClickedEventArgs e) { ((LogControl) sender.getParent()).setState(false); } }); maximize.onMouseClickedAdd( new MouseClickedAction() { @Override public void execute(AbstractControl sender, MouseClickedEventArgs e) { ((LogControl) sender.getParent()).setState(true); } }); this.addChild(minBackground); this.addChild(maxBackground); this.addChild(maximize, new Size(428, 64)); this.addChild(minimize, new Size(428, 220)); this.addChild(arrowUp, new Size(410, 15)); this.addChild(arrowDown, new Size(410, 40)); this.addChild(output, new Size(12, 12)); setState(false); }
@Override public void update(GameContainer container, int delta) throws SlickException { // throw new UnsupportedOperationException("Not supported yet."); Input input = container.getInput(); // rotate quad double x1 = jugador1.getPosicion().getX(); double y1 = jugador1.getPosicion().getY(); if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) { plane1.rotate(-0.2f * delta); } if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { plane1.rotate(0.2f * delta); } if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { float hip = 0.4f * delta; float rotation = plane1.getRotation(); x1 -= hip * Math.sin(Math.toRadians(rotation)); y1 += hip * Math.cos(Math.toRadians(rotation)); } if (Keyboard.isKeyDown(Keyboard.KEY_UP)) { float hip = 0.4f * delta; float rotation = plane1.getRotation(); x1 += hip * Math.sin(Math.toRadians(rotation)); y1 -= hip * Math.cos(Math.toRadians(rotation)); } // keep quad on the screen if (x1 < 10) { x1 = 10; } if (x1 > 790) { x1 = 790; } if (y1 < 10) { y1 = 10; } if (y1 > 590) { y1 = 590; } Vector posicion = jugador1.getPosicion(); posicion.setX(x1); posicion.setY(y1); jugador1.setPosicion(posicion); // jugador 2 if (Keyboard.isKeyDown(Keyboard.KEY_W)) lastSteering = 1; if (Keyboard.isKeyDown(Keyboard.KEY_A)) lastSteering = 2; if (Keyboard.isKeyDown(Keyboard.KEY_F)) lastSteering = 3; if (Keyboard.isKeyDown(Keyboard.KEY_S)) lastSteering = 4; /* switch(lastSteering) { case 1: jugador2.update(steeringW.getSteering(), delta); break; case 2: jugador2.update(steeringA.getSteering(), delta); break; case 3: jugador2.update(steeringF.getSteering(), delta); break; case 4: jugador2.update(steeringS.getSteering(), delta); break; default: }*/ // plane2.rotate((float) jugador2.getOrientacion()); if (input.isKeyPressed(Input.KEY_F1)) { Image target = new Image(container.getWidth(), container.getHeight()); container.getGraphics().copyArea(target, 0, 0); ImageOut.write(target.getFlippedCopy(false, true), "screenshot.png", false); target.destroy(); } }