示例#1
0
 public void handleInput() {
   if (Keys.isPressed(Keys.ESCAPE)) {
     JukeBox.stop("music1");
     gsm.setPaused(true);
   }
   if (blockInput) return;
   if (Keys.isDown(Keys.LEFT)) player.setLeft();
   if (Keys.isDown(Keys.RIGHT)) player.setRight();
   if (Keys.isDown(Keys.UP)) player.setUp();
   if (Keys.isDown(Keys.DOWN)) player.setDown();
   if (Keys.isPressed(Keys.SPACE)) player.setAction();
 }
示例#2
0
  public void init() {

    // create lists
    diamonds = new ArrayList<Diamond>();
    sparkles = new ArrayList<Sparkle>();
    items = new ArrayList<Item>();

    // load map
    tileMap = new TileMap(16);
    tileMap.loadTiles("/Tilesets/testtileset.gif");
    tileMap.loadMap("/Maps/testmap.map");

    // create player
    player = new Player(tileMap);

    // fill lists
    populateDiamonds();
    populateItems();

    // initialize player
    player.setTilePosition(17, 17);
    player.setTotalDiamonds(diamonds.size());

    // set up camera position
    sectorSize = GamePanel.WIDTH;
    xsector = player.getx() / sectorSize;
    ysector = player.gety() / sectorSize;
    tileMap.setPositionImmediately(-xsector * sectorSize, -ysector * sectorSize);

    // load hud
    hud = new Hud(player, diamonds);

    // load music
    JukeBox.load("/Music/bgmusic.mp3", "music1");
    JukeBox.setVolume("music1", -10);
    JukeBox.loop("music1", 1000, 1000, JukeBox.getFrames("music1") - 1000);
    JukeBox.load("/Music/finish.mp3", "finish");
    JukeBox.setVolume("finish", -10);

    // load sfx
    JukeBox.load("/SFX/collect.wav", "collect");
    JukeBox.load("/SFX/mapmove.wav", "mapmove");
    JukeBox.load("/SFX/tilechange.wav", "tilechange");
    JukeBox.load("/SFX/splash.wav", "splash");

    // start event
    boxes = new ArrayList<Rectangle>();
    eventStart = true;
    eventStart();
  }
示例#3
0
 private void eventFinish() {
   eventTick++;
   if (eventTick == 1) {
     boxes.clear();
     for (int i = 0; i < 9; i++) {
       if (i % 2 == 0) boxes.add(new Rectangle(-128, i * 16, GamePanel.WIDTH, 16));
       else boxes.add(new Rectangle(128, i * 16, GamePanel.WIDTH, 16));
     }
     JukeBox.stop("music1");
     JukeBox.play("finish");
   }
   if (eventTick > 1) {
     for (int i = 0; i < boxes.size(); i++) {
       Rectangle r = boxes.get(i);
       if (i % 2 == 0) {
         if (r.x < 0) r.x += 4;
       } else {
         if (r.x > 0) r.x -= 4;
       }
     }
   }
   if (eventTick > 33) {
     if (!JukeBox.isPlaying("finish")) {
       Data.setTime(player.getTicks());
       gsm.setState(GameStateManager.GAMEOVER);
     }
   }
 }
示例#4
0
  public void draw(Graphics2D g) {

    // draw tilemap
    tileMap.draw(g);

    // draw player
    player.draw(g);

    // draw diamonds
    for (Diamond d : diamonds) {
      d.draw(g);
    }

    // draw sparkles
    for (Sparkle s : sparkles) {
      s.draw(g);
    }

    // draw items
    for (Item i : items) {
      i.draw(g);
    }

    // draw hud
    hud.draw(g);

    // draw transition boxes
    g.setColor(java.awt.Color.BLACK);
    for (int i = 0; i < boxes.size(); i++) {
      g.fill(boxes.get(i));
    }
  }
示例#5
0
  public void update() {

    // check keys
    handleInput();

    // check events
    if (eventStart) eventStart();
    if (eventFinish) eventFinish();

    if (player.numDiamonds() == player.getTotalDiamonds()) {
      eventFinish = blockInput = true;
    }

    // update camera
    int oldxs = xsector;
    int oldys = ysector;
    xsector = player.getx() / sectorSize;
    ysector = player.gety() / sectorSize;
    tileMap.setPosition(-xsector * sectorSize, -ysector * sectorSize);
    tileMap.update();

    if (oldxs != xsector || oldys != ysector) {
      JukeBox.play("mapmove");
    }

    if (tileMap.isMoving()) return;

    // update player
    player.update();

    // update diamonds
    for (int i = 0; i < diamonds.size(); i++) {

      Diamond d = diamonds.get(i);
      d.update();

      // player collects diamond
      if (player.intersects(d)) {

        // remove from list
        diamonds.remove(i);
        i--;

        // increment amount of collected diamonds
        player.collectedDiamond();

        // play collect sound
        JukeBox.play("collect");

        // add new sparkle
        Sparkle s = new Sparkle(tileMap);
        s.setPosition(d.getx(), d.gety());
        sparkles.add(s);

        // make any changes to tile map
        ArrayList<int[]> ali = d.getChanges();
        for (int[] j : ali) {
          tileMap.setTile(j[0], j[1], j[2]);
        }
        if (ali.size() != 0) {
          JukeBox.play("tilechange");
        }
      }
    }

    // update sparkles
    for (int i = 0; i < sparkles.size(); i++) {
      Sparkle s = sparkles.get(i);
      s.update();
      if (s.shouldRemove()) {
        sparkles.remove(i);
        i--;
      }
    }

    // update items
    for (int i = 0; i < items.size(); i++) {
      Item item = items.get(i);
      if (player.intersects(item)) {
        items.remove(i);
        i--;
        item.collected(player);
        JukeBox.play("collect");
        Sparkle s = new Sparkle(tileMap);
        s.setPosition(item.getx(), item.gety());
        sparkles.add(s);
      }
    }
  }