-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSprite.java
executable file
·157 lines (129 loc) · 3.43 KB
/
Sprite.java
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
public class Sprite
{
private double left; //the x-coordinate of the left edge of the sprite
private double top; //the y-coordinate of the top edge of the sprite
private int width;
private int height;
private String image;
public Sprite(double theLeft, double theTop, int theWidth, int theHeight, String theImage)
{
left = theLeft;
top = theTop;
width = theWidth;
height = theHeight;
setImage(theImage);
}
public Sprite() {
}
public boolean touching(double x, double y)
{
return x>left && x<left+width && y>top && y<top + height;
}
public boolean touchingAfterDisplacement(double x, double y, double dx, double dy)
{
return x>left+dx && x<left+width+dx && y>top+dy && y<top + height+dy ;
}
public boolean touching(Sprite s)
{
double scale = 0.2;
double sRight = (s.getLeft() + s.getWidth()) - s.getWidth()*scale;
double sBottom = s.getTop() + s.getHeight() - s.getHeight()*scale;
if (touching(s.getLeft() + s.getWidth()*scale, s.getTop() + s.getHeight()*scale))
return true;
if (touching(s.getLeft() + s.getWidth()*scale,sBottom))
return true;
if (touching(sRight,sBottom))
return true;
if (touching(sRight,s.getTop() + s.getHeight()*scale))
return true;
return false;
}
public void deactivate()
{
setHeight(0);
setLeft(10000);
setTop(10000);
}
public boolean touching(Sprite s, double scale)
{
double sRight = (s.getLeft() + s.getWidth()) - s.getWidth()*scale;
double sBottom = s.getTop() + s.getHeight() - s.getHeight()*scale;
if (touching(s.getLeft() + s.getWidth()*scale, s.getTop() + s.getHeight()*scale))
return true;
if (touching(s.getLeft() + s.getWidth()*scale,sBottom))
return true;
if (touching(sRight,sBottom))
return true;
if (touching(sRight,s.getTop() + s.getHeight()*scale))
return true;
return false;
}
public boolean touchingAfterDisplacement(Sprite s, double dx, double dy) {
double scale = 0.2;
double sLeft = s.getLeft();
double sTop = s.getTop();
double sRight = (s.getLeft() + s.getWidth());
double sBottom = s.getTop() + s.getHeight();
if (touchingAfterDisplacement(sLeft,sTop,dx,dy))
return true;
if (touchingAfterDisplacement(sLeft,sBottom,dx,dy))
return true;
if (touchingAfterDisplacement(sRight,sTop,dx,dy))
return true;
if (touchingAfterDisplacement(sRight,sBottom,dx,dy))
return true;
if (touchingAfterDisplacement(sLeft + s.getWidth()/2,sTop,dx,dy))
return true;
if (touchingAfterDisplacement(sLeft,sTop + s.getHeight()/2,dx,dy))
return true;
if (touchingAfterDisplacement(sLeft+ s.getWidth()/2,sBottom,dx,dy))
return true;
if (touchingAfterDisplacement(sRight,sTop+s.getHeight()/2,dx,dy))
return true;
return false;
}
public double getLeft()
{
return left;
}
public void setLeft(double l)
{
left = l;
}
public double getTop()
{
return top;
}
public void setTop(double t)
{
top = t;
}
public int getWidth()
{
return width;
}
public void setWidth(int w)
{
width = w;
}
public int getHeight()
{
return height;
}
public void setHeight(int h)
{
height = h;
}
public String getImage()
{
return image;
}
public void setImage(String i)
{
image = i;
}
public void step(Generate generate)
{
//do NOT insert any code here
}
}