-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathShovel.java
47 lines (44 loc) · 1.37 KB
/
Shovel.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
45
46
47
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Shovel here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Shovel extends SmoothMover
{
/**
* Act - do whatever the Shovel wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public boolean selected = false;
public void addedToWorld(World world) {
setImage("shovel1.png");
selected = false;
}
public void act()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse != null) {
if (Greenfoot.mouseClicked(null)) {
MyWorld MyWorld = (MyWorld)getWorld();
MyWorld.moveHitbox();
if (intersects(MyWorld.hitbox)) {
if (!selected) {
selected = true;
setImage("shovel2.png");
AudioPlayer.play(80, "shovel.mp3");
MyWorld.addObject(new clickShovel(), mouse.getX(), mouse.getY());
}
}
}
}
// Add your action code here.
}
public void setSelected(boolean bool) {
if (!bool) {
selected = bool;
setImage("shovel1.png");
}
}
}