-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrass.java
More file actions
31 lines (27 loc) · 885 Bytes
/
Copy pathGrass.java
File metadata and controls
31 lines (27 loc) · 885 Bytes
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Grass exists in the world as decorative objects
*
* @author Jacky161
* @version v1.0-public
*/
public class Grass extends Actor
{
/** Constructor for grass. Picks a random grass sprite to use */
public Grass() {
int grassRand = Greenfoot.getRandomNumber(4) + 1;
setImage("grass/grass" + grassRand + ".png");
}
/** Checks grass for any spawn range issues (called when grass is created) */
public boolean checkRange() {
// Can't spawn too close to fences
if (getObjectsInRange(50, Fence.class).size() > 0) {
return true;
}
// Try not to spawn too close to each other
if (getObjectsInRange(5, Grass.class).size() > 0) {
return true;
}
return false;
}
}