import javax.swing.*;  
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;

public class Keypress implements KeyListener{

	private boolean[] buttons = new boolean[20];
	private char[] key = new char[20];

	public Keypress(JPanel j){
		j.addKeyListener(this);
		/////////player 1's keys////////
		key[0] = 'w'; //up
		key[1] = 'a'; //left
		key[2] = 's'; //down
		key[3] = 'd'; //right
		key[4] = 't'; //a on the arcade machine
		key[5] = 'y'; //b on the arcade machine
		key[6] = 'f'; //x on the arcade machine
		key[7] = 'g'; //y on the arcade machine
		key[8] = '1'; //start on the arcade machine
		
		//add credits
		
		key[9] = '3'; //credits button, only one exists for both players
		
		/////////player 2's keys///////////////
		key[10] = 'i'; //up
		key[11] = 'j'; //left
		key[12] = 'k'; //down
		key[13] = 'l'; //right
		key[14] = '['; //a on the arcade machine
		key[15] = ']'; //b on the arcade machine
		key[16] = ';'; //x on the arcade machine
		key[17] = 39; //y on the arcade machine
		key[18] = 2; //start on the arcade machine
		
		
		key[19] = '0'; //not built into the arcade machine can be used as an emergency close with the keyboard
	}
	
	public void keyPressed(KeyEvent e){
		for (int c = 0; c < 20; c++)
		{
		
			if (e.getKeyChar() == key[c]) {
				buttons[c] = true;
			}
		}
	}
	public void keyReleased(KeyEvent e){ 
		for (int c = 0; c < 20; c++)
		{
			if (e.getKeyChar() == key[c]) {
				buttons[c] = false;
			}
		}
	}
	public void keyTyped(KeyEvent e){ }
	
	public boolean[] getInput() {
		return(buttons);
	}
}
