Advertisement
RandomGuy32

what do you want from me java

May 20th, 2016
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.58 KB | None | 0 0
  1. public class RealTimeStrategyThing {
  2.     public static final String version = "0.0.0";
  3.  
  4.     public static void main(String[] args) throws InterruptedException {
  5.         Game.running = true;
  6.         Game.paused = false;
  7.  
  8.         // Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  9.         Rectangle screenSizeWithoutTaskbar = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
  10.  
  11.         Window.width = screenSizeWithoutTaskbar.width;
  12.         Window.height = screenSizeWithoutTaskbar.height - 27; // works for now
  13.  
  14.         Window.x = 0; // I have no idea what works and doesn't work
  15.         Window.y = 0;
  16.  
  17.         Window.mainFrame = new GameFrame("Real Time Strategy Thing v" + RealTimeStrategyThing.version);
  18.         Window.mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  19.  
  20.         Render.mainCanvas = new GameCanvas();
  21.  
  22.         Window.mainFrame.getContentPane().add(Render.mainCanvas);
  23.  
  24.         Window.mainFrame.setResizable(true);
  25.         Render.mainCanvas.setPreferredSize(new Dimension(Window.width, Window.height));
  26.         Window.mainFrame.setResizable(false);
  27.         Window.mainFrame.pack();
  28.         Window.mainFrame.setLocation(Window.x, Window.y);
  29.         Window.mainFrame.setVisible(true);
  30.  
  31.         Window.mainFrame.requestFocus();
  32.         Window.mainFrame.setFocusable(true);
  33.         Window.mainFrame.requestFocusInWindow();
  34.  
  35.         Game.level = new Level(100, 100);
  36.  
  37.         Util.log(Game.level.size);
  38.  
  39.         Game.players.add(new Player("RandomGuy32", 0x0000ff, Civilization.TERRAN, PlayerType.PLAYER, false));
  40.         Game.players.add(new Player("The_Computer", 0xff0000, Civilization.PORPUPAN, PlayerType.PLAYER, true));
  41.  
  42.         Game.players.get(0).units.add(new DebugUnit(Game.players.get(0), new float[] {10f, 10f}));
  43.         Game.players.get(1).units.add(new DebugUnit(Game.players.get(1), new float[] {15f, 15f}));
  44.  
  45.         Game.tick();
  46.     }
  47. }
  48.  
  49. public class Controls extends KeyAdapter {
  50.     public Controls() {
  51.         super();
  52.     }
  53.  
  54.     public void keyPressed(KeyEvent e) {
  55.         if (e.getKeyCode() == Controls.PAUSE) {
  56.             Game.paused = !Game.paused;
  57.         }
  58.  
  59.         if (e.getKeyCode() == Controls.ESCAPE) {
  60.             Util.log("ESC");
  61.             Game.running = false;
  62.         }
  63.  
  64.         if (e.getKeyCode() == Controls.ZERO) {
  65.             Util.log("ZERO");
  66.         }
  67.     }
  68.     public void keyReleased(KeyEvent e) {
  69.  
  70.     }
  71.  
  72.     public static int PAUSE = KeyEvent.VK_PAUSE;
  73.     public static int ESCAPE = KeyEvent.VK_ESCAPE;
  74.     public static int ZERO = KeyEvent.VK_0;
  75. }
  76.  
  77. public class GameCanvas extends JPanel {
  78.     public GameCanvas() {
  79.         super();
  80.  
  81.         setDoubleBuffered(true);
  82.         cursor = this.getMousePosition();
  83.  
  84.         addMouseListener(prepareMouseInput());
  85.         addKeyListener(new Controls());
  86.         setFocusable(true);
  87.     }
  88.  
  89.     public Point cursor;
  90.  
  91.     public MouseAdapter prepareMouseInput() {
  92.         return new MouseAdapter() {
  93.             // this is not acceptable
  94.             public void mouseClicked(MouseEvent e) {
  95.                 if (e.getButton() == MouseEvent.BUTTON1) {
  96.                     // int x = e.getX(), y = e.getY();
  97.                 }
  98.             }
  99.             public void mousePressed(MouseEvent e) {
  100.                 if (e.getButton() == MouseEvent.BUTTON1) {
  101.                     // int x = e.getX(), y = e.getY();
  102.                 }
  103.             }
  104.             public void mouseReleased(MouseEvent e) {
  105.                 if (e.getButton() == MouseEvent.BUTTON1) {
  106.                     // int x = e.getX(), y = e.getY();
  107.                 }
  108.             }
  109.         };
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement