Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RealTimeStrategyThing {
- public static final String version = "0.0.0";
- public static void main(String[] args) throws InterruptedException {
- Game.running = true;
- Game.paused = false;
- // Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- Rectangle screenSizeWithoutTaskbar = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
- Window.width = screenSizeWithoutTaskbar.width;
- Window.height = screenSizeWithoutTaskbar.height - 27; // works for now
- Window.x = 0; // I have no idea what works and doesn't work
- Window.y = 0;
- Window.mainFrame = new GameFrame("Real Time Strategy Thing v" + RealTimeStrategyThing.version);
- Window.mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Render.mainCanvas = new GameCanvas();
- Window.mainFrame.getContentPane().add(Render.mainCanvas);
- Window.mainFrame.setResizable(true);
- Render.mainCanvas.setPreferredSize(new Dimension(Window.width, Window.height));
- Window.mainFrame.setResizable(false);
- Window.mainFrame.pack();
- Window.mainFrame.setLocation(Window.x, Window.y);
- Window.mainFrame.setVisible(true);
- Window.mainFrame.requestFocus();
- Window.mainFrame.setFocusable(true);
- Window.mainFrame.requestFocusInWindow();
- Game.level = new Level(100, 100);
- Util.log(Game.level.size);
- Game.players.add(new Player("RandomGuy32", 0x0000ff, Civilization.TERRAN, PlayerType.PLAYER, false));
- Game.players.add(new Player("The_Computer", 0xff0000, Civilization.PORPUPAN, PlayerType.PLAYER, true));
- Game.players.get(0).units.add(new DebugUnit(Game.players.get(0), new float[] {10f, 10f}));
- Game.players.get(1).units.add(new DebugUnit(Game.players.get(1), new float[] {15f, 15f}));
- Game.tick();
- }
- }
- public class Controls extends KeyAdapter {
- public Controls() {
- super();
- }
- public void keyPressed(KeyEvent e) {
- if (e.getKeyCode() == Controls.PAUSE) {
- Game.paused = !Game.paused;
- }
- if (e.getKeyCode() == Controls.ESCAPE) {
- Util.log("ESC");
- Game.running = false;
- }
- if (e.getKeyCode() == Controls.ZERO) {
- Util.log("ZERO");
- }
- }
- public void keyReleased(KeyEvent e) {
- }
- public static int PAUSE = KeyEvent.VK_PAUSE;
- public static int ESCAPE = KeyEvent.VK_ESCAPE;
- public static int ZERO = KeyEvent.VK_0;
- }
- public class GameCanvas extends JPanel {
- public GameCanvas() {
- super();
- setDoubleBuffered(true);
- cursor = this.getMousePosition();
- addMouseListener(prepareMouseInput());
- addKeyListener(new Controls());
- setFocusable(true);
- }
- public Point cursor;
- public MouseAdapter prepareMouseInput() {
- return new MouseAdapter() {
- // this is not acceptable
- public void mouseClicked(MouseEvent e) {
- if (e.getButton() == MouseEvent.BUTTON1) {
- // int x = e.getX(), y = e.getY();
- }
- }
- public void mousePressed(MouseEvent e) {
- if (e.getButton() == MouseEvent.BUTTON1) {
- // int x = e.getX(), y = e.getY();
- }
- }
- public void mouseReleased(MouseEvent e) {
- if (e.getButton() == MouseEvent.BUTTON1) {
- // int x = e.getX(), y = e.getY();
- }
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement