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.
84 lines
2.5 KiB
84 lines
2.5 KiB
package playground;
|
|
|
|
import gameobjects.GameObject;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
import gameobjects.RectObject;
|
|
import gameobjects.TextObject;
|
|
|
|
import java.awt.Color;
|
|
|
|
import collider.RectCollider;
|
|
import controller.LimitedTimeController;
|
|
import controller.ReboundController;
|
|
|
|
/**
|
|
* Level that creates two RectObjects moving around and if ego is hit by them game is directly lost
|
|
* (lives = 0).
|
|
*
|
|
*/
|
|
public class LevelMovingHitObjects extends SpaceInvadersLevel {
|
|
|
|
// FIXME add logger here
|
|
|
|
|
|
//FIXME add your method overrides here
|
|
|
|
@Override
|
|
public void prepareLevel(String id) {
|
|
super.prepareLevel(id);
|
|
GameObject flyObject = new RectObject(id + "fly_enemy1", this, 300, 300, 75, 40, 40, 40, Color.blue);
|
|
flyObject.addController(new ReboundController());
|
|
flyObject.addCollider(new RectCollider("flyCollider",flyObject,40,40));
|
|
addObject(flyObject);
|
|
|
|
GameObject flyObject2 = new RectObject(id + "fly_enemy2", this, 200, 20, 90, 40, 40, 40, Color.green);
|
|
flyObject2.addController(new ReboundController());
|
|
flyObject2.addCollider(new RectCollider("flyCollider",flyObject2,40,40));
|
|
addObject(flyObject2);
|
|
logger.info("Objects are created and Collider added");
|
|
|
|
}
|
|
@Override
|
|
public void actionIfEgoCollidesWithEnemy(GameObject enemy, GameObject ego) {
|
|
/**
|
|
* set temporary text over ego. This object lives only for a short time. While it lives, further
|
|
* collisions are ignored. Otherwise a single collision would result in a lot of deducted
|
|
* points...
|
|
*/
|
|
|
|
double gameTime = this.getGameTime();
|
|
GameObject auaObj = this.getObject("AUA-EGO");
|
|
|
|
if (auaObj == null) {
|
|
addObject(new TextObject("AUA-EGO", this, ego.getX(), ego.getY() - 20, ego.getVX(),
|
|
ego.getVY(), "AUAA!!", 10, Color.RED)
|
|
.addController(new LimitedTimeController(gameTime, BONUS_DURATION)));
|
|
// deduct points
|
|
Integer pts = (Integer) getGlobalFlag("points");
|
|
|
|
if(enemy.id == "fly_enemy1" || enemy.id == "fly_enemy2") {
|
|
setGlobalFlag("points", 0);
|
|
}else {
|
|
setGlobalFlag("points", pts - 500);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private static Logger logger = LogManager.getLogger(LevelMovingHitObjects.class);
|
|
|
|
//Sind noch nicht ganz fertig geworden
|
|
|
|
/**
|
|
* "Moving Hitting Objects Level!" is the message.
|
|
*
|
|
* @return String "Moving & Hitting Objects Level!"
|
|
*/
|
|
@Override
|
|
protected String getStartupMessage() {
|
|
return "Moving & Hitting Objects Level!";
|
|
}
|
|
|
|
}
|