pl/mbogusz3/invaders/model/Enemy.java
/**
	 * Decide whether to shoot and if so return the shot projectile.
	 * @param time time for which to calculate probability of shooting (fraction of second).
	 * @return {@link Projectile} or null.
	 */
Decide whether to shoot and if so return the shot projectile.
@param time time for which to calculate probability of shooting (fraction of second).
@return  Projectile or null.
Decide whether to shoot and if so return the shot projectile . @param time time for which to calculate probability of shooting ( fraction of second ) . @return Projectile or null .
@Nullable
	public Projectile shoot(double time) {
		if(this.randomGenerator.nextDouble() > (Enemy.shotProbability * time)) {
			return null;
		}
		int shootingColumn;
		if(this.lastColumn > this.firstColumn) {
			shootingColumn = this.randomGenerator.nextInt(this.lastColumn - this.firstColumn) + this.firstColumn;
		} else {
			shootingColumn = this.firstColumn;
		}
		int shootingRow;
		for(shootingRow = this.firstRow; shootingRow >= 0; shootingRow--) {
			if(this.state[shootingRow][shootingColumn]) {
				break;
			}
		}
		if(shootingRow < 0) {
			return null;
		}
		double x = this.positionLeft + (2 * shootingColumn - this.lastColumn + this.firstColumn) * this.unitWidth;
		double y = (2 * shootingRow + 1) * Enemy.unitHeight + this.positionTop;
		return new Projectile(x, y, 1, 0.3);
	}
@ Nullable public Projectile shoot ( double time ) { if ( this . randomGenerator . nextDouble ( ) > ( Enemy . shotProbability * time ) ) { return null ; } int shootingColumn ; if ( this . lastColumn > this . firstColumn ) { shootingColumn = this . randomGenerator . nextInt ( this . lastColumn - this . firstColumn ) + this . firstColumn ; } else { shootingColumn = this . firstColumn ; } int shootingRow ; for ( shootingRow = this . firstRow ; shootingRow >= 0 ; shootingRow -- ) { if ( this . state [ shootingRow ] [ shootingColumn ] ) { break ; } } if ( shootingRow < 0 ) { return null ; } double x = this . positionLeft + ( 2 * shootingColumn - this . lastColumn + this . firstColumn ) * this . unitWidth ; double y = ( 2 * shootingRow + 1 ) * Enemy . unitHeight + this . positionTop ; return new Projectile ( x , y , 1 , 0.3 ) ; }
Decide whether to shoot and if so return the shot projectile.
Decide whether to shoot and if so return the shot projectile .
// shooting probability // Decide which column is to shoot, then check whether any unit exists in that column // Calculate projectile's position (here: shooting enemy unit's position) // Return the new projectile, flying down (increasing Y position)