Nour
3 years ago
6 changed files with 100 additions and 23 deletions
-
1GameProject/src/base/MovingObjectsGame.java
-
18GameProject/src/base/MultiLevelGame.java
-
24GameProject/src/controller/ReboundController.java
-
4GameProject/src/log4j2.xml
-
55GameProject/src/playground/LevelMovingHitObjects.java
-
21GameProject/src/playground/LevelMovingObjects.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(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -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!"; |
|||
} |
|||
|
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue