private void renderAmmo() {
   Ammo ammo = ammoMapper.get(player);
   g.translate(container.getWidth() - 64, container.getHeight() - 45);
   {
     font.drawString(-16, 8, "Ammo");
     g.rotate(0, 0, -90);
     float ammoStatus = ammo.getAmmoStatus();
     g.setDrawMode(Graphics.MODE_ADD);
     statusBar.draw(
         0,
         0,
         statusBar.getWidth() * ammoStatus,
         statusBar.getHeight(),
         0,
         0,
         statusBar.getWidth() * ammoStatus,
         statusBar.getHeight(),
         ammoStatus < 0.25 ? Color.red : ammoStatus < 0.6 ? Color.yellow : Color.green);
     statusBar.draw(
         statusBar.getWidth() * ammoStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         statusBar.getWidth() * ammoStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         new Color(0.15f, 0.15f, 0.15f));
     g.setDrawMode(Graphics.MODE_NORMAL);
     g.rotate(0, 0, 90);
   }
   g.translate(-container.getWidth() + 64, -container.getHeight() + 45);
 }
 @SuppressWarnings("unused")
 public void mouseClicked(int button, int x, int y, int clickCount) {
   if ((x >= NEWGAME_X && x <= (NEWGAME_X + newGameImage.getWidth()))
       && (y >= NEWGAME_Y && y <= (NEWGAME_Y + newGameImage.getHeight()))) {
     selection = Game.NEWGAME_STATE;
   } else if ((x >= LOADGAME_X && x <= (LOADGAME_X + loadGameImage.getWidth()))
       && (y >= LOADGAME_Y && y <= (LOADGAME_Y + loadGameImage.getHeight()))) {
     selection = Game.LOADGAME_STATE;
   } else if (optionsActivated
       && (x >= OPTIONS_X && x <= (OPTIONS_X + optionsImage.getWidth()))
       && (y >= OPTIONS_Y && y <= (OPTIONS_Y + optionsImage.getHeight()))) {
     selection = Game.OPTIONSGAME_STATE;
   } else {
     int id = Save.getInstance().levelIdForPoint(x - MAP_X, y - MAP_Y);
     if (id > -1 && Save.getInstance().hasSaveLoaded()) {
       if (!Save.getInstance().hasUnlockedLevelWithID(id)) {
         mapErrorLabel.setText("Niveau pas encore debloque!");
       } else {
         selection = Game.GAMEPLAY_STATE;
         levelSelection = id;
         mapErrorLabel.setText("");
       }
     }
   }
 }
 private void renderHealth() {
   Health health = healthMapper.get(player);
   g.translate(35, container.getHeight() - 45);
   {
     font.drawString(-26, 8, "Health");
     g.rotate(0, 0, -90);
     float healthStatus = health.getHealthStatus();
     g.setDrawMode(Graphics.MODE_ADD);
     statusBar.draw(
         0,
         0,
         statusBar.getWidth() * healthStatus,
         statusBar.getHeight(),
         0,
         0,
         statusBar.getWidth() * healthStatus,
         statusBar.getHeight(),
         healthStatus < 0.25 ? Color.red : healthStatus < 0.6 ? Color.yellow : Color.green);
     statusBar.draw(
         statusBar.getWidth() * healthStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         statusBar.getWidth() * healthStatus,
         0,
         statusBar.getWidth(),
         statusBar.getHeight(),
         new Color(0.15f, 0.15f, 0.15f));
     g.setDrawMode(Graphics.MODE_NORMAL);
     g.rotate(0, 0, 90);
   }
   g.translate(-35, -container.getHeight() + 45);
 }
  @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();
      }
    }
  }
  @Override
  protected void processEntities(ImmutableBag<Entity> entities) {
    ensurePlayerEntity();

    if (player != null) {
      hudBg.draw(
          0, container.getHeight() - hudBg.getHeight(), container.getWidth(), hudBg.getHeight());

      renderHealth();
      renderAmmo();
    }

    renderMinimap();
  }
  @Override
  public void initResources() {

    final int MARGIN = 30;
    int x = container.getWidth();
    int y = container.getHeight();
    Image tmp = ResourceManager.getImage("butRetour");

    int larg = tmp.getWidth();
    int haut = tmp.getHeight();
    int yBut = y - haut - MARGIN;

    shapeListeServers = new Rectangle(MARGIN, 50, x / 2 - MARGIN - 10, yBut - 50);

    listeServers =
        new ListeDeroulante(
            container,
            ResourceManager.getImage("transparent"),
            (int) shapeListeServers.getX() + 5,
            (int) shapeListeServers.getY() + 5);
    listeServers.setScrolled(true);
    listeServers.setMaxElementsToDraw((int) shapeListeServers.getHeight() / 20);

    butRetour =
        new MouseOverArea(
            container, ResourceManager.getImage("butRetour"), MARGIN, yBut, larg, haut);
    butRetour.setMouseOverImage(ResourceManager.getImage("butRetourOver"));

    butCreerServer =
        new MouseOverArea(container, tmp, tmp.getWidth() + MARGIN * 2, yBut, larg, haut);
    butCreerServer.setMouseOverImage(ResourceManager.getImage("MenuJouerOver"));

    timerRefreshServers = new Timer(7000);
  }
