You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
37 lines
1.2 KiB
package controller;
|
|
|
|
|
|
import playground.Playground;
|
|
import org.apache.logging.log4j.Logger;
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
/**
|
|
* This class controls the space invaders.
|
|
*/
|
|
public class EnemyController extends ObjectController {
|
|
|
|
private static Logger logger = LogManager.getLogger(EnemyController.class);
|
|
|
|
@Override
|
|
public void updateObject() {
|
|
logger.trace("updatre" + gameObject.getId());
|
|
if ((gameObject.getX() > this.getPlayground().getSizeX() * 0.9) && (gameObject.getVX() > 0)) {
|
|
logger.trace("toleft!" + gameObject.getX());
|
|
gameObject.setVX(-this.getVX());
|
|
}
|
|
if ((gameObject.getX() < this.getPlayground().getSizeX() * 0.1) && (gameObject.getVX() < 0)) {
|
|
logger.trace("toright!" + gameObject.getX());
|
|
gameObject.setVX(-this.getVX());
|
|
}
|
|
|
|
// if it reaches the bottom, delete it and deduct points
|
|
if (gameObject.getY() >= this.getPlayground().getSizeY()) {
|
|
this.getPlayground().deleteObject(gameObject.getId());
|
|
// add to points counter
|
|
Integer pts = (Integer) Playground.getGlobalFlag("points");
|
|
Playground.setGlobalFlag("points", pts - 200);
|
|
}
|
|
|
|
applySpeedVector();
|
|
}
|
|
}
|