Beispiel #1
0
  public void init() {
    setGame(this);
    int index = 0;
    for (int r = 0; r < 6; r++) {
      for (int g = 0; g < 6; g++) {
        for (int b = 0; b < 6; b++) {
          int rr = (r * 255 / 5);
          int gg = (g * 255 / 5);
          int bb = (b * 255 / 5);
          colours[index++] = rr << 16 | gg << 8 | bb;
        }
      }
    }

    screen = new Screen(WIDTH, HEIGHT, new SpriteSheet("/sprite_sheet.png"));
    input = new InputHandler(this);
    setMouse(new MouseHandler(this));
    setWindow(new WindowHandler(this));
    setMap("/levels/custom_level.png");
    setMap(1);

    game.setVendor(new Vendor(level, "Vendor", 215, 215, 304, 543));
    level.addEntity(getVendor());
  }
Beispiel #2
0
  public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      return;
    }

    int xOffset = (int) getPlayer().getX() - (screen.getWidth() / 2);
    int yOffset = (int) getPlayer().getY() - (screen.getHeight() / 2);

    level.renderTiles(screen, xOffset, yOffset);

    /*
     * for (int x = 0; x < level.width; x++) { int colour = Colours.get(-1,
     * -1, -1, 000); if (x % 10 == 0 && x != 0) { colour = Colours.get(-1,
     * -1, -1, 500); } Font.render((x % 10) + "", screen, 0 + (x * 8), 0,
     * colour, 1); }
     */

    level.renderEntities(screen);
    level.renderProjectileEntities(screen);

    for (int y = 0; y < screen.getHeight(); y++) {
      for (int x = 0; x < screen.getWidth(); x++) {
        int colourCode = screen.getPixels()[x + y * screen.getWidth()];
        if (colourCode < 255) {
          pixels[x + y * WIDTH] = colours[colourCode];
        }
      }
    }

    if (isChangeLevel() == true && getTickCount() % 60 == 0) {
      Game.setChangeLevel(true);
      setChangeLevel(false);
    }

    if (changeLevel == true) {
      print.print("Teleported into new world", PrintTypes.GAME);
      if (getMap() == 1) {
        setMap("/levels/water_level.png");
        if (getDummy() != null) { // Gave nullPointerException(); upon
          // entering new world.
          level.removeEntity(getDummy());
          setNpc(false);
        }
        level.removeEntity(getVendor());
        setMap(2);
      } else if (getMap() == 2) {
        setMap("/levels/custom_level.png");
        level.removeEntity(getDummy());
        setNpc(false);
        level.addEntity(getVendor());
        setMap(1);
      }
      changeLevel = false;
    }

    Graphics g = bs.getDrawGraphics();
    g.drawRect(0, 0, getWidth(), getHeight());
    g.drawImage(image, 0, 0, getWidth(), getHeight() - 30, null);
    status(g, isDevMode(), isClosing());
    // Font.render("Hi", screen, 0, 0, Colours.get(-1, -1, -1, 555), 1);
    g.drawImage(image2, 0, getHeight() - 30, getWidth(), getHeight(), null);
    g.setColor(Color.WHITE);
    g.setFont(font.getSegoe());
    g.drawString(
        "Welcome " + WordUtils.capitalizeFully(player.getSanitisedUsername()), 3, getHeight() - 17);
    g.setColor(Color.ORANGE);

    if (context.getLocale().getCountry().equals("BE")
        || context.getLocale().getCountry().equals("FR")) {
      g.drawString(
          "Press A to quit", (getWidth() / 2) - ("Press A to quit".length() * 3), getHeight() - 17);
    } else {
      g.drawString(
          "Press Q to quit", (getWidth() / 2) - ("Press Q to quit".length() * 3), getHeight() - 17);
    }
    g.setColor(Color.YELLOW);
    g.drawString(time.getTime(), (getWidth() - 58), (getHeight() - 3));
    g.setColor(Color.GREEN);
    if (backgroundMusic.getActive()) {
      g.drawString("MUSIC is ON ", 3, getHeight() - 3);
    }
    g.dispose();
    bs.show();
  }