pl/mbogusz3/invaders/view/InvadersView.java
/**
	 * Draw enemy units. Called from update().
	 * @param paneInsets insets of main content pane.
	 * @param paneSize size of main content pane.
	 */
Draw enemy units. Called from update().
@param paneInsets insets of main content pane.
@param paneSize size of main content pane.
Draw enemy units . Called from update () . @param paneInsets insets of main content pane . @param paneSize size of main content pane .
private void drawEnemies(Insets paneInsets, Dimension paneSize) {
		int enemyRows = this.model.getEnemy().getFirstRow() + 1;
		int enemyColumns = this.model.getEnemy().getLastColumn() - this.model.getEnemy().getFirstColumn() + 1;
		if(this.enemies == null) {
			this.enemies = new JLabel[enemyRows][enemyColumns];
			for(int i = 0; i < enemyRows; i++) {
				for(int j = 0; j < enemyColumns; j++) {
					this.enemies[i][j] = new JLabel();
					this.contentPane.add(this.enemies[i][j]);
					this.enemies[i][j].setOpaque(true);
					this.enemies[i][j].setBackground(new Color(0, 0, 0));
				}
			}
		}
		if(!this.model.isGameRunning()) {
			for(int i = 0; i < this.model.getEnemy().getRows(); i++) {
				for(int j = 0; j < this.model.getEnemy().getColumns(); j++) {
					this.enemies[i][j].setVisible(false);
				}
			}
			return;
		}
		double enemyWidth = this.model.getEnemy().getUnitWidth() * paneSize.width;
		double unitPositionTop = this.model.getEnemy().getPositionTop() * paneSize.height + paneInsets.top;
		for(int i = 0; i < enemyRows; i++) {
			double unitPositionLeft = this.model.getEnemy().getPositionLeft() * paneSize.width + paneInsets.left;
			unitPositionLeft -= (enemyColumns - 0.5) * enemyWidth;
			for(int j = 0; j < this.model.getEnemy().getColumns(); j++) {
				if(j < this.model.getEnemy().getFirstColumn() || j > this.model.getEnemy().getLastColumn()) {
					this.enemies[i][j].setVisible(false);
					continue;
				}
				if(this.model.getEnemy().getState()[i][j]) {
					this.enemies[i][j].setVisible(true);
					this.enemies[i][j].setBounds((int)(unitPositionLeft), (int)(unitPositionTop), (int)(enemyWidth), (int)(0.05 * paneSize.height));
				} else {
					this.enemies[i][j].setVisible(false);
				}
				unitPositionLeft += 2 * enemyWidth;
			}
			unitPositionTop += 0.1 * paneSize.height;
		}
		for(int i = enemyRows; i < this.model.getEnemy().getRows(); i++) {
			for(int j = 0; j < this.model.getEnemy().getColumns(); j++) {
				this.enemies[i][j].setVisible(false);
			}
		}
	}
private void drawEnemies ( Insets paneInsets , Dimension paneSize ) { int enemyRows = this . model . getEnemy ( ) . getFirstRow ( ) + 1 ; int enemyColumns = this . model . getEnemy ( ) . getLastColumn ( ) - this . model . getEnemy ( ) . getFirstColumn ( ) + 1 ; if ( this . enemies == null ) { this . enemies = new JLabel [ enemyRows ] [ enemyColumns ] ; for ( int i = 0 ; i < enemyRows ; i ++ ) { for ( int j = 0 ; j < enemyColumns ; j ++ ) { this . enemies [ i ] [ j ] = new JLabel ( ) ; this . contentPane . add ( this . enemies [ i ] [ j ] ) ; this . enemies [ i ] [ j ] . setOpaque ( true ) ; this . enemies [ i ] [ j ] . setBackground ( new Color ( 0 , 0 , 0 ) ) ; } } } if ( ! this . model . isGameRunning ( ) ) { for ( int i = 0 ; i < this . model . getEnemy ( ) . getRows ( ) ; i ++ ) { for ( int j = 0 ; j < this . model . getEnemy ( ) . getColumns ( ) ; j ++ ) { this . enemies [ i ] [ j ] . setVisible ( false ) ; } } return ; } double enemyWidth = this . model . getEnemy ( ) . getUnitWidth ( ) * paneSize . width ; double unitPositionTop = this . model . getEnemy ( ) . getPositionTop ( ) * paneSize . height + paneInsets . top ; for ( int i = 0 ; i < enemyRows ; i ++ ) { double unitPositionLeft = this . model . getEnemy ( ) . getPositionLeft ( ) * paneSize . width + paneInsets . left ; unitPositionLeft -= ( enemyColumns - 0.5 ) * enemyWidth ; for ( int j = 0 ; j < this . model . getEnemy ( ) . getColumns ( ) ; j ++ ) { if ( j < this . model . getEnemy ( ) . getFirstColumn ( ) || j > this . model . getEnemy ( ) . getLastColumn ( ) ) { this . enemies [ i ] [ j ] . setVisible ( false ) ; continue ; } if ( this . model . getEnemy ( ) . getState ( ) [ i ] [ j ] ) { this . enemies [ i ] [ j ] . setVisible ( true ) ; this . enemies [ i ] [ j ] . setBounds ( ( int ) ( unitPositionLeft ) , ( int ) ( unitPositionTop ) , ( int ) ( enemyWidth ) , ( int ) ( 0.05 * paneSize . height ) ) ; } else { this . enemies [ i ] [ j ] . setVisible ( false ) ; } unitPositionLeft += 2 * enemyWidth ; } unitPositionTop += 0.1 * paneSize . height ; } for ( int i = enemyRows ; i < this . model . getEnemy ( ) . getRows ( ) ; i ++ ) { for ( int j = 0 ; j < this . model . getEnemy ( ) . getColumns ( ) ; j ++ ) { this . enemies [ i ] [ j ] . setVisible ( false ) ; } } }
Draw enemy units.
Draw enemy units .
// First time init of enemies