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