-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimal.java
More file actions
executable file
·51 lines (48 loc) · 1.98 KB
/
Copy pathAnimal.java
File metadata and controls
executable file
·51 lines (48 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.media.AudioClip;
/**
* A class that displays the board images (duck, goat, and horse) at their respective x and y positions.
*/
public class Animal extends CollidableRect
{
/*
*****************************************************************************************************************************************************
***** INSTANCE VARIABLES / CONSTRUCTORS ************************************************************************************************************
*****************************************************************************************************************************************************
*/
private ImageView sprite = new ImageView();
private final AudioClip soundEffect;
public Animal(Image image, String soundEffectPath, double x, double y)
{
sprite.setImage(image);
sprite.setLayoutX(x);
sprite.setLayoutY(y);
setX1(x);
setY1(y);
setX2(x + image.getWidth());
setY2(y + image.getHeight());
soundEffect = new AudioClip(getClass().getClassLoader().getResource(soundEffectPath).toString());
}
/*
*****************************************************************************************************************************************************
***** PUBLIC METHODS ********************************************************************************************************************************
*****************************************************************************************************************************************************
*/
/**
* Returns the respective image (duck, goat, horse).
* @return the respective image (duck, goat, horse).
*/
public ImageView getSprite()
{
return sprite;
}
/**
* Returns the respective sound (duck, goat, horse).
* @return the respective sound (duck, goat, horse).
*/
public void playSoundEffect()
{
soundEffect.play();
}
}