I’m using Macbook Pro 13" (Early 2011 Model) and Here’s my code:
public void RunIt(){
final int FRAMES_PER_SECOND = 50;
final int SKIP_TICKS = 1000 / FRAMES_PER_SECOND;
long next_game_tick = System.currentTimeMillis();;
long sleep_time = 0;
while(true){
gameUpdate();
next_game_tick += SKIP_TICKS;
sleep_time = next_game_tick - System.currentTimeMillis();
if( sleep_time >= 0 ) {
try { Thread.sleep(sleep_time); } catch (InterruptedException e) { }
}
else { }
}
}
public void gameUpdate(){
//Background Animation Control
for (int i=0; i< backgnd.size(); i++){
if(((Background) backgnd.get(i)).getY()<cont.getHeight()){
((Background) backgnd.get(i)).move();
}
else{
backgnd.add(new Background(0, -((Background) backgnd.get(i)).getImg().getHeight(cont) ));
backgnd.remove(i);
}
}
//Cloud Animation Control
for (int i=0; i< clouds.size(); i++){
if(((Cloud) clouds.get(i)).getY()<cont.getHeight()){
((Cloud) clouds.get(i)).move();
}
else{
clouds.add(new Cloud((int)(Math.random()*getWidth()), -(int)(Math.random()*getWidth())));
clouds.remove(i);
}
}
//High Cloud Animation Control
for (int i=0; i< highclouds.size(); i++){
if(((HighCloud) highclouds.get(i)).getY()<cont.getHeight()){
((HighCloud) highclouds.get(i)).move();
}
else{
highclouds.add(new HighCloud((int)(Math.random()*getWidth()), -(int)(Math.random()*getWidth())));
highclouds.remove(i);
}
}
//Bullet Speed Control
Rectangle bllt;
Rectangle enmy;
for (int i=0 ; i < bullets.size(); i++){
if (((Bullet) bullets.get(i)).getY()>0){
((Bullet) bullets.get(i)).move();
bllt = ((Bullet) bullets.get(i)).getBounds();
//nested enemy loop
for(int a=0; a < enemies.size(); a++){
enmy = ((Enemy) enemies.get(a)).getBounds();
if(enmy.intersects(bllt)){
bullets.remove(i);
enemies.remove(a);
enemies.add(new Enemy((int)(Math.random()*getWidth()), -(int)(Math.random()*getWidth())));
}
}
}
else {
bullets.remove(i);
}
}
for (int i=0; i< enemies.size(); i++){
if(((Enemy) enemies.get(i)).getY()<cont.getHeight()){
((Enemy) enemies.get(i)).move();
}
else{
enemies.add(new Enemy((int)(Math.random()*getWidth()), -(int)(Math.random()*getWidth())));
enemies.remove(i);
}
}
//----
//Ship Coordinating
if(pressleft == true){
ship.moveLeft();
}
if(pressright == true){
ship.moveRight();
}
if(pressup == true){
ship.moveUp();
}
if(pressdown == true){
ship.moveDown();
}
if(pressx == true){
}
repaint();
}