@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()); } } } }
@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) { } } } } }