-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.java
44 lines (40 loc) · 1.18 KB
/
Button.java
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Button here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Button extends animatedObject
{
/**
* Act - do whatever the Button wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public GreenfootImage idle;
public GreenfootImage hover;
public Button(String idle, String hover) {
this.idle = new GreenfootImage(idle);
this.hover = new GreenfootImage(hover);
setImage(idle);
}
public void act()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
GameOver world = (GameOver)getWorld();
if (mouse != null) {
world.moveHitbox();
if (this.intersects(world.hitbox)) {
setImage(hover);
} else {
setImage(idle);
}
if (Greenfoot.mouseClicked(this)) {
AudioPlayer.play(100, "gravebutton.mp3");
update();
}
}
}
public void update() {
}
}