Ejemplo n.º 1
0
 /*
  * Konstruktor s animaci
  */
 public PlayerObject(
     Animation animation,
     Shape collisionShape,
     Vector2f position,
     float mass,
     GameContainer gc,
     int player)
     throws SlickException {
   super(
       animation,
       collisionShape,
       ECollisionType.PLAYER,
       "Player",
       position,
       new Vector2f(0, 0),
       mass,
       100,
       0.01f,
       engine.level.Level.getLevelShape());
   gc.getInput().addKeyListener(this);
   setControls(player);
   init();
   this.animations = new Animations(EFighter.SENTINEL);
   if (animation == null) {
     animation = animations.getStayAnimation(getSide());
   }
 }
Ejemplo n.º 2
0
 @Override
 public void keyReleased(int i, char c) {
   if (!isAlive) {
     return;
   }
   if (i == controls[3]) {
     setConstantSpeed(0);
     if (animation != null) {
       animation = animations.getStayAnimation(getSide());
     }
   }
   if (i == controls[1]) {
     setConstantSpeed(0);
     if (animation != null) {
       animation = animations.getStayAnimation(getSide());
     }
   }
 }
Ejemplo n.º 3
0
  /*
   * Aktualizace objektu
   */
  @Override
  public void update(GameContainer gc, StateBasedGame sbg, int delta) {
    super.update(gc, sbg, delta);

    if (!isAlive) {
      if ((System.currentTimeMillis() - timeOfDeath) > spawnInterval) {
        position = new Vector2f(Level.getScreenXToLevelX(100), Level.getScreenYToLevelY(100));
        isAlive = true;
        animation = animations.getStayAnimation(getSide());
        setHealth(100);
      }
    }

    int border = 250;
    float screen_speed = 3f;
    if (position.x < engine.level.Level.getScreenShape().getMinX() + border) {
      if (position.x > engine.level.Level.getLevelShape().getMinX()
          && engine.level.Level.getLevelShape().getMinX()
              < engine.level.Level.getScreenShape().getMinX()) {
        engine.level.Level.moveScreen(screen_speed, 0);
      }
    }
    if (getCollisionShape().getMaxX() > engine.level.Level.getScreenShape().getMaxX() - border) {
      if (position.x < engine.level.Level.getLevelShape().getMaxX()
          && engine.level.Level.getLevelShape().getMaxX()
              > engine.level.Level.getScreenShape().getMaxX()) {
        engine.level.Level.moveScreen(-screen_speed, 0);
      }
    }
    if (position.y < engine.level.Level.getScreenShape().getMinY() + border) {
      if (position.y > engine.level.Level.getLevelShape().getMinY()
          && engine.level.Level.getLevelShape().getMinY()
              < engine.level.Level.getScreenShape().getMinY()) {
        engine.level.Level.moveScreen(0, screen_speed);
      }
    }
    if (getCollisionShape().getMaxY() > engine.level.Level.getScreenShape().getMaxY() - border) {
      if (getCollisionShape().getMaxY() < engine.level.Level.getLevelShape().getMaxY()
          && engine.level.Level.getLevelShape().getMaxY()
              > engine.level.Level.getScreenShape().getMaxY()) {
        engine.level.Level.moveScreen(0, -screen_speed);
      }
    }

    if (position.x < engine.level.Level.getScreenShape().getMinX()) {
      position.x = engine.level.Level.getScreenShape().getMinX();
    }
    if (getCollisionShape().getMaxX() > Level.getScreenShape().getMaxX()) {
      position.x = Level.getScreenShape().getMaxX() - getCollisionShape().getWidth();
    }
    if (position.y < Level.getScreenShape().getMinY()) {
      position.y = Level.getScreenShape().getMinY();
    }
    if (position.y > Level.getLevelShape().getMaxY()) {
      this.deactivate();
    }
  }
Ejemplo n.º 4
0
 public void setDamagedAnimation(ICollidableObject entity) {
   if (animation != null) {
     if (isAlive) {
       if (((PhysicalObject) entity).getSide() == ESide.RIGHT) {
         position.y -= 2;
         setVelocity(new Vector2f(10, -10));
       } else {
         position.y -= 2;
         setVelocity(new Vector2f(-10, -10));
       }
       animation = animations.getDamagedFigure(getSide());
     }
   }
 }
Ejemplo n.º 5
0
 /*
  * Co se stane po smrti
  */
 @Override
 public void notifyDeath() {
   super.notifyDeath();
   try {
     (new Sound("data/sounds/death.wav")).play();
   } catch (SlickException ex) {
   }
   animation = animations.getDiedFigure(getSide());
   timeOfDeath = System.currentTimeMillis();
   GameStats.nextDeath();
   try {
     GameStats.nextLive();
   } catch (SlickException ex) {
   }
 }