Exemple #7
0
  public Lightning(float x, float y, String i, World world) {
    super(x, y, i, world);

    int numFrames = 4;
    Image sheet;
    try {
      sheet = new Image("assets/Art/Transformations/Animations/lightning.png");
      projectileWidth = sheet.getWidth() / numFrames;
      projectileHeight = sheet.getHeight();
      SpriteSheet ss = new SpriteSheet(sheet, projectileWidth, projectileHeight);
      projectileRightAnimation = new Animation(ss, 100);
      projectileRightAnimation.stopAt(projectileRightAnimation.getFrameCount() - 1);
      ss = new SpriteSheet(ss.getFlippedCopy(true, false), projectileWidth, projectileHeight);
      projectileLeftAnimation = new Animation(ss, 100);
      projectileLeftAnimation.stopAt(projectileLeftAnimation.getFrameCount() - 1);
    } catch (SlickException e) {
      e.printStackTrace();
    }

    damage = 3;
    projectileRange = 600;
    projectileXVelocity = 3;
    dropChance = false;
    startUpTime = .01;
    reloadTime = 800;
    projectileOffsets = new Rectangle(10, 10, 20, 20);
  }
  @Override
  public void render(GameContainer gc, StateBasedGame sb, Graphics g) throws SlickException {
    // Background etc.
    g.setAntiAlias(true);
    g.drawImage(
        background,
        gc.getWidth() / 2 - background.getWidth() / 2,
        gc.getHeight() / 2 - background.getHeight() / 2);
    uniTitle.drawString(
        gc.getWidth() / 2 - uniTitle.getWidth("Highscores") / 2,
        (float) 0,
        "Highscores",
        Color.orange);

    count = 0;

    // Zeichnet die Überschrift
    MenuItem item = levelNames.get(0);
    uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor());
    item = playerNames.get(0);
    uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor());
    item = times.get(0);
    uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor());

    // Von start bis zu end
    for (int i = start; i <= end; i++) {
      // Falls wir am ende der Liste angekommen sind, abbrechen und itemsOnSide setzen
      if (i == levelNames.size()) {
        itemsOnSide = i - start;
        break;
      }
      // Maximale itemsOnSide = 10
      else {
        itemsOnSide = 10;
      }

      // Zeichnen der Highscores
      item = levelNames.get(i);
      uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor());
      item = playerNames.get(i);
      uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor());
      item = times.get(i);
      uniNormal.drawString(item.getPos().x, item.getPos().y, item.getName(), item.getColor());
    }

    g.setColor(Color.green);
    g.draw(selection);

    // aktuelle Seite zeichnen
    String displayside = "Seite " + (side + 1) + " von " + sideCount;
    uniNormal.drawString(
        gc.getWidth() / 2 - uniNormal.getWidth(displayside) / 2,
        gc.getHeight() - uniNormal.getHeight(displayside),
        displayside,
        Color.orange);

    // ESC String
    uniNormal.drawString(
        0, gc.getHeight() - uniNormal.getHeight("ESC = Zurück"), "ESC = Zurück", Color.orange);
  }
Exemple #9
0
 public Rock(Image image, float x, float y, int id) {
   this.image = image;
   this.x = x;
   this.y = y;
   this.height = image.getHeight();
   this.width = image.getWidth();
   this.id = id;
 }
Exemple #10
0
  public TexturedQuad(Image img, Orientation orientation, int angle) {
    this.img = img;
    this.flip = orientation == Orientation.LEFT;
    this.angle = angle;

    centerX = img.getWidth() / 2;
    centerY = img.getHeight() / 2;
  }
Exemple #11
0
 public Enemy(Image image, Vector2f location) {
   this.image = image;
   loc = location;
   collisionRect = new Rectangle(0, 0, image.getWidth(), image.getHeight());
   collisionRect.setCenterX(loc.x);
   collisionRect.setCenterY(loc.y);
   isDead = false;
 }
