Beispiel #1
1
  @Override
  public void update(GameContainer container, int delta) throws SlickException {
    Projectile proj;
    playerNextPos = inputHandler.playerInput(player, container.getInput(), delta, sound);
    entity.update(delta, sound);
    if (!isBlocked(playerNextPos, player.getWidth(), player.getHeight())) {
      player.setCoord(playerNextPos);
    }

    player.logic();

    for (int i = 0; i < projectiles.size(); i++) {
      proj = projectiles.get(i);
      proj.update(delta);
      if (isBlocked(proj.pos, proj.getWidth(), proj.getHeight())) {
        projectiles.remove(i);
        sound.playSound(collisionSound);
      } else if (proj.collidesWith(entity) && proj.getOwner() == player) {
        proj.damage(entity);
        projectiles.remove(i);
      } else if (proj.collidesWith(player) && proj.getOwner() == entity) {
        proj.damage(player);
        projectiles.remove(i);
      }
    }
  }
Beispiel #2
0
  @Override
  public void init(GameContainer container) throws SlickException {
    try {
      worldMusic = sound.addSoundToMap("World", "res/Sound/World.wav", sid.getMusicID(0));
      playerAttackSound = sound.addSoundToMap("Attack", "res/Sound/Shoot.wav", sid.getAttackID(0));
      bossAttackSound =
          sound.addSoundToMap("Attack", "res/Sound/Boss_attack.wav", sid.getAttackID(1));
      collisionSound =
          sound.addSoundToMap("Collision", "res/Sound/Collide.wav", sid.getEffectID(0));

    } catch (MalformedURLException e1) {
      e1.printStackTrace();
    }
    sound.loopSound(worldMusic);

    Image[] movementUp = {
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png"),
      new Image("res/Character1_back.png")
    };

    Image[] movementDown = {
      new Image("res/Character1_frontanimation-frame-1.png"),
      new Image("res/Character1_frontanimation-frame-2.png"),
      new Image("res/Character1_frontanimation-frame-3.png"),
      new Image("res/Character1_frontanimation-frame-4.png"),
      new Image("res/Character1_frontanimation-frame-5.png"),
      new Image("res/Character1_frontanimation-frame-6.png"),
      new Image("res/Character1_frontanimation-frame-7.png"),
      new Image("res/Character1_frontanimation-frame-8.png")
    };

    Image[] movementRight = {
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png"),
      new Image("res/Character1_right.png")
    };

    Image[] movementLeft = {
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png"),
      new Image("res/Character1_left.png")
    };

    int duration[] = {100, 100, 100, 100, 100, 100, 100, 100};
    up = new Animation(movementUp, duration, false);
    down = new Animation(movementDown, duration, false);
    left = new Animation(movementLeft, duration, false);
    right = new Animation(movementRight, duration, false);
    Animation[] animList = {up, down, left, right};
    Animation[] bossAnim = {up.copy(), down.copy(), left.copy(), right.copy()};
    player = new Player(new Vector2d(10 * SIZE, 10 * SIZE), animList);
    player.setAttackSound(playerAttackSound);
    entity = new Boss(new Vector2d(25 * SIZE, 25 * SIZE), bossAnim, player);
    entity.setProjectileList(projectiles);
    entity.setAttackSound(bossAttackSound);
    player.setCurrentBoss(entity);

    tileMap = new TiledMap("res/tilemap.tmx");
    blocked = new boolean[tileMap.getWidth()][tileMap.getHeight()];
    try {
      this.initAbilities();
    } catch (IOException e) {
      e.printStackTrace();
    }
    for (int x = 0; x < tileMap.getWidth(); x++) {
      for (int y = 0; y < tileMap.getHeight(); y++) {
        int ID = tileMap.getTileId(x, y, 0);
        String value = tileMap.getTileProperty(ID, "blocked", "false");
        if ("true".equals(value)) {
          blocked[x][y] = true;
        }
      }
    }
  }