-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackboard.java
More file actions
72 lines (54 loc) · 1.36 KB
/
Backboard.java
File metadata and controls
72 lines (54 loc) · 1.36 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import greenfoot.*;
public class Backboard extends Actor
{
private Basket basket;
private final int WIDTH = 15;
private final int HEIGHT = 140;
private final int BALL_RADIUS = 21;
public Backboard()
{
GreenfootImage backboardImage = new GreenfootImage("images/backboard.png");
backboardImage.scale(WIDTH, HEIGHT);
setImage(backboardImage);
}
public void act()
{
}
public void setBasket(Basket basket)
{
this.basket = basket;
}
public Basket getBasket()
{
return basket;
}
public void moveToRandomLocation()
{
if (getWorld() != null)
{
int newX = Greenfoot.getRandomNumber(getWorld().getWidth() - 150) + 75;
int newY = Greenfoot.getRandomNumber(200) + 150;
setLocation(newX, newY);
if (basket != null)
{
basket.setLocation(newX - 45, newY + 51);
}
}
}
public int getLeft()
{
return getX() - WIDTH / 2;
}
public int getRight()
{
return getX() + WIDTH / 2;
}
public int getTop()
{
return getY() - HEIGHT / 2;
}
public int getBottom()
{
return getY() + HEIGHT / 2;
}
}