moveValX = new double[ NUM_ITEMS ];
moveValY = new double[ NUM_ITEMS ];
Random rand = new Random( System.currentTimeMillis() );
//tree.buildTreeToDepth( 8 );
for( int i = 0; i < NUM_ITEMS; i++ ) {
Point tempPoint = Points.get( rand.nextInt( theWindow.getWidth() - 30 ) + 30, rand.nextInt( theWindow.getHeight() - 30 ) + 30 );
Size tempSize = Sizes.get( rand.nextInt( 30 ) + 21, rand.nextInt( 30 ) + 21 );
JavaSprite temp = new JavaSprite( "fenceright", tempPoint, tempSize );
allGraphics.add( temp );
tree.insert( temp );
moveValX[ i ] = rand.nextDouble() * RAND_RANGE * ( rand.nextInt( 50 ) > 24 ? -1 : 1 );
moveValY[ i ] = rand.nextDouble() * RAND_RANGE * ( rand.nextInt( 50 ) > 24 ? -1 : 1 );
}
long prevTime = System.nanoTime() / 1000000,
curTime = System.nanoTime() / 1000000;
long delta;
long gameLoop = 0;
while( true ) {
//System.out.println( "Main loop has run " + gameLoop + " times." );
++gameLoop;
input.update();
mouseInput.poll();
if( input.isKeyDown( KeyEvent.VK_Q ) ) {
break;
}
if( mouseInput.buttonDown( 0 ) ) {
//System.out.println( "Button event 1 detected." );
Point p = Points.get( mouseInput.cx, mouseInput.cy );
for( int i = 0; i < allGraphics.size(); i++ ) {
if( allGraphics.get( i ).getBox()[ 0 ].contains( p ) ) {
System.out.println( "Removing graphics object: " + i );
tree.remove( allGraphics.get( i ) );
allGraphics.remove( allGraphics.get( i ) );
break;
}
}
}
delta = curTime - prevTime;
prevTime = curTime;
curTime = System.nanoTime() / 1000000;
theWindow.clear();
for( int i = 0; i < allGraphics.size(); i++ ) {
GraphicsObject go = allGraphics.get( i );
Point goP = go.getPoints()[ 0 ];
goP.modify( moveValX[ i ], moveValY[ i ], 0.0 );
if( goP.getRealX() < 0.0 ) {
goP.setX( 5.0 );
moveValX[ i ] = -moveValX[ i ];
}
if( goP.getRealX() > theWindow.getWidth() ) {
goP.setX( theWindow.getWidth() - 5.0 );
moveValX[ i ] = -moveValX[ i ];
}
if( goP.getRealY() < 0.0 ) {
goP.setY( 5.0 );
moveValY[ i ] = -moveValY[ i ];
}
if( goP.getRealY() > theWindow.getHeight() ) {
goP.setY( theWindow.getHeight() - 5.0 );
moveValY[ i ] = -moveValY[ i ];
}
tree.update( go );
/*List< GraphicsObject > list = tree.findColliding( go );
for( GraphicsObject graphics : list ) {