Browse Source

HA06 finished

main
Nico B 3 years ago
parent
commit
5be60e1dd0
  1. 2
      GameProject/src/base/MovingObjectsGame.java
  2. 5
      GameProject/src/log4j2.xml
  3. 51
      GameProject/src/playground/LevelMovingHitObjects.java

2
GameProject/src/base/MovingObjectsGame.java

@ -1,4 +1,4 @@
package base;
package base;
import java.io.IOException; import java.io.IOException;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;

5
GameProject/src/log4j2.xml

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

51
GameProject/src/playground/LevelMovingHitObjects.java

@ -1,5 +1,13 @@
package playground; 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 * Level that creates two RectObjects moving around and if ego is hit by them game is directly lost
@ -8,7 +16,48 @@ package playground;
*/ */
public class LevelMovingHitObjects extends SpaceInvadersLevel { public class LevelMovingHitObjects extends SpaceInvadersLevel {
// FIXME add logger here
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 //FIXME add your method overrides here

Loading…
Cancel
Save