aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag/src/PunchingBagGUI.java
blob: 63f05ae96d08fa4b89cf2395a49bb90aea812e55 (plain)
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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;

public class PunchingBagGUI implements MouseListener, MouseMotionListener,
		ButtonListener, LEDListener {

	public static enum Mode {
		Menu, Interactive, Game
	};

	Mode currentMode = Mode.Interactive;

	final int bagXSize = 360;
	final int bagYSize = 840;

	static JFrame frame;
	static JFrame bagSimFrame;

	// Contact
	public enum Direction {
		None, Up, Down, Left, Right
	};
	
	PunchingBag bag = new PunchingBag();

	final boolean useDebugScreen = true;

	public static void main(String[] args) throws InterruptedException {
		// SlaveArduino.listPorts();

		new PunchingBagGUI();

	}

	PunchingBagGUI() throws InterruptedException {
		frame = new JFrame("Punching Bag GUI");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setSize(300, 300);
		frame.setVisible(true);

		bagSimFrame = new JFrame("Punching Bag Sim");
		bagSimFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		bagSimFrame.setSize(bagXSize, bagYSize);
		bagSimFrame.addMouseListener(this);
		bagSimFrame.addMouseMotionListener(this);
		bagSimFrame.setVisible(true);

		System.out.println("Bag X: " + bagSimFrame.getX() + " Bag Y: "
				+ bagSimFrame.getY());

		bag.addButtonListener(this);
		bag.addLEDChangeListener(this);
	}

	public void runInteractively(Contact contact) {
		System.out.println("Contact");
		bag.buttonPressed(contact.x, contact.y);
	}

	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void mousePressed(MouseEvent arg0) {
		if (currentMode == Mode.Interactive) {
			runInteractively(new Contact(System.currentTimeMillis(), (arg0
					.getX() - 4) / 40, (arg0.getY() - 30) / 40, 0));
		}
	}

	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void mouseMoved(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	public void contact(Contact c) {
		// TODO Auto-generated method stub

	}

	@Override
	public void buttonPressed(int x, int y) {
		System.out.println("Button Pressed: " + x + " " + y);
		bag.CircleExpand(x, y, 16);

	}

	@Override
	public void LEDchanged() {
		for (int x = 0; x < bag.ledWidth; x++) {
			for (int y = 0; y < bag.ledHeight; y++) {
				if (useDebugScreen) {
					Graphics g = bagSimFrame.getGraphics();
					if (bag.getLED(x, y) == PunchingBag.Colour.Red) {
						g.setColor(Color.red);
						g.fillOval(40 * x, 40 * y, 6, 6);
					} else if (bag.getLED(x, y) == PunchingBag.Colour.Green) {
						g.setColor(Color.green);
						g.fillOval(40 * x, 40 * y, 6, 6);
					} else if (bag.getLED(x, y) == PunchingBag.Colour.Yellow) {
						g.setColor(Color.yellow);
						g.fillOval(40 * x, 40 * y, 6, 6);
					} else {
						g.setColor(Color.white);
						g.fillOval(40 * x, 40 * y, 6, 6);
					}
				}
			}
		}

	}

}