/*
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 */
package pacman;


import javafx.animation.Interpolator;
import javafx.animation.RotateTransition;
import javafx.animation.Timeline;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.media.AudioClip;
import javafx.scene.transform.Rotate;
import javafx.util.Duration;
import static pacman.Pacman.*;


/**
 *
 * @author akouznet
 */
public class Palevo extends ImageView {
    
    private static Image[] images = {
        new Image(Palevo.class.getResource("images/водка.png").toExternalForm()),
        new Image(Palevo.class.getResource("images/сигареты.png").toExternalForm()),
        new Image(Palevo.class.getResource("images/стакан пива.png").toExternalForm()),
        new Image(Palevo.class.getResource("images/heineken.png").toExternalForm()),
    };

    private static AudioClip[] audioClips = {
        new AudioClip(Palevo.class.getResource("sounds/bottle.wav").toExternalForm()),
        new AudioClip(Palevo.class.getResource("sounds/cigarettes.wav").toExternalForm()),
        new AudioClip(Palevo.class.getResource("sounds/cup2.wav").toExternalForm()),
        new AudioClip(Palevo.class.getResource("sounds/bottle.wav").toExternalForm()),
    };

    public Palevo() {
        int index = (int) (Math.random() * 4);
        Image image = images[index];
        setImage(image);
        audioClips[index].play();
        setFitWidth(CELL_WIDTH);
        setFitHeight(CELL_WIDTH);
        setPreserveRatio(true);
        setX((CELL_WIDTH - getLayoutBounds().getWidth()) / 2);
        setTranslateZ(CELL_WIDTH);
        
        RotateTransition rotateTransition = new RotateTransition(Duration.millis(1500), this);
        rotateTransition.setByAngle(360);
        rotateTransition.setCycleCount(Timeline.INDEFINITE);
        rotateTransition.setInterpolator(Interpolator.LINEAR);
        rotateTransition.setAxis(Rotate.Y_AXIS);
        rotateTransition.playFrom(Duration.millis(1500 * Math.random()));
        
//        getGame().addAnimation(rotateTransition);
    }
}
