hello!
For this game i need to remove the bullets when they reach the end. now they just stop at the edge.
I work with the model-view-controller method.
This is the Bullet class: (Kogel = bullet)
The controller Class:
The bulletView Class:
public class Kogel {
private double x;
private double y;
private String richting;
//private boolean kogelInVeld;
private static final int SNELHEID = 5;
private static final int BREEDTE = 30; //breedte van de Shooter
/**
* @param x de x-coordinaat van de kogel
* @param y de y coordinaat van de kogel
*/
public Kogel(double x, double y, String richting) {
this.richting = richting;
switch (richting) {
case "l":
this.y = y + BREEDTE / 2;
this.x = x;
break;
case "r":
this.x = x + BREEDTE;
this.y = y + BREEDTE / 2;
break;
case "u":
this.x = x + BREEDTE / 2;
this.y = y;
break;
default:
this.x = x + BREEDTE / 2;
this.y = y + BREEDTE;
break;
}
}
/**
*
* @return the x
*/
public double getX() {
return x;
}
/**
* @return the y
*/
public double getY() {
return y;
}
public boolean checkKogelInVeld() {
return (this.x <= 940 && this.x >= 10 && this.y <= 735 && this.y >= 10);
}
// move bullet
public void tick() {
if (checkKogelInVeld()) {
switch (richting) {
case "l":
this.x -= SNELHEID;
break;
case "r":
this.x += SNELHEID;
break;
case "u":
this.y -= SNELHEID;
break;
case "d":
this.y += SNELHEID;
break;
}
} else {
// TODO: remove bullet
}
}
}
private Kogel model;
public static final int STRAAL = 5;
public KogelView(Kogel model) {
this.model = model;
update();
}
public void update() {
getChildren().clear();
Circle kogel = new Circle (model.getX(), model.getY(), STRAAL);
kogel.setFill(Color.RED);
getChildren().add(kogel);
}

