예제 #1
1
 public void initAbilities() throws FileNotFoundException, IOException, SlickException {
   BufferedReader reader = new BufferedReader(new FileReader("res/abilities.txt"));
   String[] values;
   String line;
   Ability ability = new Ability();
   Projectile proj;
   try {
     line = reader.readLine();
     while (line != null) {
       values = line.split(",");
       if (values[0].equals("add")) {
         entity.addAttack(ability, Integer.parseInt(values[1]));
         ability = new Ability();
       } else {
         proj =
             new Projectile(
                 Float.parseFloat(values[0]),
                 Float.parseFloat(values[1]),
                 Float.parseFloat(values[2]),
                 Float.parseFloat(values[3]),
                 new Image(values[4]),
                 entity);
         ability.addProjectile(proj);
       }
       line = reader.readLine();
     }
   } finally {
     reader.close();
   }
 }
예제 #2
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);
      }
    }
  }
예제 #3
1
  public void render(GameContainer container, Graphics g) throws SlickException {
    int xOffset = -(int) player.getX() + WIDTH / 2;
    int yOffset = -(int) player.getY() + HEIGHT / 2;

    tileMap.render(xOffset, yOffset);
    player.draw(WIDTH, HEIGHT);
    entity.draw(xOffset, yOffset);
    for (int i = 0; i < projectiles.size(); i++) {
      projectiles.get(i).draw(xOffset, yOffset);
    }
    this.drawHealthBar(g, player, xOffset, yOffset);
    this.drawHealthBar(g, entity, xOffset, yOffset);
  }
예제 #4
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;
        }
      }
    }
  }