-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCuttingBoard.java
More file actions
83 lines (77 loc) · 2.94 KB
/
CuttingBoard.java
File metadata and controls
83 lines (77 loc) · 2.94 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* This actor takes an actor of the food class and determines whether the object
* is cut or not. If not, then the cutting board allows this object to be cut.
* Credit to Mr. Cohen for the stat bar actor
* Credit to Hiroyuki Terada for the cutting sounds
*
* @author Isaac Chan
* @version January 28, 2022
*/
public class CuttingBoard extends Counter
{
public CuttingBoard() //constructs a cutting board
{
//adds a stat bar to the cutting board
statBar = new SuperStatBar(maxVal, currVal, this, width, height, offset, filledColor, missingColor, hideAtMax);
}
public void addedToWorld(World w) //allows the stat bar to be added into the world directly
{
w.addObject(statBar, 0, 0);
}
public void act()
{
chopping();
}
public void chopping() //while the food is being chopped
{
//if the polayer presses q, is near the cutting board, is touching food, and that food isn't a plate
if(Greenfoot.isKeyDown("q") && touchingPlayer() && touchingFood() && !isTouching(Plate.class)){
if(!qWasPressed){
findFoodObject = getOneIntersectingObject(Food.class);
foundFoodObject = (Food)findFoodObject; //casts the actor into the food class
//chops the food up
foundFoodObject.chopFood();
//checks that the previous button pressed was q
qWasPressed = true;
} else { // if q was previously pressed
//checks that the previous button pressed was not q
qWasPressed = false;
}
}
}
public boolean isCuttingFood(boolean isCut) //cuts the food
{
if(!isCut){ //if the food object has not been cut yet
//add the sound of cutting the food
GreenfootSound sound = new GreenfootSound("CuttingSound.wav");
sound.setVolume(90);
if(!setZero){ //sets the stat bar to zero in order to reveal it
currVal = 0;
setZero = true;
}
//gradually increases the stat bar; cutting the food
statBar.update(currVal);
currVal++;
if(currVal % 10 == 0){ //every 10 frames that pass by plays a sound
sound.play();
}
if(currVal >= maxVal){ //if the stat bar is full
sound.stop();
statBar.update(currVal);
setZero = false;
return true;
}
} else if(isCut){ //if the object is already cut then nothing will happen
return true;
}
return false;
}
public boolean hasFood() //checks whether the cutting boar is touching food
{
if(isTouching(Food.class)){
return true;
}
return false;
}
}