public void run() {
        
        long start = System.nanoTime();
        long elapsed;
        long wait;
        final int minTimeBetweenFrames = 5;

        while (running) {
            //Timing
            //elapsed is the number of nanoseconds since last frame
            elapsed = System.nanoTime() - start;
            elapsed = Math.min(MAX_FRAME, elapsed);
            start = System.nanoTime();
            Point pos = hero.getPos();
            frame++;
            
            
            //Physics!
            simulate(hero, elapsed);
            
            //Move camera
            updateCamPos();
            
            //Test 'victory' conditions
            if (pos.y < LOWER_BOUND) {
                running = false;
            }
            
            //Test world events (like touching a light)
            testTriggers(triggers);
            
            //Delete (release) dead effects.
            deleteDeadEntities();
            
            //redraw everything
            repaint();
            
            //"elapsed" is reassigned to the number of nanoseconds 
            //since this frame began
            elapsed = System.nanoTime() - start;
            
            //wait is how much time is remaining 
            //before the next frame needs to be drawn.
            wait = targetTime - elapsed / NS_PER_MS;
            
            //wait at least 5 ms between frames.
            if (wait < 0) {
                wait = minTimeBetweenFrames;
            }
            try {
                Thread.sleep(wait);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        } //end while
    } // end run