-
Notifications
You must be signed in to change notification settings - Fork 1
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
2 changed files
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
public class Star | ||
{ | ||
private Ball b; | ||
private double speedX; | ||
private double speedY; | ||
|
||
private double startX; | ||
private double startY; | ||
|
||
private GameArena arena; | ||
|
||
public Star(double x, double y, double size, String colour, double speedX, double speedY, GameArena a) | ||
{ | ||
this.startX = x; | ||
this.startY = y; | ||
this.speedX = speedX; | ||
this.speedY = speedY; | ||
this.arena = a; | ||
|
||
b = new Ball(x, y, size, colour); | ||
} | ||
|
||
public void addTo(GameArena a) | ||
{ | ||
a.addBall(b); | ||
} | ||
|
||
public void move() | ||
{ | ||
b.move(speedX, speedY); | ||
|
||
// Check bounds within the given GameArena | ||
if (b.getXPosition() > arena.getArenaWidth() || b.getXPosition() < 0 || b.getYPosition() > arena.getArenaHeight() || b.getYPosition() < 0) | ||
{ | ||
b.setXPosition(startX); | ||
b.setYPosition(startY); | ||
} | ||
} | ||
} |
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,45 @@ | ||
/** | ||
* A class to represent a simple starfield effect. | ||
* A cnfigurable number of stars appear in the centre of the screen, | ||
* and move outward to the edges in a randome direction. | ||
*/ | ||
|
||
public class Starfield | ||
{ | ||
private Star[] stars; | ||
private Ball horizon; | ||
private int numberOfStars; | ||
private double effectDepth = 1.0; | ||
private double effectSpeed = 1.0; | ||
private double starSize = 3; | ||
private String starColour = "#DDDDDD"; | ||
|
||
private GameArena arena; | ||
|
||
/** | ||
* Constructor. Creates a Ball with the given parameters. | ||
* @param numberOfStars The number of stars that should be on screen at any point in time | ||
* @param speed The spparent speed of the effect - higher numbers are faster. | ||
*/ | ||
public Starfield(int numberOfStars, double speed, GameArena a) | ||
{ | ||
stars = new Star[numberOfStars]; | ||
this.effectSpeed = speed; | ||
this.arena = a; | ||
|
||
for (int i=0; i<stars.length; i++) | ||
{ | ||
stars[i] = new Star(arena.getWidth()/2, arena.getHeight()/2, starSize, starColour, speed * (0.5 - Math.random()), speed * (0.5 - Math.random()), arena); | ||
stars[i].addTo(a); | ||
} | ||
|
||
horizon = new Ball(arena.getWidth()/2, arena.getHeight()/2, 20, "BLACK"); | ||
arena.addBall(horizon); | ||
} | ||
|
||
public void move() | ||
{ | ||
for (int i=0; i<stars.length; i++) | ||
stars[i].move(); | ||
} | ||
} |