-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlateStation.java
More file actions
45 lines (40 loc) · 1.54 KB
/
PlateStation.java
File metadata and controls
45 lines (40 loc) · 1.54 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* The station that the player uses in order to gather plates which hold
* the soup that the player needs to serve. It can only generate a total
* of two plates in the world.
*
* @author Isaac Chan
* @version January 28, 2022
*/
public class PlateStation extends Counter
{
//total number of plates that the world can have
private static int totalPlates = 2;
public void act()
{
spawnPlate();
}
public void spawnPlate() //summons a plate for the player
{
if(Greenfoot.isKeyDown("q") && touchingPlayer()){ //if the player interacts with this actor
if(!qWasPressed && !touchingFood() && totalPlates > 0){ //if there are plates available while nothing it on the actor
//creates a new plate
Plate plate = new Plate();
getWorld().addObject(plate, getX(), getY());
//reduces the plates left for the world to have
totalPlates--;
//checks that the previous button pressed was q
qWasPressed = true;
} else {
//checks that the previous button pressed was not q
qWasPressed = false;
}
}
}
public void setPlates(int platesReturned) //when plates have been returned from serving orders
{
//increase the plates that can be generated rom this actor
totalPlates += platesReturned;
}
}