Exemple #12
0
 public Button(Image button, int x, int y, int images) {
   int imageHeight = button.getHeight() / images;
   Image btn = button.getSubImage(0, 0, button.getWidth(), imageHeight);
   Image hover = button.getSubImage(0, imageHeight, button.getWidth(), imageHeight);
   Image click = button.getSubImage(0, imageHeight * 2, button.getWidth(), imageHeight);
   Image disabled = button.getSubImage(0, imageHeight * 3, button.getWidth(), imageHeight);
   constructorHack(
       null, btn, hover, click, disabled, new Rectangle(x, y, button.getWidth(), imageHeight));
 }
  @Override
  public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
    // Images
    backgroundImage = Global.setImage("papyrus_page.png");
    backgroundImage.rotate(90);
    mapImage = Global.setImage("scroll_background_page_horizontal.png");
    mapLvlDefaultImage = Global.setImage("bloque_niveau.png");
    mapLvlUnlockedImage = Global.setImage("debut_niveau.png");
    mapLvlUnlockedFinishedImage = Global.setImage("fin_niveau.png");
    mapLvlFinishedImage = Global.setImage("fin_niveau.png");

    // Labels
    newGameImage = Global.setImage("main_menu_nouvelle_partie.png");
    newGameImage =
        newGameImage.getScaledCopy(
            (int) (newGameImage.getWidth() * SCALE_DOWN_W), newGameImage.getHeight());

    loadGameImage = Global.setImage("main_menu_charger_partie.png");
    loadGameImage =
        loadGameImage.getScaledCopy(
            (int) (loadGameImage.getWidth() * SCALE_DOWN_W), loadGameImage.getHeight());

    if (optionsActivated) {
      optionsImage = Global.setImage("main_menu_options.png");
      optionsImage =
          optionsImage.getScaledCopy(
              (int) (optionsImage.getWidth() * SCALE_DOWN_W), optionsImage.getHeight());
    }

    titleImage = Global.setImage("main_menu_title.png");
    titleImage =
        titleImage.getScaledCopy(
            (int) (titleImage.getWidth() * SCALE_DOWN_W * 1.5), titleImage.getHeight());

    display = new Display(gc);
    Image labelImage = Global.setImage(Global.BUTTON_STANDARD_IMAGE);
    Image playerImage = labelImage.getScaledCopy(150, 25);
    mapErrorLabel = new Label(playerImage, "");
    mapErrorLabel.setForeground(Color.red);
    mapErrorLabel.setBounds(800 - ERROR_X - ERROR_W, ERROR_Y, ERROR_W, ERROR_H);
    mapErrorLabel.pack();
    this.display.add(mapErrorLabel);
    mapErrorLabel.setImage(null);
  }
Exemple #14
0
 public EarthProjectile(float xSpawnLocation, float ySpawnLocation, Item item, World world) {
   super(xSpawnLocation, ySpawnLocation, item, world);
   xCenterOfRotation = owner.getHitbox().getCenterX();
   yCenterOfRotation = owner.getHitbox().getCenterY();
   angle = 90; // PI/2
   imageRight = item.projectileRightImage;
   imageLeft = item.projectileLeftImage;
   radius = 84 + imageRight.getHeight() / 2;
   spinAngularVelocity = 15;
 }
Exemple #15
0
 public Player(
     World world,
     float x,
     float y,
     float mass,
     String name,
     SoundWrapper soundWrapper,
     Image image) {
   super(world, x, y, image.getWidth(), image.getHeight(), mass, name, soundWrapper);
   setImage(image);
 }
  @Override
  public void render(GameContainer container, Graphics g) throws SlickException {
    sheet1.startUse();

    sheet1.renderInUse(50, 50, 0, 0);
    sheet1.renderInUse(100, 50, 1, 2);
    sheet1.renderInUse(150, 50, 64, 64, 1, 2);
    sheet1.renderInUse(250, 50, 64, 64, rot1, 1, 2); // rotates around top left
    sheet1.renderInUse(350, 50, 64, 64, rot2, 3, 2); // rotates around top middle
    sheet1.renderInUse(450, 50, rot1, 4, 4); // default; rotates around center

    sheet1.renderInUse(250, 50, 64, 64, rot1, 1, 2);

    sheet1.endUse();

    sheet2.startUse();
    subImage.drawEmbedded(100, 200, subImage.getWidth(), subImage.getHeight(), rot1);
    subImage.drawEmbedded(300, 200, subImage.getWidth() * 4f, subImage.getHeight() * 2f, rot2);
    sheet2.endUse();
  }
