/* * Pridani predmetu do inventare */ public void putItemToInventory(ItemObject item) { inventory.addItem(item); try { (new Sound("data/sounds/p.wav")).play(); } catch (SlickException ex) { } }
/* * Inicializace */ private void init() throws SlickException { hStep = (float) (100 / getHealth()); inventory = new Inventory(530, 20, 100, 200); inventory.addItem(new PistolObject(new Vector2f(200, 100))); inventory.addItem( new AmmoObject( EAmmo.BULLETS, new Image("data/images/icons/bullets.png"), 50, new Image("data/images/items/ammobox.png"), "Bullets", new Vector2f(250, 100))); addCollisionTypeToList(ECollisionType.ENEMY); addCollisionTypeToList(ECollisionType.ITEM); addCollisionTypeToList(ECollisionType.TERRAIN); }
/* * Vykresleni */ @Override public void render(Graphics graphics) { super.render(graphics); graphics.setColor(Color.black); graphics.fillRect(530, 10, 102, 7); graphics.setColor(Color.red); graphics.fillRect(531, 11, (float) (hStep * getHealth()), 5); inventory.draw(graphics); }
@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) { } } } } }