Package org.gbcpainter.game.levels

Examples of org.gbcpainter.game.levels.Level


  @NotNull
  @Override
  public Level loadLevel( @NotNull @NonNls final String name ) throws IllegalStateException, LevelNotFoundException, IOException, ParsingFailException {
    checkStartable();
    final Level result;
    try {
      result = doLoading( name );
    } catch ( Exception e ) {
      synchronized (acquireMutex()) {
        failException = e;
View Full Code Here


    new Thread( new Runnable() {
      @Override
      public void run() {
        try {

          final Level result = doLoading( name );
          synchronized (acquireMutex()) {
            loadResult = result;
            setStatus( LOADING_STATUS.SUCCESS );
          }
        } catch ( Exception e ) {
View Full Code Here

  }

  @NotNull
  @Override
  public Level getResult() throws IllegalStateException {
    final Level actualResult;
    synchronized (acquireMutex()) {
      actualResult = this.loadResult;
    }
    if ( actualResult == null ) {
      throw new IllegalStateException();
View Full Code Here

  public synchronized void levelStopped( @NotNull final LevelManager ignored, @NotNull final Level stoppedLevel ) {
    if( this.closing || this.manager == null || this.redrawer == null) {
      return;
    }

    final Level level = getLevel();

    @Nullable
    final Runnable fadeoutAction;

    if ( this.manager.hasFailed() ) {
      /* Errore nel manager del livello */
      this.closing = true;
      fadeoutAction = null;
      stopDrawJob();
      new ErrorDialog( ViewManager.getMainView().getFrame(), LanguageDictionary.ERROR_STRING, LanguageDictionary.ERROR_UPDATING_LEVEL, this.manager.getError() );

      EventQueue.invokeLater( new Runnable() {
        @Override
        public void run() {
          ViewManager.getMainView().swapToMenuView( new MainMenu() );
        }
      } );
    } else if ( level.isWin() ) {
      /* Il giocatore ha vinto il livello */
      this.closing = true;
      final String nextLevel;
      if ( level instanceof CampaignLevel ) {
        nextLevel = ( (CampaignLevel) level ).getNextLevel();
      } else {
        nextLevel = null;
      }

      fadeoutAction = new Runnable() {
        @Override
        public void run() {
          ViewManager.getMainView().swapToMenuView( new LevelWinMenu( nextLevel ) );
        }
      };

    } else if ( ! level.isAlive() && level.isEnded() ) {
      /* Il giocatore ha perso tutte le vite */
      this.closing = true;
      fadeoutAction = new Runnable() {
        @Override
        public void run() {
          ViewManager.getMainView().swapToMenuView( new GameOverMenu( GameHolder.this ) );
        }
      };

    } else if ( ! level.isAlive() ) {
      /* Il giocatore ha perso una vita ma non tutte */
      this.closing = true;
      fadeoutAction = new Runnable() {
        @Override
        public void run() {
          level.restart();
          ViewManager.getMainView().swapToMenuView( new LevelLostMenu( GameHolder.this ) );
        }
      };
    } else {
      fadeoutAction = null;
View Full Code Here

    return null;

  }

  private void drawCore( @NotNull Graphics2D g2d ) throws Exception {
    final Level level = getLevel();
    final Player player = level.getPlayer();
    final Point2D screenPlayerPosition;

    if ( player instanceof AnimatedElement ) {
      final EntityMovementAnimation animation = ( (AnimatedElement) player ).getAnimation();
      Point2D animationPosition;
      if ( animation != null ) {
        try {
          animationPosition = animation.getActualPosition();
        } catch ( TerminatedAnimationException e ) {
          animationPosition = player.getPosition();
        }

      } else {
        animationPosition = player.getPosition();
      }


      screenPlayerPosition = GraphicsEnv.getInstance().centeredGamePointToScreen( animationPosition );


    } else {
      screenPlayerPosition = GraphicsEnv.getInstance().centeredGamePointToScreen( player.getPosition() );
    }

    int actualGamePointSize = GraphicsEnv.getInstance().getScaledPointDimension();
    double screenMaxLateralSize = actualGamePointSize * MAX_LATERAL_SPACE;
    final Rectangle2D gameScreenBounds = new Rectangle2D.Double( ( this.levelBounds.x * actualGamePointSize ) - screenMaxLateralSize,
                                                                 ( this.levelBounds.y * actualGamePointSize ) - screenMaxLateralSize,
                                                                 ( this.levelBounds.width * actualGamePointSize ) + ( screenMaxLateralSize * 2 ),
                                                                 ( this.levelBounds.height * actualGamePointSize ) + ( screenMaxLateralSize * 2 ) );
    final Rectangle clipBounds = g2d.getClipBounds();
    final Rectangle2D gameScreen = new Rectangle2D.Double( screenPlayerPosition.getX() - ( clipBounds.width / 2 ),
                                                           screenPlayerPosition.getY() - ( clipBounds.height / 2 ),
                                                           clipBounds.width, clipBounds.height );

    if ( ! gameScreenBounds.contains( gameScreen ) ) {

      if ( gameScreen.getWidth() < gameScreenBounds.getWidth() ) {
        if ( gameScreen.getMaxX() > gameScreenBounds.getMaxX() ) {
          gameScreen.setFrame( gameScreen.getX() - ( gameScreen.getMaxX() - gameScreenBounds.getMaxX() ),
                               gameScreen.getY(),
                               gameScreen.getWidth(),
                               gameScreen.getHeight() );
        }

        if ( gameScreen.getMinX() < gameScreenBounds.getMinX() ) {
          gameScreen.setFrame( gameScreenBounds.getMinX(), gameScreen.getMinY(), gameScreen.getWidth(), gameScreen.getHeight() );
        }
      } else {
        gameScreen.setFrame( gameScreenBounds.getCenterX() - ( gameScreen.getWidth() / 2 ), gameScreen.getMinY(),
                             gameScreen.getWidth(), gameScreen.getHeight() );
      }

      if ( gameScreen.getHeight() < gameScreenBounds.getHeight() ) {
        if ( gameScreen.getMaxY() > gameScreenBounds.getMaxY() ) {
          gameScreen.setFrame( gameScreen.getX(),
                               gameScreen.getY() - ( gameScreen.getMaxY() - gameScreenBounds.getMaxY() ),
                               gameScreen.getWidth(),
                               gameScreen.getHeight() );
        }

        if ( gameScreen.getMinY() < gameScreenBounds.getMinY() ) {
          gameScreen.setFrame( gameScreen.getMinX(), gameScreenBounds.getMinY(), gameScreen.getWidth(), gameScreen.getHeight() );
        }
      } else {
        gameScreen.setFrame( gameScreenBounds.getMinX(), gameScreenBounds.getCenterY() - ( gameScreen.getHeight() / 2 ),
                             gameScreen.getWidth(), gameScreen.getHeight() );
      }

    }
    g2d.translate( - gameScreen.getX(), - gameScreen.getY() );


    for (Map.Entry<Face, Integer> faceEntry : this.faces.entrySet()) {
      final Face face = faceEntry.getKey();
      face.setColored( level.isFaceColored( faceEntry.getValue() ) );
      face.draw( g2d );
    }

    for (Pipe pipe : level.getMap().edgeSet()) {
      pipe.draw( g2d );
    }

    for (Junction junction : level.getMap().vertexSet()) {
      junction.draw( g2d );
    }

    for (Monster mob : level.getMonsters()) {
      mob.draw( g2d );
    }

    player.draw( g2d ) ;
  }
View Full Code Here

  }

  private void drawScore( @NotNull Graphics2D g2d ) throws Exception {
    final Rectangle clipBounds = getComponentRect( COMPONENTS.SCORE_VIEW );
    assert clipBounds != null;
    final Level level = getLevel();
    assert level instanceof ScoreLevel;

    g2d.setFont( GraphicsEnv.getInstance().getScoreFont() );
    g2d.setColor( Color.GREEN );
    g2d.drawString( "" + ( (ScoreLevel) level ).getScore(), clipBounds.x, clipBounds.y + clipBounds.height - 1 );
View Full Code Here

  }

  private void drawLives( @NotNull Graphics2D g2d ) throws Exception {
    final Rectangle clipBounds = getComponentRect( COMPONENTS.LIVES_VIEW );
    assert clipBounds != null;
    final Level level = getLevel();
    assert level instanceof LivesLevel;

    g2d.setFont( GraphicsEnv.getInstance().getScoreFont() );
    g2d.setColor( Color.RED );
    g2d.drawString( "" + ( (LivesLevel) level ).getActualLives(), clipBounds.x, clipBounds.y + clipBounds.height - 1 );
View Full Code Here

                                            .gameRectangleToActualScreen(
                                                this.levelBounds );
    final Point screenCenter = new Point( (int) screenBounds.getCenterX() ,
                                          (int) screenBounds.getCenterY() );
    g2d.translate( - screenCenter.x/2, - screenCenter.y/2 );
    final Level level = getLevel();
    final Player player = level.getPlayer();

    for (Map.Entry<Face, Integer> faceEntry : this.faces.entrySet()) {
      final Face face = faceEntry.getKey();
      face.setColored( level.isFaceColored( faceEntry.getValue() ) );
      face.draw( g2d );
    }

    for (Pipe pipe : level.getMap().edgeSet()) {
      pipe.draw( g2d );
    }

    for (Junction junction : level.getMap().vertexSet()) {
      junction.draw( g2d );
    }

    for (Monster mob : level.getMonsters()) {
      mob.draw( g2d );
    }

    player.draw( g2d ) ;
  }
View Full Code Here

    return new Rectangle( windowSize );
  }

  protected boolean tryCreateFaces() {
    try {
      final Level level = getLevel();
      Map<Set<Pipe>, Integer> facesMap = level.getFacesMap();
      UnmodifiableUndirectedGraph<Junction, Pipe> levelMap = level.getMap();
      faces = new HashMap<>( facesMap.size() );

      for (Map.Entry<Set<Pipe>, Integer> faceAndId : facesMap.entrySet()) {
      /* Per ogni faccia ... */
        Pipe firstPipe = faceAndId.getKey().iterator().next();
View Full Code Here

TOP

Related Classes of org.gbcpainter.game.levels.Level

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.