-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawPanel.java
119 lines (93 loc) · 2.46 KB
/
DrawPanel.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
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.Color;
import java.awt.event.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
public class DrawPanel extends JPanel //implements MouseMotionListener
{
State state = new State();
Graphics2D g2;
int density;
int x_count;
int y_count;
public DrawPanel(int p_x_count, int p_y_count, int p_density)
{
setDoubleBuffered(true);
density = p_density;
x_count = p_x_count;
y_count = p_y_count;
addMouseListener(new java.awt.event.MouseAdapter()
{
public void mouseClicked(java.awt.event.MouseEvent e)
{
}
public void mousePressed(java.awt.event.MouseEvent e)
{
}
public void mouseReleased(java.awt.event.MouseEvent e)
{
}
});
addMouseMotionListener(new java.awt.event.MouseAdapter()
{
public void mouseMoved(java.awt.event.MouseEvent e)
{
int x = e.getX();
int y = e.getY();
state.mouseX = x;
state.mouseY = y;
//double dX = state.mouseX - 800;
//double dY = state.mouseY - 600;
}
public void mouseDragged(java.awt.event.MouseEvent e)
{
}
});
}
double imageAngleRad;
int x;
int y;
protected void paintComponent(Graphics g)
{
//System.out.println(x_count);
//System.out.println("y"+y_count);
g.drawImage(state.bg, 0, 0, null);
g.setColor(Color.YELLOW);
g2 = (Graphics2D)g;
g2.setStroke(new BasicStroke(3));
for(int i = 0; i < y_count; i++)
{
for(int j = 0; j < x_count; j++)
{
x = j*density;
y = i*density;
//g.fillOval(x-4, y-4, 8, 8);
AffineTransform oldAT = g2.getTransform();
double dX = state.mouseX - x;
double dY = state.mouseY - y;
imageAngleRad = Math.atan2(dY, dX);
g2.rotate(imageAngleRad, x, y);
//g2.drawImage(state.line, x, y, null);
g2.setTransform(oldAT);
}
}
g2.setStroke(new BasicStroke(6));
if(!state.monsters.isEmpty())
{
for(int i = 0; i < state.monsters.size(); i++)
{
g2.setColor(state.monsters.get(i).color);
g2.drawLine(state.monsters.get(i).X, state.monsters.get(i).Y, state.monsters.get(i).X, state.monsters.get(i).Y);
}
}
}
public void updatePaint()
{
}
public void save()// throws IOException
{
}
}