예제 #1
0
 private void paintBullets(Graphics g) {
   if (landscape.getBullets() == null) {
     return;
   }
   for (BulletInterface b : landscape.getBullets()) {
     g.drawImage(imgBullet, b.getX(), b.getY(), b.getWidth(), b.getHeight(), this);
   }
 }
예제 #2
0
 /**
  * Starts Game.
  *
  * @param pTUI - runs parallel TUI if true
  */
 public void startGame(boolean pTUI) {
   getGraphics().drawImage(imgBackground, 0, 0, getWidth(), getHeight(), this);
   if (pTUI) {
     new TUI(landscape);
   }
   landscape.addAnObserver(this);
   action = ACTION_NORMAL;
   up = false;
   right = false;
   left = false;
   shoot = false;
   player.pause(PAUSE_LONG);
   requestFocus();
   landscape.start();
   new Thread() {
     public void run() {
       while (player.getHealth() > 0 && !player.isInGoal()) {
         player.pause(PAUSE_SHORT);
         if (up) {
           action = ACTION_JUMP;
           landscape.jump();
         }
         if (right) {
           action = ACTION_RIGHT;
           landscape.right();
         }
         if (left) {
           action = ACTION_LEFT;
           landscape.left();
         }
         if (shoot) {
           action = ACTION_SHOOT;
           landscape.shoot();
         }
       }
       if (player.isInGoal()) {
         JOptionPane.showMessageDialog(
             gui, "You won!", "Congratulations!", JOptionPane.INFORMATION_MESSAGE);
       } else if (player.getHealth() == 0) {
         JOptionPane.showMessageDialog(gui, "Player died!", "Game over!", JOptionPane.OK_OPTION);
       }
       main.reset();
     }
   }.start();
 }
예제 #3
0
 /**
  * Draws the enemies.
  *
  * @param g - Graphics
  */
 private void paintEnemies(Graphics g) {
   for (EnemyInterface e : landscape.getEnemies()) {
     if (e.isDead()) {
       g.drawImage(imgEnemieDead, e.getX(), e.getY(), e.getWidth(), e.getHeight(), this);
     } else {
       g.drawImage(imgEnemie, e.getX(), e.getY(), e.getWidth(), e.getHeight(), this);
     }
   }
 }
예제 #4
0
  /** Draws all components. (Double buffered) */
  @Override
  public void paint(Graphics g) {
    if (buffer == null) {
      buffer = createVolatileImage(getWidth(), getHeight());
    }
    Graphics bufG = buffer.getGraphics();
    objects = landscape.getVisibleBlocks();
    bufG.drawImage(imgBackground, 0, 0, getWidth(), getHeight(), this);

    paintLandscape(bufG);
    paintEnemies(bufG);
    paintCrates(bufG);
    paintPlayer(bufG);
    paintOverlay(bufG);
    paintBullets(bufG);

    g.drawImage(buffer, 0, 0, this);
  }
예제 #5
0
  /**
   * Creates GUI.
   *
   * @param pMain - Main
   * @param pLandscape - Landscape
   */
  public GUI(final MainMenuGUI pMain, LandscapeInterface pLandscape) {
    landscape = pLandscape;

    player = landscape.getPlayer();
    main = pMain;
    gui = this;

    imgBackground =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/background.png"));
    imgGras =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/gras.jpg"));
    imgPlayerNormal =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/player_normal.gif"));
    imgPlayerJump =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/player_jump.gif"));
    imgPlayerRight =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/player_right.gif"));
    imgPlayerLeft =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/player_left.gif"));
    imgEnemie =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/enemy.gif"));
    imgEnemieDead =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/enemy_dead.png"));
    imgWater =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/water.png"));
    imgHealth =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/health.png"));
    imgCoin =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/coin.png"));
    imgCoinCount =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/coinCount.png"));
    imgGoal =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/goal.png"));
    imgCrate =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/crate.png"));
    imgButtonPressed =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/buttonPressed.png"));
    imgButtonReleased =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/buttonReleased.png"));
    imgGateClosed =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/gateClosed.png"));
    imgGateOpened =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/gateOpened.png"));
    imgBullet =
        Toolkit.getDefaultToolkit()
            .getImage(getClass().getClassLoader().getResource("images/bullet.png"));

    addKeyListener(this);
  }
예제 #6
0
 private void paintCrates(Graphics g) {
   for (BlockInterface c : landscape.getCrates()) {
     g.drawImage(imgCrate, c.getX(), c.getY(), c.getWidth(), c.getHeight(), this);
   }
 }