package edu.stuy.starlorn.world;

import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.util.LinkedList;

import edu.stuy.starlorn.graphics.DefaultHook;
import edu.stuy.starlorn.graphics.Screen;
import edu.stuy.starlorn.entities.Entity;
import edu.stuy.starlorn.entities.PlayerShip;

/*
 * Represents a world with entities in it
 */
public class World extends DefaultHook {

    private Screen screen;
    private LinkedList<Entity> entities;
    private PlayerShip player;

    public World(Screen scr) {
        screen = scr;
        entities = new LinkedList<Entity>();
        player = new PlayerShip();
        player.setWorld(this);
    }

    public void addEntity(Entity e) {
        entities.add(e);
    }

    public void removeEntity(Entity e) {
        entities.remove(e);
    }

    public void step(Graphics2D graphics) {
        for (Entity e : entities) {
            e.preStep();
        }
        for (Entity e : entities) {
            e.step();
        }
        for (Entity e : entities) {
            e.postStep();
        }
        for (Entity e : entities) {
            e.draw(graphics);
        }
    }

    public void keyPressed(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.VK_W)
            player.setGoingUp(true);
        else if (event.getKeyCode() == KeyEvent.VK_A)
            player.setGoingLeft(true);
        else if (event.getKeyCode() == KeyEvent.VK_S)
            player.setGoingDown(true);
        else if (event.getKeyCode() == KeyEvent.VK_D)
            player.setGoingRight(true);
    }

    public void keyReleased(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.VK_W)
            player.setGoingUp(false);
        else if (event.getKeyCode() == KeyEvent.VK_A)
            player.setGoingLeft(false);
        else if (event.getKeyCode() == KeyEvent.VK_S)
            player.setGoingDown(false);
        else if (event.getKeyCode() == KeyEvent.VK_D)
            player.setGoingRight(false);
    }

    public Screen getScreen() {
        return screen;
    }
}

@@ -104,26 +104,48 @@
 va.util.
+concurrent.Concurrent
 Linked
-List
+Queue
 ;%0A%0Aimpor
@@ -447,26 +447,37 @@
 private 
+Concurrent
 Linked
-List
+Queue
 %3CEntity%3E
@@ -599,18 +599,29 @@
 new 
+Concurrent
 Linked
-List
+Queue
 %3CEnt
@@ -1592,24 +1592,126 @@
 ight(true);%0A
+        else if (event.getKeyCode() == KeyEvent.VK_SPACE)%0A            player.setShootRequested(true);%0A
     %7D%0A%0A    p
@@ -2072,32 +2072,32 @@
  KeyEvent.VK_D)%0A
-
             play
@@ -2117,24 +2117,127 @@
 ght(false);%0A
+        else if (event.getKeyCode() == KeyEvent.VK_SPACE)%0A            player.setShootRequested(false);%0A
     %7D%0A%0A    p

Use a ConcurrentLinkedQueue for the list of entities