Exemple #17
0
  @Override
  public void init(GameContainer container, StateBasedGame game) throws SlickException {
    this.container = container;
    this.game = game;
    this.input = container.getInput();

    // initialize buttons
    Image button = GameImage.MENU_BUTTON_MID.getImage();
    button = button.getScaledCopy(container.getWidth() / 2, button.getHeight());
    Image buttonL = GameImage.MENU_BUTTON_LEFT.getImage();
    Image buttonR = GameImage.MENU_BUTTON_RIGHT.getImage();
    for (MenuState ms : MenuState.values()) ms.init(container, game, button, buttonL, buttonR);
  }
Exemple #18
0
 public Button(
     Image button, Image buttonHover, Image buttonClick, Image buttonDisabled, int x, int y) {
   if (button == null) {
     throw new IllegalArgumentException("Button image cannot be null.");
   }
   constructorHack(
       null,
       button,
       buttonHover,
       buttonClick,
       buttonDisabled,
       new Rectangle(x, y, button.getWidth(), button.getHeight()));
 }
Exemple #19
0
    /**
     * 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()), Utils.FONT_XLARGE, Color.white);
        b.setHoverFade();
        menuButtons[i] = b;
      }
    }
 /**
  * Indicates whether the game is over or not. If the game is over it draws a message showing which
  * player has won.
  *
  * @return Whether the game is over or not.
  * @throws SlickException
  */
 private boolean gameOver(StateBasedGame sbg, GameContainer gc) throws SlickException {
   if (!gameOver) {
     return false;
   } else {
     if (player1.getLives() <= 0) {
       sbg.enterState(Main.GAMEOVERSTATE);
     } else { // Draws a message saying player1 has won.
       Image gameOverMessage = new Image("data/player1_win.png");
       gameOverMessage.draw(
           windowSizeX / 2 - gameOverMessage.getWidth() / 2,
           windowSizeY / 2 - gameOverMessage.getHeight() / 2);
     }
   }
   return true;
 }
