package net.devox.basic;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
/*
* Title: Game
* Version: 1.0.0
* Desc: This class is used to control and pack together the
* methods required to run the games logic in a central
* location.
*/
public class Game extends Canvas
{
//buffer for off screen drawing
private BufferedImage buffer;
private static final long serialVersionUID = 1L;
private void init()
{
//turn paint off
this.setIgnoreRepaint(true);
//set size
this.setSize(GUI.WIDTH, GUI.HEIGHT);
//set Focusable
this.setFocusable(true);
//create buffer
buffer = new BufferedImage(GUI.WIDTH, GUI.HEIGHT, BufferedImage.TYPE_INT_ARGB);
}
public void start()
{
//initialize game
this.init();
//start loop
while(true){
try{
this.update();
this.drawbuffer();
this.drawscreen();
}catch(Exception e){e.printStackTrace(); Main.close();}
}
}
private void update()
{
return;
}
private void drawbuffer()
{
//set buffer
Graphics buff = buffer.createGraphics();
//do drawing logic
drawrect(buff, 10, 10, 10, 10);
//clear buffer
buff.dispose();
}
private void drawscreen()
{
Graphics2D g2d = (Graphics2D)getGraphics();
// Render Buffer to Screen
g2d.drawImage(buffer, 0, 0, this);
Toolkit.getDefaultToolkit().sync();
// Dispose of Graphics2D
g2d.dispose();
}
//Generic render method. Change this.
private void drawrect(Graphics buff, int x, int y, int width, int height)
{
buff.setColor(Color.BLACK);
buff.drawRect(x, y, width, height);
}
}