4 Commits
2c67481aad
...
5be60e1dd0
Author | SHA1 | Message | Date |
---|---|---|---|
Nico B | 5be60e1dd0 |
HA06 finished
|
3 years ago |
Nico B | 016fa51476 |
pull
|
3 years ago |
jkonert | 59ca180a42 |
fixed small JavaDoc typo
|
3 years ago |
jkonert | 58355dbed8 |
adding files afor HA06 (using RectCollider and Logger)
|
3 years ago |
5 changed files with 123 additions and 9 deletions
-
9GameProject/src/base/MovingObjectsGame.java
-
35GameProject/src/controller/ReboundController2.java
-
5GameProject/src/log4j2.xml
-
77GameProject/src/playground/LevelMovingHitObjects.java
-
2GameProject/src/playground/package-info.java
@ -0,0 +1,35 @@ |
|||
package controller; |
|||
|
|||
/** Controller to let Objects bounce from the outer level limits back and forth. |
|||
* |
|||
*/ |
|||
public class ReboundController2 extends ObjectController { |
|||
|
|||
/** inverts the x y direction speeds if the outer limits are reached. |
|||
* |
|||
*/ |
|||
@Override |
|||
public void updateObject() { |
|||
double sizeX = this.getPlayground().preferredSizeX(); |
|||
double sizeY = this.getPlayground().preferredSizeY(); |
|||
double objSizeX = 30; |
|||
double objSizeY = 30; |
|||
|
|||
if (this.getX() < objSizeX) { |
|||
this.setVX(this.getVX() * -1); |
|||
this.setX(objSizeX); |
|||
} else if (this.getX() > sizeX - objSizeX) { |
|||
this.setVX(this.getVX() * -1); |
|||
this.setX(sizeX - objSizeX); |
|||
} |
|||
if (this.getY() < objSizeY) { |
|||
this.setVY(this.getVY() * -1); |
|||
this.setY(objSizeY); |
|||
} else if (this.getY() > sizeY - objSizeY) { |
|||
this.setVY(this.getVY() * -1); |
|||
this.setY(sizeY - objSizeY); |
|||
} |
|||
this.applySpeedVector(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,77 @@ |
|||
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 |
|||
* (lives = 0). |
|||
* |
|||
*/ |
|||
public class LevelMovingHitObjects extends SpaceInvadersLevel { |
|||
|
|||
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 |
|||
|
|||
|
|||
|
|||
/** |
|||
* "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