-
Notifications
You must be signed in to change notification settings - Fork 0
/
Block.java
104 lines (68 loc) · 2 KB
/
Block.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
import java.awt.*;
public class Block {
double x;
double y;
double rtEdge;
double ltEdge;
double btEdge;
int angle;
int[] xblok1;
int[] yblok1;
int[] xblok2;
int[] yblok2;
int[] xblok3;
int[] yblok3;
int[] xblok4;
int[] yblok4;
public Block(double x, double y, int angle, int[][] bloks){
this.x = x;
this.y = y;
this.angle = angle;
xblok1 = bloks[0];
xblok2 = bloks[1];
xblok3 = bloks[2];
xblok4 = bloks[3];
yblok1 = bloks[4];
yblok2 = bloks[5];
yblok3 = bloks[6];
yblok4 = bloks[7];
}
public void rotate(){angle -= 90;}
public void moveLt(int dx){ x -= dx;}
public void moveRt(int dx){ x += dx;}
public void moveDn(int dy){ y += dy;}
public void draw(Graphics g)
{
int[] xp = new int[4];
int[] yp = new int[4];
if(angle >= 360) angle -= 360;
if(angle < 0) angle += 360;
double cosA = Lookup.cos[angle];
double sinA = Lookup.sin[angle];
for(int i = 0; i < 4; i ++)
{
xp[i] = (int)((xblok1[i]*cosA - yblok1[i]*sinA) + x);
yp[i] = (int)((xblok1[i]*sinA + yblok1[i]*cosA) + y);
}
g.drawPolygon(xp, yp, 4);
for(int i = 0; i < 4; i ++)
{
xp[i] = (int)((xblok2[i]*cosA - yblok2[i]*sinA) + x);
yp[i] = (int)((xblok2[i]*sinA + yblok2[i]*cosA) + y);
}
g.drawPolygon(xp, yp, 4);
for(int i = 0; i < 4; i ++)
{
xp[i] = (int)((xblok3[i]*cosA - yblok3[i]*sinA) + x);
yp[i] = (int)((xblok3[i]*sinA + yblok3[i]*cosA) + y);
}
g.drawPolygon(xp, yp, 4);
for(int i = 0; i < 4; i ++)
{
xp[i] = (int)((xblok4[i]*cosA - yblok4[i]*sinA) + x);
yp[i] = (int)((xblok4[i]*sinA + yblok4[i]*cosA) + y);
}
g.drawPolygon(xp, yp, 4);
g.drawLine((int)x ,(int)y ,(int)x,(int)y);
}
}