-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
760 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
part14-Part14_09.Asteroids/src/main/java/asteroids/Asteroid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package asteroids; | ||
|
||
import java.util.Random; | ||
import javafx.scene.shape.Polygon; | ||
|
||
|
||
|
||
public class Asteroid extends Character{ | ||
|
||
private double rotationalMovement; | ||
|
||
public Asteroid(int x, int y){ | ||
super(new PolygonFactory().createPolygon(), x, y); | ||
|
||
Random rnd = new Random(); | ||
|
||
super.getCharacter().setRotate(rnd.nextInt(360)); | ||
|
||
int accelerationAmount = 1 + rnd.nextInt(10); | ||
for (int i = 0; i < accelerationAmount; i++){ | ||
accelerate(); | ||
} | ||
|
||
this.rotationalMovement = 0.5 - rnd.nextDouble(); | ||
} | ||
|
||
@Override | ||
public void move(){ | ||
super.move(); | ||
super.getCharacter().setRotate(super.getCharacter().getRotate() + rotationalMovement); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.