-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrashCan.java
More file actions
34 lines (33 loc) · 1.12 KB
/
TrashCan.java
File metadata and controls
34 lines (33 loc) · 1.12 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Allows the user to throw away any unnecessary food that the player
* wishes to dispose of.
*
* @author Isaac Chan
* @version January 28, 2022
*/
public class TrashCan extends Counter
{
public void act()
{
throwAway();
}
public void throwAway() //throws away the food
{
if(Greenfoot.isKeyDown("q") && touchingPlayer()){ //if the player presses q whle interacting with the object
if(!qWasPressed && touchingFood()){ //if this is touching food
if(isTouching(Plate.class)){ //removes the soup on the plate
removeTouching(Food.class);
getWorld().addObject(new Plate(), getX(), getY());
} else { //removes the food
removeTouching(Food.class);
}
//checks that the previous button pressed was q
qWasPressed = true;
} else {
//checks that the previous button pressed was not q
qWasPressed = false;
}
}
}
}