diff --git a/Meteo_Engine.jar b/Meteo_Engine.jar index 8ff2835..feff0c0 100644 Binary files a/Meteo_Engine.jar and b/Meteo_Engine.jar differ diff --git a/src/sig/Board.java b/src/sig/Board.java index d99627c..5efff10 100644 --- a/src/sig/Board.java +++ b/src/sig/Board.java @@ -12,10 +12,16 @@ public class Board { double max_rise_spd; double max_fall_spd; double[] combo_power_bonus; - public Board(int width, int height, double gravity, double launch_power, double max_rise_spd, double max_fall_spd, + int x,y; + int block_width,block_height; + public Board(int centerX,int centerY,int block_width,int block_height,int boardWidth, int boardHeight, double gravity, double launch_power, double max_rise_spd, double max_fall_spd, double[] combo_power_bonus) { - this.width = width; - this.height = height; + this.x=centerX; + this.y=centerY; + this.block_width=block_width; + this.block_height=block_height; + this.width = boardWidth; + this.height = boardHeight; this.gravity = gravity; this.launch_power = launch_power; this.max_rise_spd = max_rise_spd; @@ -24,7 +30,7 @@ public class Board { this.blockData = new ArrayList(); List initialBlocks = new ArrayList(); - for (int x=0;xTIMEPERTICK) { //Took longer than 1/60th of a second. No sleep. + System.err.println("Frame Drawing took longer than "+TIMEPERTICK+"ns to calculate ("+diff+"ns total)!"); + } else { + try { + long sleepTime = TIMEPERTICK - diff; + long millis = (sleepTime)/1000000; + int nanos = (int)(sleepTime-(((sleepTime)/1000000)*1000000)); + //System.out.println("FRAME DRAWING: Sleeping for ("+millis+"ms,"+nanos+"ns) - "+(diff)+"ns"); + Thread.sleep(millis,nanos); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + }.start(); + + new Thread() { + public void run(){ + while (true) { + long startTime = System.nanoTime(); + runGameLoop(); + long endTime = System.nanoTime(); + long diff = endTime-startTime; + if (diff>TIMEPERTICK) { //Took longer than 1/60th of a second. No sleep. + System.err.println("Main Game Loop took longer than "+TIMEPERTICK+"ns to calculate ("+diff+"ns total)!"); + } else { + try { + long sleepTime = TIMEPERTICK - diff; + long millis = (sleepTime)/1000000; + int nanos = (int)(sleepTime-(((sleepTime)/1000000)*1000000)); + //System.out.println("Sleeping for ("+millis+"ms,"+nanos+"ns) - "+(diff)+"ns"); + Thread.sleep(millis,nanos); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + }.start(); + + f.add(p); + f.setSize(SCREEN_WIDTH,SCREEN_HEIGHT); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setVisible(true); } } \ No newline at end of file diff --git a/src/sig/Panel.java b/src/sig/Panel.java new file mode 100644 index 0000000..6337878 --- /dev/null +++ b/src/sig/Panel.java @@ -0,0 +1,16 @@ +package sig; + +import javax.swing.JPanel; +import java.awt.Graphics; + +public class Panel extends JPanel{ + + Panel() { + this.setSize(Meteo.SCREEN_WIDTH,Meteo.SCREEN_HEIGHT); + } + + public void paintComponent(Graphics g) { + super.paintComponent(g); + g.drawString(Long.toString(Meteo.FRAMECOUNT),0,16); + } +}