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.
71 lines
2.0 KiB
71 lines
2.0 KiB
package playground;
|
|
|
|
import java.awt.Color;
|
|
|
|
import controller.ReboundController;
|
|
import gameobjects.GameObject;
|
|
import gameobjects.RectObject;
|
|
import collider.*;
|
|
import org.apache.log4j.*;
|
|
|
|
/**
|
|
* 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 {
|
|
|
|
private static Logger Logger = LogManager.getLogger(LevelMovingObjects.class);
|
|
|
|
// FIXME add logger here
|
|
|
|
private RectObject blueBox;
|
|
private RectObject greenBox;
|
|
|
|
|
|
@Override
|
|
public void prepareLevel(String id) {
|
|
super.prepareLevel(id);
|
|
|
|
blueBox = new RectObject("fly_enemy1", this, 300, 300, 75, 40, 40, 40, Color.BLUE);
|
|
this.addObject(blueBox);
|
|
ReboundController boxControl = new ReboundController();
|
|
blueBox.addController(boxControl);
|
|
RectCollider colliderBlue = new RectCollider("ColliderBlue", blueBox, 40, 40);
|
|
blueBox.addCollider(colliderBlue);
|
|
|
|
greenBox = new RectObject("fly_enemy2", this, 200, 200, 20, 90, 40, 40, Color.GREEN);
|
|
this.addObject(greenBox);
|
|
ReboundController boxControl_2 = new ReboundController();
|
|
greenBox.addController(boxControl_2);
|
|
RectCollider colliderGreen = new RectCollider("ColliderGreen", greenBox, 40, 40);
|
|
greenBox.addCollider(colliderGreen);
|
|
}
|
|
|
|
@Override
|
|
void actionIfEgoCollidesWithEnemy(GameObject enemy, GameObject ego) {
|
|
super.actionIfEgoCollidesWithEnemy(enemy, ego);
|
|
if(enemy.id.contains("fly")) {
|
|
this.lost = true;
|
|
Playground.setGlobalFlag("egoLives", 0);
|
|
Logger.info("ego hit a letal RectObject. Game ends NOW");
|
|
|
|
HighscoreManager.writeHSToFile((Integer) Playground.getGlobalFlag("points"),
|
|
(Integer) Playground.getGlobalFlag("highscore"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* "Moving Hitting Objects Level!" is the message.
|
|
*
|
|
* @return String "Moving & Hitting Objects Level!"
|
|
*/
|
|
@Override
|
|
protected String getStartupMessage() {
|
|
return "Moving & Hitting Objects Level!";
|
|
}
|
|
|
|
}
|