public class INTERFACE extends Canvas implements KeyListener, MouseListener
{
private static final long serialVersionUID = 1L;
static int _x;
static int _y;
static int _c;
static Font fontMenue;
static Font fontSpiel;
static Font fontKlein;
static BufferStrategy _strategy;
static Graphics2D g;
static Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
static HashSet<Punkt> _punkteToRepaint = new HashSet<Punkt>();
static HashSet<Point> _pointsToRepaint = new HashSet<Point>();
static BufferedImage _bimage;
public INTERFACE()
{
setUpGraphics();
requestFocus();
addKeyListener(this);
addMouseListener(this);
}
private void setUpGraphics()
{
_x = dim.width;
_y = dim.height;
int menue = _x * _y / 50000;
int spiel = _x * _y / 20000;
int klein = _x * _y / 96000;
int k = _x * _y;
_c = k / 19200;
fontMenue = new Font("Sans Serif", 0, menue);
fontSpiel = new Font("Sans Serif", 0, spiel);
fontKlein = new Font("Sans Serif", 0, klein);
JFrame container = new JFrame("Achtung, die Kurve");
container.setCursor(getToolkit().createCustomCursor(new ImageIcon("").getImage(), new Point(0, 0), "No Cursor"));
JPanel panel = (JPanel) container.getContentPane();
panel.setPreferredSize(new Dimension(_x, _y));
panel.setBackground(Color.BLACK);
panel.setLayout(null);
setBounds(0, 0, _x, _y);
panel.add(this);
container.setUndecorated(true);
setIgnoreRepaint(true);
container.pack();
container.setResizable(false);
container.setVisible(true);
createBufferStrategy(2);
_strategy = getBufferStrategy();
}
static void zeichne(Point a, Color c)
{
g = (Graphics2D) _strategy.getDrawGraphics();
g.setColor(c);
g.fillRect(a.x, a.y, 1, 1);
g.dispose();
_strategy.show();
}
private static void ueberZeichnen()
{
g = (Graphics2D) _strategy.getDrawGraphics();
ArrayList<Point> loeschen = new ArrayList<Point>();
for (Point p : _pointsToRepaint)
{
try
{
g.setColor(SPIELFELD.gibFarbeAn(p.x, p.y));
g.setColor(Color.black);
g.fillRect(p.x, p.y, 1, 1);
loeschen.add(p);
}
catch (Exception e)
{
loeschen.add(p);
}
}
_pointsToRepaint.removeAll(loeschen);
}
static void zeichneIntro()
{
g = (Graphics2D) _strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, _x, _y);
g.dispose();
_strategy.show();
sleep(500);
for (Spieler s : Spiel._spieler)
{
g = (Graphics2D) _strategy.getDrawGraphics();
g.setColor(s.gibFarbe());
for (Punkt p : s.gibPlatz())
{
g.fillRect(p.x, p.y, 1, 1);
}
g.dispose();
_strategy.show();
sleep(600);
}
}
static void zeichneGlowEffekt(Spieler s)
{
int groeße1 = 12;
int groeße2 = 9;
int helligkeit = 2;
g.setColor(new Color(s.gibFarbe().getRed(), s.gibFarbe().getGreen(), s.gibFarbe().getBlue(), (int) (helligkeit * 6)));
g.fillRect((int) s._x - groeße1, (int) s._y - groeße1, groeße1 * 2 + 1, groeße1 * 2 + 1);
g.setColor(new Color(s.gibFarbe().getRed(), s.gibFarbe().getGreen(), s.gibFarbe().getBlue(), (int) (helligkeit * 8)));
g.fillRect((int) s._x - groeße2, (int) s._y - groeße2, groeße2 * 2 + 1, groeße2 * 2 + 1);
}
public static void zeichneFrame()
{
ueberZeichnen();
g = (Graphics2D) _strategy.getDrawGraphics();
for (Spieler s : Spiel._spieler)
{
g.setColor(s.gibFarbe());
if (s.springt())
{
for (Punkt p : s.gibPlatz())
{
g.fillRect(p.x, p.y, 1, 1);
_pointsToRepaint.add(new Point(p.x, p.y));
}
}
else
{
for (Punkt p : s.gibPlatz())
{
g.fillRect(p.x, p.y, 1, 1);
}
if (s.lebt())
{
zeichneGlowEffekt(s);
}
}
}
g.dispose();
_strategy.show();
}
}