Space von Team 22 (Nico B. Benjamin F. Lea A.)
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.

77 lines
2.2 KiB

package playground;
import java.awt.Color;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import collider.RectCollider;
import controller.ReboundController;
import controller.ReboundController2;
import gameobjects.GameObject;
import gameobjects.RectObject;
/**
* 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 logger1 = LogManager.getLogger(LevelMovingHitObjects.class);
@Override
public void prepareLevel(String id) {
super.prepareLevel(id);
RectObject fly_enemy1 = new RectObject("fly_enemy1", this, 300, 300, 75, 40, 40, 40, Color.BLUE);
RectObject fly_enemy2 = new RectObject("fly_enemy2", this, 200, 200, 20, 90, 40, 40, Color.GREEN);
logger1.info("Created two rectobjects");
ReboundController2 fly1_controller = new ReboundController2();
ReboundController2 fly2_controller = new ReboundController2();
logger1.info("Created two controllers");
fly_enemy1.addController(fly1_controller);
fly_enemy2.addController(fly2_controller);
logger1.info("Added controller to Rectbjects");
this.addObject(fly_enemy1);
this.addObject(fly_enemy2);
logger1.info("Added objects to LevelMoving<HItObejcts");
RectCollider collider1 = new RectCollider("collider1", fly_enemy1, 40d, 40d);
RectCollider collider2 = new RectCollider("collider2", fly_enemy2, 40d, 40d);
logger1.info("Created two colliders");
fly_enemy1.addCollider(collider1);
fly_enemy2.addCollider(collider2);
logger1.info("Added collider to rectobjects");
}
@Override
void actionIfEgoCollidesWithEnemy(GameObject enemy, GameObject ego) {
if (enemy.id.equals("fly_enemy1") || enemy.id.equals("fly_enemy2")) {
setGlobalFlag("egoLive", 0);
this.lost = true;
} else {
super.actionIfEgoCollidesWithEnemy(enemy, ego);
}
}
//FIXME add your method overrides here
/**
* "Moving Hitting Objects Level!" is the message.
*
* @return String "Moving & Hitting Objects Level!"
*/
@Override
protected String getStartupMessage() {
return "Moving & Hitting Objects Level!";
}
}