Exemple #21
0
 public void render(Graphics g) {
   // render all except entities
   for (int l = 0; l < map.getLayerCount(); l++) {
     String value = map.getLayerProperty(l, "type", null);
     if (value == null || !value.equalsIgnoreCase("entity")) {
       for (int w = 0; w < map.getWidth(); w++) {
         for (int h = 0; h < map.getHeight(); h++) {
           Image img = map.getTileImage(w, h, l).getScaledCopy(4);
           if (img != null) {
             g.drawImage(img, w * img.getWidth(), h * img.getHeight());
           }
         }
       }
     }
   }
 }
  private void renderMinimap() {
    int minimapWidth = minimapBg.getWidth();
    int minimapHeight = minimapBg.getHeight();

    int boundaryWidth = boundarySystem.getBoundaryWidth();
    int boundaryHeight = boundarySystem.getBoundaryHeight();

    float scaleX = (float) minimapWidth / (float) boundaryWidth;
    float scaleY = (float) minimapHeight / (float) boundaryHeight;

    g.setColor(Color.white);

    g.translate(container.getWidth() - minimapWidth - 20, 20);
    {
      minimapBg.draw();

      float offsetX = cameraSystem.getStartX();
      float offsetY = cameraSystem.getStartY();
      g.drawRect(
          offsetX * scaleX,
          offsetY * scaleY,
          scaleX * cameraSystem.getWidth(),
          scaleY * cameraSystem.getHeight());

      ImmutableBag<Entity> entities = world.getManager(GroupManager.class).getEntities("crates");
      for (int i = 0; entities.size() > i; i++) {
        Entity crate = entities.get(i);
        Physics cratePhysics = physicsMapper.get(crate);
        float crateX = cratePhysics.getX() * scaleX;
        float crateY = cratePhysics.getY() * scaleY;
        g.fillRect(crateX - 1, crateY - 1, 2, 2);
      }

      ImmutableBag<Entity> tanks = world.getManager(GroupManager.class).getEntities("tanks");
      for (int i = 0; tanks.size() > i; i++) {
        Entity t = tanks.get(i);
        String tp = world.getManager(PlayerManager.class).getPlayer(t);
        Physics physics = physicsMapper.get(t);
        g.setColor(Color.green);
        float tx = physics.getX() * scaleX;
        float ty = physics.getY() * scaleY;
        g.fillRect(tx - 3, ty - 3, 6, 6);
      }
    }
    g.translate(-container.getWidth() + minimapWidth + 20, -20);
  }
  @Override
  public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
    g.setColor(Color.black);

    // Top part
    backgroundImage.draw(
        -backgroundImage.getWidth() / 8, -backgroundImage.getHeight() / 8, 300, 800);
    titleImage.draw(TITLE_X, TITLE_Y);
    newGameImage.draw(NEWGAME_X, NEWGAME_Y);
    loadGameImage.draw(LOADGAME_X, LOADGAME_Y);
    if (MainMenuGameState.optionsActivated) {
      optionsImage.draw(OPTIONS_X, OPTIONS_Y);
    }

    // Map part
    mapImage.draw(MAP_X, MAP_Y, 800 - 2 * MAP_X, 600 - MAP_Y);
    Save s = Save.getInstance();
    if (s.hasSaveLoaded()) {
      int[] ids = s.getAllIds();
      for (int i = 0; i < ids.length; i++) {
        int[] mapLvl = s.mapPointForLevelID(ids[i]);
        if (mapLvl != null) {
          switch (s.getFinishedStateForLevelID(ids[i])) {
            case 0:
              mapLvlDefaultImage.draw(MAP_X + mapLvl[0], MAP_Y + mapLvl[1], mapLvl[2], mapLvl[3]);
              break;
            case 1:
              mapLvlUnlockedImage.draw(MAP_X + mapLvl[0], MAP_Y + mapLvl[1], mapLvl[2], mapLvl[3]);
              break;
            case 2:
              mapLvlFinishedImage.draw(MAP_X + mapLvl[0], MAP_Y + mapLvl[1], mapLvl[2], mapLvl[3]);
              break;
            case 3:
              mapLvlUnlockedFinishedImage.draw(
                  MAP_X + mapLvl[0], MAP_Y + mapLvl[1], mapLvl[2], mapLvl[3]);
              break;
            default:
              break;
          }
        }
      }
    }

    display.render(gc, g);
  }
  public void update() {

    W = defaultTexture.getWidth();
    H = defaultTexture.getHeight();

    hitbox.setBounds((int) X, (int) Y, W, H);
    topHitbox.setBounds((int) X, (int) Y, W, H / 3);
    middleHitbox.setBounds((int) X, (int) Y + (H / 3), W, H / 2);
    bottomHitbox.setBounds((int) X, (int) Y + H - bottomHitbox.height, W, H / 5);

    gravity();

    if (gui.GameScreen.rightMouseDown == true
        && hitbox.intersects(Mouse.getX(), 600 - Mouse.getY(), 1, 1)
        && ObjectList.player.range.intersects(hitbox)) {
      activate();
    }
  }
  private void drawLight(Entity entity, int lightSize, int x, int y) {
    Graphics g = container.getGraphics();
    ResourceManager manager = ResourceManager.getInstance();
    String resName = resourceMapper.get(entity).getResourceName();
    Resource res = manager.getResource(resName);
    Image entityFrame = getFrame(res);
    int ew = entityFrame.getWidth();
    int eh = entityFrame.getHeight();

    float invSize = 1f / lightSize;
    g.clearAlphaMap();
    g.scale(lightSize, lightSize);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    Image light = (Image) manager.getResource("light").getObject();
    light.drawCentered((x) * invSize, (y) * invSize);
    g.scale(invSize, invSize);
    GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_DST_ALPHA);
    g.setColor(new Color(0, 0, 0, 255));
    g.fillRect(0, 0, container.getWidth(), container.getHeight());
    g.setDrawMode(Graphics.MODE_NORMAL);
  }
  public void render(GUIContext ctx, Graphics g, Component comp, Skin skin, Theme theme) {
    // makes sure it's the same as what we're attached to
    checkComponent(comp);

    CheckBox check = (CheckBox) comp;
    Rectangle cachedRect = null;
    boolean roundRectEnabled = SimpleSkin.isRoundRectanglesEnabled();

    // make sure we are showing outline
    // also, the outline will only render if we aren't rendering a background
    if (isShowOutline() && (!check.isOpaque() || check.getBackground() == null)) {
      // get the cached rectangle from the component bounds
      cachedRect = check.getAbsoluteBounds();
      Rectangle bounds = cachedRect;

      // if we have round rectangles, use them
      if (roundRectEnabled && roundBounds != null) {
        roundBounds.setBounds(bounds);
        bounds = roundBounds;
      }

      Color oldCol = g.getColor();
      boolean oldAA = g.isAntiAlias();
      Color back;

      if (check.getState() != Button.UP) // hover
      back = theme.getPrimary1();
      else // still
      back = theme.getPrimary3();

      g.setColor(back);
      g.setAntiAlias(true);
      g.fill(bounds);

      g.setAntiAlias(oldAA);
      g.setColor(oldCol);
    }

    // renders base
    SkinUtil.renderComponentBase(g, check);

    // renders text/image
    SkinUtil.renderCheckBoxBase(g, check);

    // get cached bounds from the "check" box button area
    Rectangle cachedBox = check.getAbsoluteBoxBounds();
    Rectangle btnRect = cachedBox;

    // try to use round rectangle
    if (roundRectEnabled && roundBoxBounds != null) {
      roundBoxBounds.setBounds(cachedBox);
      btnRect = roundBoxBounds;
    }

    // renders the actual button state for the small box area, using rounded edges
    SimpleButtonAppearance.renderButtonState(g, theme, check, btnRect, grad);

    Image def = getDefaultImage();
    if (def != null && check.isSelected()) {
      float x = btnRect.getX() + (btnRect.getWidth() / 2f - def.getWidth() / 2f);
      float y = btnRect.getY() + (btnRect.getHeight() / 2f - def.getHeight() / 2f);
      g.drawImage(def, (int) x, (int) y, check.getImageFilter());
    }
  }
Exemple #27
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
  protected void processEntities(ImmutableBag<Entity> entities) {
    Graphics g = container.getGraphics();
    ResourceManager manager = ResourceManager.getInstance();
    ImmutableBag<Entity> players = world.getGroupManager().getEntities("PLAYER");
    ImmutableBag<Entity> enemies = world.getGroupManager().getEntities("ENEMY");
    ImmutableBag<Entity> maps = world.getGroupManager().getEntities("MAP");
    ImmutableBag<Entity> trinkets = world.getGroupManager().getEntities("TRINKET");
    ImmutableBag<Entity> enemyDeaths = world.getGroupManager().getEntities("ENEMY_DEATH");

    Entity player = players.get(0);
    Location playerLocation = locationMapper.get(player);
    Vector2f playerPosition = playerLocation.getPosition();
    String playerResName = resourceMapper.get(player).getResourceName();
    Resource playerRes = manager.getResource(playerResName);
    Image playerFrame = getFrame(playerRes);
    int mapX = (int) playerPosition.x * -1 + container.getWidth() / 2 - playerFrame.getWidth() / 2;
    int mapY =
        (int) playerPosition.y * -1 + container.getHeight() / 2 - playerFrame.getHeight() / 2;
    String mapResName = resourceMapper.get(maps.get(0)).getResourceName();
    Resource mapRes = manager.getResource(mapResName);
    TiledMap tiledMap = (TiledMap) mapRes.getObject();

    // Draw the ground
    tiledMap.render(mapX, mapY, 0);

    // Draw the background
    tiledMap.render(mapX, mapY, 1);

    // Draw trinkets on map
    for (int i = 0; i < trinkets.size(); i++) {
      Entity trinket = trinkets.get(i);
      Location trinketLocation = locationMapper.get(trinket);
      Vector2f trinketPosition = trinketLocation.getPosition();

      if (trinketLocation.getMap().equals(playerLocation.getMap())) {
        String trinketResName = resourceMapper.get(trinket).getResourceName();
        Resource trinketRes = manager.getResource(trinketResName);
        Image trinketImage = (Image) trinketRes.getObject();

        int trinketX = mapX + (int) trinketPosition.x;
        int trinketY = mapY + (int) trinketPosition.y;
        trinketImage.draw(trinketX, trinketY);
      }
    }

    // Draw the player
    int playerCenterX = container.getWidth() / 2 - playerFrame.getWidth() / 2;
    int playerCenterY = container.getHeight() / 2 - playerFrame.getHeight() / 2;
    drawCreatureEntity(player, playerCenterX, playerCenterY);

    // Player Health Bar
    Stats stats = statsMapper.get(player);
    HashMap<StatType, Integer> playerStats = stats.getStats();
    int health = playerStats.get(StatType.HEALTH);

    if (health <= 0) {
      game.enterState(MenuState.ID);
    }

    int maxHealth = playerStats.get(StatType.MAX_HEALTH);
    int armor = playerStats.get(StatType.ARMOR);

    // Secondary cooldown time bar
    long secondaryCooldown = secondaryMapper.get(player).getTime();
    long currentSecondaryCooldown =
        new Date().getTime() - secondaryMapper.get(player).getLastTime();

    float secondaryBarWidth = longestBarWidth * (2.0f / 3.0f);
    float secondaryPer = (float) currentSecondaryCooldown / (float) secondaryCooldown;
    if (secondaryPer <= 1) {
      g.setColor(Color.black);
      g.fillRect(
          container.getWidth() / 2 - secondaryBarWidth / 2 - 1,
          container.getHeight() / 2 + playerFrame.getHeight() / 2 + barHeight + barSpacing,
          secondaryBarWidth + 2,
          barHeight);
      g.setColor(new Color(255, 127, 0));
      g.fillRect(
          container.getWidth() / 2 - secondaryBarWidth / 2,
          container.getHeight() / 2 + playerFrame.getHeight() / 2 + barHeight + barSpacing + 1,
          secondaryBarWidth * secondaryPer,
          barHeight - 2);
    }

    // Attack cooldown time bar
    long attackCooldown = attackMapper.get(player).getTime();
    long currentAttackCooldown = new Date().getTime() - attackMapper.get(player).getLastTime();

    float attackBarWidth = longestBarWidth / 3;
    float attackPer = (float) currentAttackCooldown / (float) attackCooldown;
    if (attackPer <= 1) {
      g.setColor(Color.black);
      g.fillRect(
          container.getWidth() / 2 - attackBarWidth / 2 - 1,
          container.getHeight() / 2 + playerFrame.getHeight() / 2 + barHeight * 2 + barSpacing * 2,
          attackBarWidth + 2,
          barHeight);
      g.setColor(new Color(255, 255, 0));
      g.fillRect(
          container.getWidth() / 2 - attackBarWidth / 2,
          container.getHeight() / 2
              + playerFrame.getHeight() / 2
              + barHeight * 2
              + barSpacing * 2
              + 1,
          attackBarWidth * attackPer,
          barHeight - 2);
    }

    // Draw enemies
    for (int i = 0; i < enemies.size(); i++) {
      Entity enemy = enemies.get(i);
      Location enemyLocation = locationMapper.get(enemy);
      if (enemyLocation.getMap().equals(playerLocation.getMap())) {
        Vector2f enemyPosition = enemyLocation.getPosition();
        int enemyX = mapX + (int) enemyPosition.x;
        int enemyY = mapY + (int) enemyPosition.y;
        drawCreatureEntity(enemy, enemyX, enemyY);
      }
    }

    // Draw enemy deaths
    for (int i = 0; i < enemyDeaths.size(); i++) {
      Entity enemyDeath = enemyDeaths.get(i);
      Location enemyDeathLocation = locationMapper.get(enemyDeath);
      Vector2f enemyDeathPosition = enemyDeathLocation.getPosition();
      int enemyDeathX = mapX + (int) enemyDeathPosition.x;
      int enemyDeathY = mapY + (int) enemyDeathPosition.y;
      ParticleComponent particleComponent = particleComponentMapper.get(enemyDeath);
      particleComponent.updateParticleSystem(world.getDelta());
      particleComponent.renderParticleSystem(enemyDeathX, enemyDeathY);
    }

    // Draw the foreground
    tiledMap.render(mapX, mapY, 2);

    // Draw the collision layer
    // tiledMap.render(mapX, mapY, 3);

    // If lighting is turned on
    int lightSize = Integer.valueOf(tiledMap.getMapProperty("LightSize", "-1"));
    if (lightSize != -1) {
      // Draw the player light
      drawLight(player, lightSize, container.getWidth() / 2, container.getHeight() / 2);
    }

    // Draw Upper Left UI
    float bigBarWidth = 200;
    float bigBarHeight = 17;
    if (health < 0) health = 0;
    float healthPer = (float) (health) / (float) maxHealth;
    if (healthPer < 0) healthPer = 0;
    // float armorPer = (float)(armor) / (float)maxHealth;
    Image healthIconImage = (Image) manager.getResource("healthicon").getObject();

    // Upper left health icon

    g.drawImage(healthIconImage, 5, 6);
    // Upper left bar
    g.setColor(new Color(50, 50, 50, 125));
    g.fillRect(healthIconImage.getWidth() + 8, 5, bigBarWidth + 2, bigBarHeight + 2);
    g.setColor(new Color(255, 0, 0, 150));
    g.fillRect(healthIconImage.getWidth() + 9, 6, bigBarWidth * healthPer, bigBarHeight);
    /*g.setColor(new Color(0,0,255,100));
    g.fillRect(bigBarWidth*healthPer+6, 4, bigBarWidth*armorPer, bigBarHeight);*/

    Image armorIconImage = (Image) manager.getResource("armoricon").getObject();
    g.drawImage(armorIconImage, 5, healthIconImage.getHeight() + 8);

    g.setColor(Color.white);
    int healthTextWidth = g.getFont().getWidth(health + "/" + maxHealth);
    g.drawString(
        health + "/" + maxHealth,
        7 + bigBarWidth / 2 - healthTextWidth / 2 + healthIconImage.getWidth(),
        5);
    // g.drawString(String.valueOf(armor), armorIconImage.getWidth() + 5,
    // healthIconImage.getHeight() + 3);

    // Polymorph Trinket UI
    int nPolymorph = 0;
    for (int i = 0; i < trinkets.size(); i++) {
      Entity trinket = trinkets.get(i);
      if (polymorphMapper.get(trinket) != null) {
        Polymorph polymorph = polymorphMapper.get(trinket);
        ResourceRef trinketRef = resourceMapper.get(trinket);
        if (polymorph.existsOnPlayer()) {
          Image polymorphImage =
              (Image) manager.getResource(trinketRef.getResourceName()).getObject();
          int selWidth = 32, selHeight = 32;
          int notSelWidth = 32, notSelHeight = 32;

          if (polymorph.isActive()) {
            // playerRes.setResourceName(polymorph.getPolymorphRef());
            // activePolymorphTrinket = true;
            int x = container.getWidth() / 2 - selWidth / 2 + nPolymorph * selWidth;
            int y = container.getHeight() - selHeight;
            // g.drawImage(polymorphImage, x-4, y-4, x+selWidth+4, y+selHeight+4, 0, 0,
            // polymorphImage.getWidth(), polymorphImage.getHeight(), Color.green);
            g.drawImage(
                polymorphImage,
                x,
                y,
                x + selWidth,
                y + selHeight,
                0,
                0,
                polymorphImage.getWidth(),
                polymorphImage.getHeight(),
                Color.white);

            // g.drawRect(x-2, y-2, width-2, height-2);

          } else {
            int x = container.getWidth() / 2 - notSelWidth / 2 + nPolymorph * selWidth;
            int y = container.getHeight() - notSelHeight;
            g.drawImage(
                polymorphImage,
                x,
                y,
                x + notSelWidth,
                y + notSelHeight,
                0,
                0,
                polymorphImage.getWidth(),
                polymorphImage.getHeight(),
                Color.gray);
          }

          nPolymorph += 1;
        }
      }
    }
  }
