-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTomatoSupply.java
More file actions
32 lines (30 loc) · 1.06 KB
/
TomatoSupply.java
File metadata and controls
32 lines (30 loc) · 1.06 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Supplies the tomatoes for the player to collect when interacting with
* this actor. Generates an infinite amount of tomatoes for the player's
* usage.
*
* @author Isaac Chan
* @version January 28, 2022
*/
public class TomatoSupply extends Counter
{
public void act()
{
spawnTomato();
}
public void spawnTomato() //spawns a tomato that the player can use
{
if(Greenfoot.isKeyDown("q") && touchingPlayer()){ //if q is pressed while interacting with the player
if(!qWasPressed && !touchingFood()){ //create a tomato while food is not touching it
Tomato rawTomato = new Tomato();
getWorld().addObject(rawTomato, getX(), getY());
//checks that the previous button pressed was q
qWasPressed = true;
} else {
//checks that the previous button pressed was not q
qWasPressed = false;
}
}
}
}