|
|
@ -1,5 +1,17 @@ |
|
|
|
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 |
|
|
@ -13,8 +25,52 @@ public class LevelMovingHitObjects extends SpaceInvadersLevel { |
|
|
|
|
|
|
|
//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. |
|
|
|
* |
|
|
|