-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrow.java
More file actions
86 lines (65 loc) · 1.96 KB
/
Arrow.java
File metadata and controls
86 lines (65 loc) · 1.96 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import greenfoot.*;
public class Arrow extends Actor
{
private int power = 0;
private boolean visible = false;
public Arrow()
{
GreenfootImage arrowImage = new GreenfootImage(50, 10);
arrowImage.setColor(Color.WHITE);
arrowImage.fillRect(0, 4, 40, 2);
int[] xPoints = {40, 50, 40};
int[] yPoints = {0, 5, 10};
arrowImage.fillPolygon(xPoints, yPoints, 3);
setImage(arrowImage);
setVisible(false);
}
public void setPower(int power)
{
this.power = power;
int length = Math.max(20, Math.min(80, power / 3));
GreenfootImage arrowImage = new GreenfootImage(length + 10, 10);
arrowImage.setColor(Color.WHITE);
arrowImage.fillRect(0, 4, length, 2);
int[] xPoints = {10, 0, 10};
int[] yPoints = {0, 5, 10};
arrowImage.fillPolygon(xPoints, yPoints, 3);
arrowImage.fillRect(10, 4, length, 2);
setImage(arrowImage);
}
public void setVisible(boolean visible)
{
this.visible = visible;
if (!visible)
{
GreenfootImage transparent = new GreenfootImage(1, 1);
transparent.setTransparency(0);
setImage(transparent);
}
}
public int getPower()
{
return power;
}
public boolean isVisible()
{
return visible;
}
private boolean facingLeft = false;
private boolean lastFacingLeft = false;
public void setFacingLeft(boolean facingLeft)
{
this.facingLeft = facingLeft;
updateDirection();
}
private void updateDirection()
{
if (facingLeft != lastFacingLeft)
{
GreenfootImage img = getImage();
img.mirrorHorizontally();
setImage(img);
lastFacingLeft = facingLeft;
}
}
}