-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCookingPot.java
More file actions
162 lines (155 loc) · 6.11 KB
/
CookingPot.java
File metadata and controls
162 lines (155 loc) · 6.11 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Cooks the food and turns it into soup that can later be served in order
* to complete an order. The cooking pot can also count how many objects
* are currently stored in the pot.
* Credit to Mr. Cohen for the stat bar actor
* Credit to Relaxing White Noise for the boiling sound
*
* @author Isaac Chan
* @version January 28, 2022
*/
public class CookingPot extends Counter
{
//variables for the dimensions of this actor
private final int length = 75;
//variables for drawing the indicator that shows how much food is in the pot
//as well as what type of food it is
private final Color onionIndicator = new Color (102, 0, 204);
private final Color tomatoIndicator = new Color (255, 70, 70);
private final int drawIndicatorLength = 10;
//variables used to check for boiling parameters
int totalFoodInPot = 0;
boolean isBoiling = false;
boolean onionInPot = false, tomatoInPot = false;
boolean hasOnionSoup = false, hasTomatoSoup = false;
boolean soupInPot = false;
GreenfootSound sound = new GreenfootSound("BoilingSound.wav");
//StatBar variables are different here for a longer duration
int maxVal = 400, currVal = 400;
public CookingPot()
{
//attaches the stat bar to the cooking pot when it is constructed
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()
{
boiling();
noSoup();
}
public boolean foodInPot() //checks if the player is putting food into the pot
{
findFoodObject = getOneIntersectingObject(Food.class);
foundFoodObject = (Food)findFoodObject;
if(foundFoodObject != null){
if(foundFoodObject.hasBeenCut() && !soupInPot){ //when adding chopped food into the cooking pot
if(foundFoodObject instanceof Onion && tomatoInPot == false){ //if the food object is an onion
totalFoodInPot++;
onionInPot = true; //classifies it into onion soup
foodIndicator(); //displays the number of onions in the pot
removeTouching(Onion.class);
} else if(foundFoodObject instanceof Tomato && onionInPot == false){ //if the food object is a tomato
totalFoodInPot++;
tomatoInPot = true; //classifies it into tomato soup
foodIndicator(); //displays the number of tomatoes in the pot
removeTouching(Tomato.class);
}
return true;
}
}
return false;
}
public void boiling() //boils the food
{
if(touchingPlayer() && foodInPot()){ //if the player is near the pot with food
if(!isBoiling && totalFoodInPot == 3){
isBoiling = true; //starts boiling the food
if(!setZero){
sound.setVolume(100);
sound.play();
currVal = 0; //reveals the stat bar starting at 0
setZero = true;
}
}
} else if(isBoiling){ //while the food is boiling
currVal++;
statBar.update(currVal);
if(currVal >= maxVal){
statBar.update(currVal);
sound.stop();
soupType(); //determines what kind of soup has been made
//resets the stats to prepare for the next soup
totalFoodInPot = 0;
onionInPot = false;
tomatoInPot = false;
soupInPot = true;
setZero = false;
isBoiling = false;
}
}
}
public void soupType() //determines what kind of soup has been made
{
if(onionInPot){ //makes onion soup
GreenfootImage onionSoup = new GreenfootImage("OnionSoup.png");
setImage(onionSoup);
hasOnionSoup = true;
} else if (tomatoInPot){ //makes tomato soup
GreenfootImage tomatoSoup = new GreenfootImage("TomatoSoup.png");
setImage(tomatoSoup);
hasTomatoSoup = true;
}
}
public GreenfootImage drawIndicator() //makes the image of the indicator
{
GreenfootImage image = new GreenfootImage (drawIndicatorLength, drawIndicatorLength);
if(onionInPot){
image.setColor(onionIndicator); //purple
} else if(tomatoInPot){
image.setColor(tomatoIndicator); //red
}
image.fillRect(0, 0, drawIndicatorLength, drawIndicatorLength);
return image;
}
public void foodIndicator() //indicates how much onion or tomato is in the pot
{
GreenfootImage image = getImage();
GreenfootImage indicator = drawIndicator();
if(totalFoodInPot != 0){ //draws the indicator on top of the original image
image.drawImage(indicator, length / 4 * totalFoodInPot - drawIndicatorLength/2, length - drawIndicatorLength);
setImage(image);
}
}
public void putOnPlate() //puts the soup onto the plate
{
if(isTouching(Plate.class) && soupInPot){
//resets the image to normal again
GreenfootImage cookingPot = new GreenfootImage("CookingPot.png");
setImage(cookingPot);
}
}
public String getSoupInPot() //returns what kind of soup is in the pot
{
if(hasOnionSoup){ //if it is onion soup
putOnPlate();
soupInPot = false;
return "onion";
} else if(hasTomatoSoup){ //if it is tomato soup
putOnPlate();
soupInPot = false;
return "tomato";
}
return "";
}
public void noSoup() //checks for soup stats during every act
{
if(!soupInPot){
hasOnionSoup = false;
hasTomatoSoup = false;
}
}
}