Exemple #29
0
 public CollideMask(Image i) {
   System.out.println("BitMaskImage.createMask() from image : " + i);
   X_SIZE = i.getWidth();
   Y_SIZE = i.getHeight();
   createMask(i);
 }
  private void drawCreatureEntity(Entity entity, int x, int y) {
    Graphics g = container.getGraphics();
    ResourceManager manager = ResourceManager.getInstance();
    Movement movement = movementMapper.get(entity);
    String resName = resourceMapper.get(entity).getResourceName();
    Resource res = manager.getResource(resName);
    Image entityFrame = getFrame(res);

    switch (res.getType()) {
      case CREATURE_ANIMATION:
        CreatureAnimation entityAnim = (CreatureAnimation) res.getObject();
        Direction direction = directionMapper.get(entity);
        entityAnim.setIdle();
        Animation animation = null;

        switch (direction.getDirection()) {
          case UP:
          case UP_LEFT:
          case UP_RIGHT:
            if (movement.getCurrentSpeed() != 0) {
              animation = entityAnim.getMoveUp();
            } else {
              animation = entityAnim.getIdleUp();
            }
            break;
          case DOWN:
          case DOWN_RIGHT:
          case DOWN_LEFT:
            if (movement.getCurrentSpeed() != 0) {
              animation = entityAnim.getMoveDown();
            } else {
              animation = entityAnim.getIdleDown();
            }
            break;
          case LEFT:
            if (movement.getCurrentSpeed() != 0) {
              animation = entityAnim.getMoveLeft();
            } else {
              animation = entityAnim.getIdleLeft();
            }
            break;
          case RIGHT:
            if (movement.getCurrentSpeed() != 0) {
              animation = entityAnim.getMoveRight();
            } else {
              animation = entityAnim.getIdleRight();
            }
            break;
        }

        Color color = Color.white;
        if (colorChangeMapper.get(entity) != null) {
          ColorChange colorChange = colorChangeMapper.get(entity);
          if (new Date().getTime() - colorChange.getLastTime() > colorChange.getTime()) {
            entity.removeComponent(colorChange);
          } else {
            color = colorChange.getColor();
          }
        }
        g.drawAnimation(animation, x, y, color);
        break;
      case IMAGE:
        Image entityImg = (Image) res.getObject();
        g.drawImage(entityImg, x, y);
        break;
    }

    HashMap<StatType, Integer> stats = statsMapper.get(entity).getStats();
    int maxHealth = stats.get(StatType.MAX_HEALTH);
    int health = stats.get(StatType.HEALTH);
    float barWidth = longestBarWidth;
    float per = (float) health / (float) maxHealth;

    if (health > 0 && health != maxHealth) {
      g.setColor(new Color(0, 0, 0));
      g.fillRect(
          x + entityFrame.getWidth() / 2 - barWidth / 2 - 1,
          y + entityFrame.getHeight(),
          barWidth + 2,
          barHeight);
      g.setColor(new Color(255, 0, 0));
      g.fillRect(
          x + entityFrame.getWidth() / 2 - barWidth / 2,
          y + entityFrame.getHeight() + 1,
          barWidth * per,
          barHeight - 2);
    }
  }