|
|
@ -1,5 +1,12 @@ |
|
|
|
package playground; |
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
|
|
|
|
import org.apache.logging.log4j.LogManager; |
|
|
|
|
|
|
|
import collider.RectCollider; |
|
|
|
import gameobjects.GameObject; |
|
|
|
import gameobjects.RectObject; |
|
|
|
|
|
|
|
/** |
|
|
|
* Level that creates two RectObjects moving around and if ego is hit by them game is directly lost |
|
|
@ -7,9 +14,10 @@ package playground; |
|
|
|
* |
|
|
|
*/ |
|
|
|
public class LevelMovingHitObjects extends SpaceInvadersLevel { |
|
|
|
|
|
|
|
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); |
|
|
|
// FIXME add logger here |
|
|
|
|
|
|
|
static org.apache.logging.log4j.Logger logger = LogManager.getLogger(SpaceInvadersLevel.class); |
|
|
|
|
|
|
|
//FIXME add your method overrides here |
|
|
|
|
|
|
@ -24,5 +32,33 @@ public class LevelMovingHitObjects extends SpaceInvadersLevel { |
|
|
|
protected String getStartupMessage() { |
|
|
|
return "Moving & Hitting Objects Level!"; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void prepareLevel(String id) { |
|
|
|
super.prepareLevel(id); |
|
|
|
this.addObject(fly_enemy1); |
|
|
|
fly_enemy1.addController(new controller.ReboundController()); |
|
|
|
fly_enemy1.addCollider(new RectCollider(id + "fly_enemy1_C", fly_enemy1, 40, 40)); |
|
|
|
logger.debug("fly_enemy1 added"); |
|
|
|
|
|
|
|
this.addObject(fly_enemy2); |
|
|
|
fly_enemy2.addController(new controller.ReboundController()); |
|
|
|
fly_enemy2.addCollider(new RectCollider(id + "fly_enemy2_C", fly_enemy2, 40, 40)); |
|
|
|
logger.debug("fly_enemy2 added"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
void actionIfEgoCollidesWithEnemy(GameObject enemy, GameObject ego) { |
|
|
|
if (enemy == this.fly_enemy1 || enemy == this.fly_enemy2) { |
|
|
|
logger.info("own objects hit"); |
|
|
|
Playground.setGlobalFlag("egoLives", 0); |
|
|
|
this.lost = true; |
|
|
|
} else { |
|
|
|
logger.info("normal objects hit"); |
|
|
|
super.actionIfEgoCollidesWithEnemy(enemy, ego); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |