Java version of Shanzhai StarCraft (online multiplayer game available)

From , 3 Years ago, written in Java, viewed 232 times.
URL https://pastebin.vip/view/1ecfb463
  1. package core;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Container;
  5. import java.awt.Font;
  6. import java.awt.Graphics2D;
  7. import java.awt.Point;
  8. import java.awt.RenderingHints;
  9. import java.awt.Toolkit;
  10. import java.awt.image.BufferStrategy;
  11.  
  12. import javax.swing.JComponent;
  13. import javax.swing.JFrame;
  14.  
  15. /**
  16.  * Simple abstract class used for testing. Subclasses should implement the
  17.  * draw() method.
  18.  */
  19. public abstract class GameCore extends JFrame {
  20.  
  21.         protected static final int FONT_SIZE = 10;
  22.  
  23.         private boolean isRunning;
  24.  
  25.         protected JFrame window;
  26.  
  27.         public void stop() {
  28.  
  29.         }
  30.  
  31.         /**
  32.          * Calls init() and gameLoop()
  33.          */
  34.         public void run() {
  35.                 init();
  36.                 gameLoop();
  37.         }
  38.  
  39.         /**
  40.          * Sets full screen mode and initiates and objects.
  41.          */
  42.         public void init() {
  43.  
  44.                 setUndecorated(true);
  45.                 setTitle("JStarCraft");
  46.                 setIconImage(ResourceManager.loadImage("title.png"));
  47.                 setDefaultCloseOperation(EXIT_ON_CLOSE);
  48.                 setSize(800, 600);
  49.                 setVisible(true);
  50.                 setIgnoreRepaint(true);
  51.                 setResizable(false);
  52.                 setFont(new Font("Dialog", Font.PLAIN, FONT_SIZE));
  53.                 setBackground(Color.black);
  54.                 setForeground(Color.white);
  55.                 createBufferStrategy(2);
  56.                 isRunning = true;
  57.                 setCursor(Toolkit.getDefaultToolkit().createCustomCursor(
  58.                                 ResourceManager.loadImage("cur.png"), new Point(0, 0), "cur"));
  59.                 window = getWindow();
  60.                 NullRepaintManager.install();
  61.                 window.setLayout(null);
  62.                 Container contentPane = getWindow().getContentPane();
  63.                 ((JComponent) contentPane).setOpaque(false);
  64.  
  65.         }
  66.  
  67.         /**
  68.          * Runs through the game loop until stop() is called.
  69.          */
  70.         public void gameLoop() {
  71.  
  72.                 BufferStrategy strategy = getBufferStrategy();
  73.                 long startTime = System.currentTimeMillis();
  74.                 long currTime = startTime;
  75.                 while (isRunning) {
  76.  
  77.                         long elapsedTime = System.currentTimeMillis() - currTime;
  78.                         currTime += elapsedTime;
  79.  
  80.                         // update
  81.                         update(elapsedTime);
  82.  
  83.                         // draw the screen
  84.                         Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
  85.                         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  86.                                         RenderingHints.VALUE_ANTIALIAS_ON);
  87.                         g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
  88.                                         RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  89.                         // g.drawImage(ResourceManager.loadImage("background3.jpg"), 0, 33,
  90.                         // null);
  91.                         draw(g);
  92.                         g.dispose();
  93.  
  94.                         if (!strategy.contentsLost()) {
  95.                                 strategy.show();
  96.                         }
  97.  
  98.                         // take a nap
  99.                         try {
  100.                                 Thread.sleep(5);
  101.                         } catch (InterruptedException ex) {
  102.                         }
  103.                 }
  104.         }
  105.  
  106.         /**
  107.          * Updates the state of the game/animation based on the amount of elapsed
  108.          * time that has passed.
  109.          */
  110.         public void update(long elapsedTime) {
  111.                 // do nothing
  112.         }
  113.  
  114.         /**
  115.          * Draws to the screen. Subclasses must override this method.
  116.          */
  117.         public abstract void draw(Graphics2D g);
  118.  
  119.         public JFrame getWindow() {
  120.                 return this;
  121.         }
  122. }
  123.  

Reply to "Java version of Shanzhai StarCraft (online multiplayer game available)"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website