import java.awt.BufferCapabilities;
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferStrategy;
import java.text.NumberFormat;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
/*
* Created on Jun 7, 2003
*/
/**
* @author scottpalmer
*
*/
public class VectorCollector implements KeyListener
{
static
{ // stuff for debugging mac version
//System.setProperty("apple.awt.fakefullscreen", "true");
}
private static DisplayMode[] BEST_DISPLAY_MODES =
new DisplayMode[] {
new DisplayMode(640, 480, 32, 0),
new DisplayMode(640, 480, 16, 0),
new DisplayMode(640, 480, 8, 0)
};
private Rectangle bounds;
private boolean gameOn = true;
private int fpsTick = 0;
private double FAC = 1.0;
private int tick = 0;
private int ctick = 0; // corrected tick
private long tickTime = 0;
private String msg = null;
private String fpsS = "";
private double fps = 0;
static int keyRot = 0;
private int shipRot = 0;
private double shipAngle = 0;
private double shipVelX = 0;
private double shipVelY = 0;
private double shipX = 0;
private double shipY = 0;
private int lives = 5;
private String livesS = "5";
private Collection treasureBag;
private int worldX = 0;
private int worldY = 0;
private static double ACCEL = 0.55;
private static double GRAVITY = 0.075;
private static double TERMINAL_VELOCITY = 50;
private static final double RF = Math.PI/8; // 16 possible ship angles 2*PI/16
// for AWT keyboard "polling" TODO use JInput
private boolean thrust = false;
private boolean left = false;
private boolean right = false;
private boolean space = false;
private VCLevel level = new DefaultLevel();
private Shape keyShape = new Polygon(
new int [] { -8,-8,-4,-4, 8,8,7,7,6,6,5,5,4,4,3,3,-4,-4},
new int [] { 2,-2,-2,-1,-1,2,2,0,0,2,2,1,1,2,2,0, 0, 2},
18 );
protected static Shape [] rotKeys = new Shape[16];
private Shape shipShape = new Polygon(
new int [] { -3, 0, 3 },
new int [] { 5,-5, 5 }, 3);
private Shape thrustShape = new Polygon(
new int [] { -2, 0, 2 },
new int [] { 5, 10, 5 }, 3 );
private int score = 0;
private String scoreS = "0";
Frame mainFrame;
public VectorCollector(int numBuffers, GraphicsDevice device, boolean doFullScreen)
{
computeRotatedKeyShapes();
GraphicsConfiguration gc = device.getDefaultConfiguration();
mainFrame = new Frame(gc) {
public void paint(Graphics g){}
public void update(Graphics g){} };
mainFrame.setIgnoreRepaint(true);
if ( doFullScreen && device.isFullScreenSupported())
{
mainFrame.setUndecorated(true);
device.setFullScreenWindow(mainFrame);
if (device.isDisplayChangeSupported())
{
chooseBestDisplayMode(device);
mainFrame.setBounds(0,0,640,480);
}
}
else
{
mainFrame.setBounds(0,0,640,480);
mainFrame.show();
}
mainFrame.createBufferStrategy(numBuffers);
mainFrame.addKeyListener( this );
// Debug info
BufferCapabilities bc = gc.getBufferCapabilities();
System.out.println("BufferCapabilities");
System.out.println(" isFullScreenRequired:"+bc.isFullScreenRequired());
System.out.println(" isMultiBufferAvailable:"+bc.isMultiBufferAvailable());
System.out.println(" isPageFlipping:"+bc.isPageFlipping());
}