Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- public class GameScreen extends JPanel implements Runnable{
- private static final long serialVersionUID = 1L;
- public Thread thread = new Thread(this);
- private int fps = 0;
- public int scene = 0;
- public boolean running = false;
- Frame frame;
- Account account;
- public GameScreen(Frame frame){
- this.frame = frame;
- thread.start();
- Logger.log("Thread Started");
- }
- public void paintComponent(Graphics g){
- g.clearRect(0, 0, this.frame.getWidth(), this.frame.getHeight());
- if(scene == 0){ g.setColor(Color.DARK_GRAY); g.fillRect(0, 0, this.frame.getWidth(), this.frame.getHeight());}
- else if(scene == 1){
- g.setColor(Color.GREEN);
- g.fillRect(0, 0, this.frame.getWidth(), this.frame.getHeight());
- g.setColor(Color.GRAY);
- for(int x = 0; x < 27; x++) {
- for(int y = 0; y < 16; y++){
- double width = (this.frame.getWidth() / (1920.0 / 1350.0)) / 27;
- double height = (this.frame.getHeight() / (1080.0 / 800.0)) / 16;
- g.drawRect(50 + (x * 50), 50 + (y * 50), (int) width, (int) height);
- }
- }
- }
- else {g.setColor(Color.WHITE);g.fillRect(0, 0, this.frame.getWidth(), this.frame.getHeight());}
- g.setColor(Color.YELLOW);
- g.setFont(new Font ("Calibri", Font.PLAIN, 30));
- g.drawString("FPS: " + fps, 5, 25);
- }
- public void loadGame(){
- account = new Account(this);
- running = true;
- }
- public void startGame(Account account){
- account.createPlayer();
- this.scene = 1;
- }
- public void run() {
- loadGame();
- long lastFrame = System.currentTimeMillis();
- int frames = 0;
- this.frame.addKeyListener(new KeyController(this));
- while(running){
- Logger.Update();
- frames++;
- if(System.currentTimeMillis() - 1000 >= lastFrame){
- fps = frames;
- frames = 0;
- lastFrame = System.currentTimeMillis();
- }
- repaint();
- try {
- Thread.sleep(5);
- } catch (Exception e) {
- Logger.logError("CANNOT SLEEP IN GAME LOOP!");
- e.printStackTrace();
- }
- }
- System.exit(0);
- }
- public class KeyTyped{
- public void keyQ(){
- Logger.log("Quitting Game");
- running = false;
- }
- public void keyF11(){
- Frame.devMode = !Frame.devMode;
- if(Frame.devMode) Logger.log("Dev Mode Active");
- else if (!Frame.devMode) Logger.log("Dev Mode Deactivated");
- }
- public void keySPACE(){
- startGame(account);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement