|
|
@ -9,8 +9,6 @@ import java.awt.image.MemoryImageSource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.awt.event.ComponentEvent; |
|
|
|
|
|
|
|
import java.awt.event.ComponentListener; |
|
|
|
|
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
|
|
|
|
|
|
@ -22,7 +20,7 @@ import java.awt.event.KeyListener; |
|
|
|
import sig.DrawLoop; |
|
|
|
import sig.DrawLoop; |
|
|
|
import sig.RabiClone; |
|
|
|
import sig.RabiClone; |
|
|
|
|
|
|
|
|
|
|
|
public class Panel extends JPanel implements Runnable,ComponentListener,KeyListener { |
|
|
|
public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
JFrame window; |
|
|
|
JFrame window; |
|
|
|
public int pixel[]; |
|
|
|
public int pixel[]; |
|
|
|
final int CIRCLE_PRECISION=32; |
|
|
|
final int CIRCLE_PRECISION=32; |
|
|
@ -117,14 +115,14 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void init(){ |
|
|
|
public void init(){ |
|
|
|
cm = getCompatibleColorModel(); |
|
|
|
cm = getCompatibleColorModel(); |
|
|
|
int screenSize = getWidth()*getHeight(); |
|
|
|
int screenSize = RabiClone.BASE_WIDTH*RabiClone.BASE_HEIGHT; |
|
|
|
if(pixel == null || pixel.length < screenSize){ |
|
|
|
if(pixel == null || pixel.length < screenSize){ |
|
|
|
pixel = new int[screenSize]; |
|
|
|
pixel = new int[screenSize]; |
|
|
|
} |
|
|
|
} |
|
|
|
if(thread.isInterrupted() || !thread.isAlive()){ |
|
|
|
if(thread.isInterrupted() || !thread.isAlive()){ |
|
|
|
thread.start(); |
|
|
|
thread.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
mImageProducer = new MemoryImageSource(getWidth(), getHeight(), cm, pixel,0, getWidth()); |
|
|
|
mImageProducer = new MemoryImageSource(RabiClone.BASE_WIDTH, RabiClone.BASE_HEIGHT, cm, pixel,0, RabiClone.BASE_WIDTH); |
|
|
|
mImageProducer.setAnimated(true); |
|
|
|
mImageProducer.setAnimated(true); |
|
|
|
mImageProducer.setFullBufferUpdates(true); |
|
|
|
mImageProducer.setFullBufferUpdates(true); |
|
|
|
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); |
|
|
|
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); |
|
|
@ -138,7 +136,7 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe |
|
|
|
// ask ImageProducer to update image
|
|
|
|
// ask ImageProducer to update image
|
|
|
|
mImageProducer.newPixels(); |
|
|
|
mImageProducer.newPixels(); |
|
|
|
// draw it on panel
|
|
|
|
// draw it on panel
|
|
|
|
g.drawImage(this.imageBuffer, 0, 0, this); |
|
|
|
g.drawImage(this.imageBuffer,0,0,getWidth(),getHeight(),0,0,RabiClone.BASE_WIDTH,RabiClone.BASE_HEIGHT,this); |
|
|
|
updateFPSCounter(); |
|
|
|
updateFPSCounter(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -157,24 +155,10 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public /* abstract */ void render(){ |
|
|
|
public /* abstract */ void render(){ |
|
|
|
resizeUpdate(); |
|
|
|
|
|
|
|
int[] p = pixel; // this avoid crash when resizing
|
|
|
|
|
|
|
|
//a=h/w
|
|
|
|
//a=h/w
|
|
|
|
DrawLoop.drawGame(this); |
|
|
|
DrawLoop.drawGame(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void resizeUpdate() { |
|
|
|
|
|
|
|
if (resizing) { |
|
|
|
|
|
|
|
pixel = new int[getWidth()*getHeight()]; |
|
|
|
|
|
|
|
resizing=false; |
|
|
|
|
|
|
|
mImageProducer = new MemoryImageSource(getWidth(), getHeight(), cm, pixel,0, getWidth()); |
|
|
|
|
|
|
|
mImageProducer.setAnimated(true); |
|
|
|
|
|
|
|
mImageProducer.setFullBufferUpdates(true); |
|
|
|
|
|
|
|
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); |
|
|
|
|
|
|
|
System.out.println("Window resized."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void FillRect(int[] p,Color col,double x,double y,double w,double h) { |
|
|
|
public void FillRect(int[] p,Color col,double x,double y,double w,double h) { |
|
|
|
for (int xx=0;xx<w;xx++) { |
|
|
|
for (int xx=0;xx<w;xx++) { |
|
|
|
for (int yy=0;yy<h;yy++) { |
|
|
|
for (int yy=0;yy<h;yy++) { |
|
|
@ -375,30 +359,6 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe |
|
|
|
frameCount++; |
|
|
|
frameCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentHidden(ComponentEvent e) { |
|
|
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentMoved(ComponentEvent e) { |
|
|
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentResized(ComponentEvent e) { |
|
|
|
|
|
|
|
//COMPONENT_RESIZED (8,564 948x508)
|
|
|
|
|
|
|
|
resizing=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentShown(ComponentEvent e) { |
|
|
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void keyTyped(KeyEvent e) { |
|
|
|
public void keyTyped(KeyEvent e) { |
|
|
|
// TODO Auto-generated method stub
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|