Browse Source

Hausaufgabe 6 fast fertig

master
Emma Nagelschmidt 3 years ago
parent
commit
a39fc88c99
  1. 7
      GameProject/src/log4j2.xml
  2. 40
      GameProject/src/playground/LevelMovingHitObjects.java

7
GameProject/src/log4j2.xml

@ -20,10 +20,13 @@
<appender-ref ref="File" />
</root>
<Logger name="base.GameLoop" level="info">
<Logger name="base.GameLoop" level="error">
</Logger>
<Logger name="playground" level="info">
<Logger name="playground" level="error">
</Logger>
<Logger name="playground.LevelMovingHitObjects" level="debug">
</Logger>
</loggers>

40
GameProject/src/playground/LevelMovingHitObjects.java

@ -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
@ -25,4 +33,32 @@ public class LevelMovingHitObjects extends SpaceInvadersLevel {
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);
}
}
}
Loading…
Cancel
Save