Ejemplo n.º 6
0
 @Override
 protected void doAfterCollision(ICollidableObject entity) {
   if (isAlive) {
     if (animation != null) {
       if (animations.isJumpAnimation(animation)) {
         if (isOnGround() && velocity.x < 0.5 && velocity.x > -0.5) {
           animation = animations.getStayAnimation(getSide());
         }
         if (isOnGround() && velocity.x > 1) {
           animation = animations.getWalkAnimation(getSide());
         } else if (isOnGround() && velocity.x < -1) {
           animation = animations.getWalkAnimation(getSide());
         }
       }
       if (isOnGround() && animations.isDamagedAnimation(animation)) {
         animation = animations.getStayAnimation(getSide());
       }
     }
   }
 }
Ejemplo n.º 7
0
  @Override
  public void keyPressed(int i, char c) {
    if (!isAlive) {
      return;
    }
    if (i == controls[0] && isOnGround()) {
      setVelocityY(-MAX_JUMP);
      try {
        (new Sound("data/sounds/jumping.wav")).play();
      } catch (SlickException ex) {
      }
      if (animation != null) {
        animation = animations.getJumpAnimation(getSide());
      }
    }
    if (i == controls[3]) {
      if (isObjectLooksRight()) {
        if (image != null) {
          image = image.getFlippedCopy(true, false);
        }
      }
      setConstantSpeed(-SPEED);
      if (animation != null) {
        if (isOnGround()) {
          animation = animations.getWalkAnimation(getSide());
        } else {
          animation = animations.getJumpAnimation(getSide());
        }
      }
    }
    if (i == controls[1]) {
      if (isObjectLooksLeft()) {
        if (image != null) {
          image = image.getFlippedCopy(true, false);
        }
      }
      setConstantSpeed(SPEED);
      if (animation != null) {
        if (isOnGround()) {
          animation = animations.getWalkAnimation(getSide());
        } else {
          animation = animations.getJumpAnimation(getSide());
        }
      }
    }

    if (action.isNextTick()) {
      if (i == controls[4]) {
        if (inventory.isPistolIn()) {
          if (inventory.getPistol().reload(inventory.getAmmo(EAmmo.BULLETS))) {
            if (inventory.getPistol().tryToFire(this)) {
              animation = animations.getPistolFigure(getSide());
            }
          } else {
            try {
              (new Sound("data/sounds/gun_noammo.ogg")).play();
            } catch (SlickException ex) {
            }
          }
        } else {
          try {
            (new Sound("data/sounds/eee.wav")).play();
          } catch (SlickException ex) {
          }
        }
      }
      if (i == controls[5]) {
        if (inventory.isShotgunIn()) {
          if (inventory.getShotgun().reload(inventory.getAmmo(EAmmo.SHELLS))) {
            if (inventory.getShotgun().tryToFire(this)) {
              animation = animations.getShotgunFigure(getSide());
            }
          } else {
            try {
              (new Sound("data/sounds/gun_noammo.ogg")).play();
            } catch (SlickException ex) {
            }
          }
        } else {
          try {
            (new Sound("data/sounds/eee.wav")).play();
          } catch (SlickException ex) {
          }
        }
      }
      if (i == controls[6]) {
        if (inventory.isBFG9KIn()) {
          if (inventory.getBFG9K().reload(inventory.getAmmo(EAmmo.PLASMA))) {
            if (inventory.getBFG9K().tryToFire(this)) {
              animation = animations.getBFG9KFigure(getSide());
            }
          } else {
            try {
              (new Sound("data/sounds/gun_noammo.ogg")).play();
            } catch (SlickException ex) {
            }
          }
        } else {
          try {
            (new Sound("data/sounds/eee.wav")).play();
          } catch (SlickException ex) {
          }
        }
      }
      if (i == controls[7]) {
        if (inventory.getHand().reload(inventory.getAmmo(EAmmo.GRENADES))) {
          if (inventory.getHand().tryToThrow(this)) {
            animation = animations.getThrowingFigure(getSide());
          }
        } else {
          try {
            (new Sound("data/sounds/eee.wav")).play();
          } catch (SlickException ex) {
          }
        }
      }
      if (i == controls[8]) {
        if (inventory.getHand().reload(inventory.getAmmo(EAmmo.BOMBS))) {
          if (inventory.getHand().tryToThrow(this)) {
            animation = animations.getThrowingFigure(getSide());
          }
        } else {
          try {
            (new Sound("data/sounds/eee.wav")).play();
          } catch (SlickException ex) {
          }
        }
      }
    }
  }