Game Engine - Pt.2
Update in progres...
New Classes
Projectile.java
package ceccs;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
public class Projectile extends Circle {
RunNGunApp app;
double x,y,vx,vy, size;
public Projectile(RunNGunApp app, double x0, double y0, double vx0, double vy0){
this.app = app;
x = x0;
y = y0;
vx = vx0;
vy = vy0;
size = 3;
setRadius(size);
setFill(Color.RED);
//add new projectile to list of projectiles
app.projectiles.add(this);
//add to the visual data
app.motionPane.getChildren().add(this);
}
void updatePhysics(){
x += vx;
y += vy;
}
void updateGraphics(){
setLayoutX(x);
setLayoutY(y);
setRadius(size);
}
}
Class Modificaitons & Changes
RunNGunApp.java
//above start() in the class body
ArrayList projectiles;
GameTimer.java
...
//loops were added to the update methods
void updatePhysics(){
app.player.updatePhysics();
for (int i = 0; i < app.projectiles.size(); i++) {
app.projectiles.get(i).updatePhysics();
}
}
void updateGraphics(){
app.player.updateGraphics();
for (int i = 0; i < app.projectiles.size(); i++) {
app.projectiles.get(i).updateGraphics();
}
}
...