Spam Killing

Hello JGO,

Ever since I finished my LD entry (http://www.ludumdare.com/compo/ludum-dare-30/?action=preview&uid=41601), I’ve noticed a bug where if you hold down space, it just kills the robots no matter where you are. I’ve been trying to figure out why this happens and how to fix it, but I can’t do it. Here’s my code.

[icode]Robot.java[/icode]


package com.darkcart.ld.cwld;

import java.awt.Image;
import java.util.Random;

import javax.swing.ImageIcon;

public class Robot {
	private int tileX, tileY;
	private Image robot;
	Random rand = new Random();
	Random rand1 = new Random();

	public Robot() {
		ImageIcon img = new ImageIcon("robot.png");
		robot = img.getImage();

	}

	public Image getRobot() {
		return robot;
	}

	public int getTileX() {
		return tileX;
	}

	public int getTileY() {
		return tileY;
	}

	public void placeRobot() {
		int randY = rand.nextInt(12);
		if (randY < 1) {
			randY = randY + 1;
		}

		tileX = 10;
		tileY = randY;
	}
	
	public void placeRobot1() {
		int randY = rand1.nextInt(12);
		if (randY < 1) {
			randY = randY + 1;
		}

		tileX = 10;
		tileY = randY;
	}

	public void hideRobot() {
		tileX = -1;
		tileY = -1;
	}

	public void moveForward() {
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		tileX--;
		
	}
}

[icode]Terrain.java[/icode]


//Blah blah blah
ArrayList<Robot> listOfRobots = new ArrayList<Robot>();
Robot temp = new Robot();
public Terrain() {
		//Blah blah blah
		placeRobot();
		
	}

public void paint(Graphics g) {
super.paint(g);
for (int i = 0; i < listOfRobots.size(); i++) {
				g.drawImage(listOfRobots.get(i).getRobot(), listOfRobots.get(i)
						.getTileX() * 32, listOfRobots.get(i).getTileY() * 32,
						null);
			}
}

public void keyPressed(KeyEvent e) {
			int keyCode = e.getKeyCode();
			if (keyCode == KeyEvent.VK_SPACE) {
				temp.hideRobot();
				listOfRobots.remove(temp);
				placeRobot();
				scoreCount++;
				System.out.println(scoreCount + " robots killed");
			}
		}

Can anyone help me?

Thanks, -DarkCart