package objects;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.util.Timer;
import java.util.TimerTask;

public class Player extends Ship implements KeyListener{
	private Timer movetimer;
	private int movedir;
	
	public Player(BufferedImage image, int x, int y) {
		super(image,x,y);
		movetimer = new Timer();
		movetimer.schedule(new TimerTask() {
			@Override
			public void run() {
				border.setLocation((int)border.getX()+movedir*7, (int)border.getY());
			}
		}, 0, 10);
	}
	
	@Override
	public void keyPressed(KeyEvent e) {
	}
	@Override
	public void keyReleased(KeyEvent e) {
		if((e.getKeyChar() == 'd' && movedir == 1) || (e.getKeyChar() == 'a' && movedir == -1)){
			movedir = 0;
		}
	}
	@Override
	public void keyTyped(KeyEvent e) {
		if(e.getKeyChar() == 'd'){
			movedir = 1;
		}else if(e.getKeyChar() == 'a'){
			movedir = -1;
		}
	}
	
}
