Example #1
0
 public void actionPerformed(ActionEvent action) {
   player.Update();
   viewScreen.CenterOnObject(player.getBoundingBox());
   map.centerOnWorldCoordinates(
       new Point((int) player.getBoundingBox().x, (int) player.getBoundingBox().y));
   collisionManager.handleCollisions();
   this.repaint();
   this.requestFocus();
 }
Example #2
0
  public GamePanel() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gs.getDefaultConfiguration();

    // Create an image that does not support transparency
    backBufferImage =
        gc.createCompatibleImage(
            TopDownShooter_Main.screenWidth, TopDownShooter_Main.screenHeight, Transparency.OPAQUE);
    backBuffer = backBufferImage.getGraphics();

    player = new Player(new Point(750, 750));

    map = Map.getInstance();
    map.loadWorld("World 1");
    viewScreen = ViewScreen.getInstance();
    collisionManager = CollisionManager.getInstance();

    SwingUtilities.invokeLater(
        new Runnable() { // The GUI needs to be added to the JPanel at a later time, since there is
                         // no way to know the size of this panel yet.
          public void run() {
            viewScreen.setSize(
                new Rectangle(
                    new Point(0, 0),
                    new Dimension(
                        GamePanel.this.getWidth(),
                        GamePanel.this
                            .getHeight()))); // Size the ViewScreen to the actual dimensions of the
                                             // viewable area now that we know them
            viewScreen.CenterOnObject(player.getBoundingBox());
          }
        });

    this.setFocusable(true);
    this.addKeyListener(player);

    new Timer(16, this).start(); // Master game timer
  }
Example #3
0
 public void paintEntities() {
   player.Draw(backBuffer, viewScreen.getScreen());
 }
Example #4
0
 public void paintBackground() {
   map.Draw(backBuffer, viewScreen.getScreen());
 }