Nour 3 years ago
parent
commit
fff7872098
  1. 1
      GameProject/src/base/MovingObjectsGame.java
  2. 18
      GameProject/src/base/MultiLevelGame.java
  3. 24
      GameProject/src/controller/ReboundController.java
  4. 4
      GameProject/src/log4j2.xml
  5. 55
      GameProject/src/playground/LevelMovingHitObjects.java
  6. 21
      GameProject/src/playground/LevelMovingObjects.java

1
GameProject/src/base/MovingObjectsGame.java

@ -20,6 +20,7 @@ public class MovingObjectsGame extends GameLoop {
* @throws IOException if highscore.txt file cannot be written or accessed, the exception is
* thrown (and game ends).
*/
public static void main(String[] args) throws IOException {
logger.info("Starting Game Program...let's play and don't get hit!");
GameLoop myGame = new MovingObjectsGame();

18
GameProject/src/base/MultiLevelGame.java

@ -2,14 +2,9 @@
import java.io.IOException;
import playground.Level1;
import playground.Level3;
import playground.Level5;
import playground.Level6;
import playground.Level7;
import playground.LevelBoss;
import playground.LevelHitTwice;
import playground.LevelWithBox;
import playground.LevelMovingHitObjects;
public class MultiLevelGame extends GameLoop {
@ -17,10 +12,9 @@ public class MultiLevelGame extends GameLoop {
@Override
void defineLevels() {
this.addLevel(new LevelWithBox());
this.addLevel(new Level5());
this.addLevel(new Level6());
this.addLevel(new Level7());
this.addLevel(new LevelMovingHitObjects());
}

24
GameProject/src/controller/ReboundController.java

@ -0,0 +1,24 @@
package controller;
public class ReboundController extends ObjectController{
@Override
public void updateObject() {
if (this.getX() < 30 || this.getX() > 670 ) {
setVX(getVX() * -1) ;
}
if (getY() < 30 || getY() > 670 ) {
setVY(getVY() * -1) ;
}
super.applySpeedVector();
}
}

4
GameProject/src/log4j2.xml

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

55
GameProject/src/playground/LevelMovingHitObjects.java

@ -1,28 +1,71 @@
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 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 {
// FIXME add logger here
public class LevelMovingHitObjects extends SpaceInvadersLevel {
//FIXME add your method overrides here
private static Logger logger = LogManager.getLogger(LevelMovingHitObjects.class);
@Override
public void prepareLevel(String id) {
super.prepareLevel(id);
GameObject a = new RectObject("fly_enemy1", this, 300, 300, 75, 40, 40 , 40 , Color.blue);
this.addObject(a);
logger.info("Object added");
a.addController(new ReboundController());
GameObject b = new RectObject("fly_enemy2", this, 200, 200, 20, 90, 40 , 40 , Color.green);
this.addObject(b);
b.addController(new ReboundController());
logger.info("collider added");
a.addCollider(new RectCollider("fly_enemy1", a, 40, 40));
b.addCollider(new RectCollider("fly_enemy2", b, 40, 40));
}
void actionIfEgoCollidesWithEnemy(GameObject enemy, GameObject ego) {
logger.info("the id contines :eneym:");
if (enemy.id.equals("fly_enemy1") || enemy.id.equals("fly_enemy2")) {
int NoLives = 0;
Playground.setGlobalFlag("egoLives", NoLives);
logger.info("the game ends");
this.lost = true;
} else {
super.actionIfEgoCollidesWithEnemy(enemy, ego);
}
}
/**
* "Moving Hitting Objects Level!" is the message.
*
* @return String "Moving & Hitting Objects Level!"
*/
@Override
protected String getStartupMessage() {
return "Moving & Hitting Objects Level!";
}
}

21
GameProject/src/playground/LevelMovingObjects.java

@ -1,19 +1,36 @@
package playground;
import java.awt.Color;
import controller.ReboundController;
import gameobjects.GameObject;
import gameobjects.RectObject;
/** This level adds two distracting objects to the canvas that cannot collide but bounce around all the time.
*/
public class LevelMovingObjects extends SpaceInvadersLevel {
// TODO your code here
@Override
public void prepareLevel(String id) {
super.prepareLevel(id);
GameObject o = new RectObject("blue", this, 300, 300, 170, 70, 30 , 30 , Color.blue);
this.addObject(o);
o.addController(new ReboundController());
}
/** "Moving Objects Level!" is the message.
*
* @return String "Moving Objects Level!"
*/
@Override
protected String getStartupMessage() {
return "Moving Objects Level!";
}

Loading…
Cancel
Save