basic drawing engine

concurrentModificationException1
sigonasr2, Sig, Sigo 3 years ago
parent 808a3c58bb
commit d0fbfb812f
  1. BIN
      Meteo_Engine.jar
  2. 14
      src/sig/Board.java
  3. 72
      src/sig/Meteo.java
  4. 16
      src/sig/Panel.java

Binary file not shown.

@ -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<BlockClump>();
List<Block> initialBlocks = new ArrayList<Block>();
for (int x=0;x<width;x++) {
for (int x=0;x<boardWidth;x++) {
for (int y=0;y<3;y++) {
initialBlocks.add(new Block(x,y));
}

@ -1,8 +1,78 @@
package sig;
import javax.swing.JFrame;
public class Meteo {
public final static int SCREEN_WIDTH=640;
public final static int SCREEN_HEIGHT=640;
public static long FRAMECOUNT=0;
public static JFrame f;
public static Board b;
public final static long TIMEPERTICK = 16666667l;
public static void runGameLoop() {
FRAMECOUNT++;
}
public static void main(String[] args) {
double[] val = {0,0,};
Board b = new Board(8,14,0.05,1,4,1,val);
b = new Board(SCREEN_WIDTH/2,SCREEN_HEIGHT/2,16,16,8,14,0.05,1,4,1,val);
JFrame f = new JFrame("Meteo Engine");
Panel p = new Panel();
new Thread() {
public void run(){
while (true) {
long startTime = System.nanoTime();
p.repaint();
long endTime = System.nanoTime();
long diff = endTime-startTime;
if (diff>TIMEPERTICK) { //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);
}
}

@ -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);
}
}
Loading…
Cancel
Save