ueb02.1
This commit is contained in:
parent
8c4152c273
commit
aa482c8e5d
@ -7,7 +7,7 @@ import fr.enssat.BoulderDash.helpers.AudioLoadHelper;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ElementPositionUpdateHelper
|
* ElementPositionUpdateHelper
|
||||||
*
|
* <p>
|
||||||
* Updates position of all elements displayed on the map, according to their
|
* Updates position of all elements displayed on the map, according to their
|
||||||
* next potential position. Each object has a weight, which is used to compare
|
* next potential position. Each object has a weight, which is used to compare
|
||||||
* their power to destroy in the food chain. Sorry for that Darwinism.
|
* their power to destroy in the food chain. Sorry for that Darwinism.
|
||||||
@ -39,7 +39,7 @@ public class BoulderAndDiamondController implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
while (this.levelModel.isGameRunning()) {
|
while (this.levelModel.isGameRunning()) {
|
||||||
if(!this.levelModel.getGamePaused()){
|
if (!this.levelModel.getGamePaused()) {
|
||||||
this.manageFallingObject();
|
this.manageFallingObject();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -61,7 +61,7 @@ public class BoulderAndDiamondController implements Runnable {
|
|||||||
// Gets the spriteName of actual DisplayableElementModel object scanned
|
// Gets the spriteName of actual DisplayableElementModel object scanned
|
||||||
DisplayableElementModel elementModel = this.levelModel.getGroundLevelModel()[x][y];
|
DisplayableElementModel elementModel = this.levelModel.getGroundLevelModel()[x][y];
|
||||||
|
|
||||||
if(elementModel == null) {
|
if (elementModel == null) {
|
||||||
elementModel = new DirtModel();
|
elementModel = new DirtModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +70,8 @@ public class BoulderAndDiamondController implements Runnable {
|
|||||||
// If it is a boulder or a diamond...
|
// If it is a boulder or a diamond...
|
||||||
if (spriteName == "boulder" || spriteName == "diamond") {
|
if (spriteName == "boulder" || spriteName == "diamond") {
|
||||||
this.manageFall(x, y);
|
this.manageFall(x, y);
|
||||||
} else if(spriteName == "expandingwall"){
|
} else if (spriteName == "expandingwall") {
|
||||||
if(this.expandWall(x,y).equals("left")){
|
if (this.expandWall(x, y).equals("left")) {
|
||||||
x -= 1;
|
x -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,6 +79,25 @@ public class BoulderAndDiamondController implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getSpriteNameLeft(int x, int y) {
|
||||||
|
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
||||||
|
return elementLeft.getSpriteName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSpriteNameRight(int x, int y) {
|
||||||
|
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
||||||
|
return elementRight.getSpriteName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSpriteNameBelow(int x, int y) {
|
||||||
|
DisplayableElementModel elementBelow = getElementBelow(x, y);
|
||||||
|
return elementBelow.getSpriteName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private DisplayableElementModel getElementBelow(int x, int y) {
|
||||||
|
return this.levelModel.getGroundLevelModel()[x][y + 1];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expand the wall at left & right
|
* Expand the wall at left & right
|
||||||
*
|
*
|
||||||
@ -86,18 +105,13 @@ public class BoulderAndDiamondController implements Runnable {
|
|||||||
* @param y Vertical position
|
* @param y Vertical position
|
||||||
*/
|
*/
|
||||||
private String expandWall(int x, int y) {
|
private String expandWall(int x, int y) {
|
||||||
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
|
||||||
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
|
||||||
String spriteNameLeft = elementLeft.getSpriteName();
|
|
||||||
String spriteNameRight = elementRight.getSpriteName();
|
|
||||||
|
|
||||||
String way = "";
|
String way = "";
|
||||||
if(spriteNameLeft == "black"){
|
if (getSpriteNameLeft(x, y) == "black") {
|
||||||
this.levelModel.expandThisWallToLeft(x,y);
|
this.levelModel.expandThisWallToLeft(x, y);
|
||||||
way = "left";
|
way = "left";
|
||||||
}
|
}
|
||||||
if(spriteNameRight == "black"){
|
if (getSpriteNameRight(x, y) == "black") {
|
||||||
this.levelModel.expandThisWallToRight(x,y);
|
this.levelModel.expandThisWallToRight(x, y);
|
||||||
way = "right";
|
way = "right";
|
||||||
}
|
}
|
||||||
return way;
|
return way;
|
||||||
@ -110,16 +124,9 @@ public class BoulderAndDiamondController implements Runnable {
|
|||||||
* @param y Vertical position
|
* @param y Vertical position
|
||||||
*/
|
*/
|
||||||
private void manageFall(int x, int y) {
|
private void manageFall(int x, int y) {
|
||||||
// Get informed about Rockford surroundings
|
|
||||||
DisplayableElementModel elementBelow = this.levelModel.getGroundLevelModel()[x][y + 1];
|
|
||||||
DisplayableElementModel elementLeft = this.levelModel.getGroundLevelModel()[x - 1][y];
|
|
||||||
DisplayableElementModel elementRight = this.levelModel.getGroundLevelModel()[x + 1][y];
|
|
||||||
|
|
||||||
String spriteNameBelow = elementBelow.getSpriteName();
|
|
||||||
String spriteNameLeft = elementLeft.getSpriteName();
|
|
||||||
String spriteNameRight = elementRight.getSpriteName();
|
|
||||||
|
|
||||||
// Then, process in case of the surrounding
|
// Then, process in case of the surrounding
|
||||||
|
String spriteNameBelow = getSpriteNameBelow(x, y);
|
||||||
if (spriteNameBelow == "black") {
|
if (spriteNameBelow == "black") {
|
||||||
this.levelModel.makeThisDisplayableElementFall(x, y);
|
this.levelModel.makeThisDisplayableElementFall(x, y);
|
||||||
} else if (spriteNameBelow == "boulder") {
|
} else if (spriteNameBelow == "boulder") {
|
||||||
@ -143,19 +150,19 @@ public class BoulderAndDiamondController implements Runnable {
|
|||||||
this.levelModel.setGameRunning(false);
|
this.levelModel.setGameRunning(false);
|
||||||
} else if (spriteNameBelow == "magicwall") {
|
} else if (spriteNameBelow == "magicwall") {
|
||||||
if (this.levelModel.getGroundLevelModel()[x][y].getSpriteName() == "boulder"
|
if (this.levelModel.getGroundLevelModel()[x][y].getSpriteName() == "boulder"
|
||||||
&& (this.levelModel.getGroundLevelModel()[x][y+2].getSpriteName() == "dirt" ||
|
&& (this.levelModel.getGroundLevelModel()[x][y + 2].getSpriteName() == "dirt" ||
|
||||||
this.levelModel.getGroundLevelModel()[x][y+2].getSpriteName() == "black")) {
|
this.levelModel.getGroundLevelModel()[x][y + 2].getSpriteName() == "black")) {
|
||||||
if(this.levelModel.getGroundLevelModel()[x][y].isConvertible()) {
|
if (this.levelModel.getGroundLevelModel()[x][y].isConvertible()) {
|
||||||
this.levelModel.transformThisBoulderIntoADiamond(x, y);
|
this.levelModel.transformThisBoulderIntoADiamond(x, y);
|
||||||
} else {
|
} else {
|
||||||
this.levelModel.deleteThisBoulder(x, y);
|
this.levelModel.deleteThisBoulder(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (elementBelow.isDestructible() && spriteNameBelow != "dirt" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) {
|
} else if (getElementBelow(x, y).isDestructible() && spriteNameBelow != "dirt" && this.levelModel.getGroundLevelModel()[x][y].isFalling()) {
|
||||||
this.levelModel.exploseThisBrickWall(x, y);
|
this.levelModel.exploseThisBrickWall(x, y);
|
||||||
} else if (spriteNameLeft == "rockford" && this.levelModel.getRockford().isRunningRight() && this.levelModel.getGroundLevelModel()[x + 1][y].getSpriteName() == "black") {
|
} else if (getSpriteNameLeft(x, y) == "rockford" && this.levelModel.getRockford().isRunningRight() && this.levelModel.getGroundLevelModel()[x + 1][y].getSpriteName() == "black") {
|
||||||
this.levelModel.moveThisBoulderToRight(x, y);
|
this.levelModel.moveThisBoulderToRight(x, y);
|
||||||
} else if (spriteNameRight == "rockford" && this.levelModel.getRockford().isRunningLeft() && this.levelModel.getGroundLevelModel()[x - 1][y].getSpriteName() == "black") {
|
} else if (getSpriteNameRight(x, y) == "rockford" && this.levelModel.getRockford().isRunningLeft() && this.levelModel.getGroundLevelModel()[x - 1][y].getSpriteName() == "black") {
|
||||||
this.levelModel.moveThisBoulderToLeft(x, y);
|
this.levelModel.moveThisBoulderToLeft(x, y);
|
||||||
} else {
|
} else {
|
||||||
this.levelModel.getGroundLevelModel()[x][y].setFalling(false);
|
this.levelModel.getGroundLevelModel()[x][y].setFalling(false);
|
||||||
|
@ -114,16 +114,22 @@ public class RockfordModel extends DisplayableElementModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void resetMovement(){
|
||||||
* Stops the Rockford movement
|
|
||||||
*/
|
|
||||||
public void startStaying() {
|
|
||||||
isCollisionDone = false;
|
isCollisionDone = false;
|
||||||
isStaying = true;
|
isStaying = false;
|
||||||
isRunningLeft = false;
|
isRunningLeft = false;
|
||||||
isRunningRight = false;
|
isRunningRight = false;
|
||||||
isRunningUp = false;
|
isRunningUp = false;
|
||||||
isRunningDown = false;
|
isRunningDown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the Rockford movement
|
||||||
|
*/
|
||||||
|
public void startStaying() {
|
||||||
|
resetMovement();
|
||||||
|
isStaying = true;
|
||||||
|
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
}
|
}
|
||||||
@ -132,12 +138,9 @@ public class RockfordModel extends DisplayableElementModel {
|
|||||||
* Starts moving Rockford to the left
|
* Starts moving Rockford to the left
|
||||||
*/
|
*/
|
||||||
public void startRunningLeft() {
|
public void startRunningLeft() {
|
||||||
isCollisionDone = false;
|
resetMovement();
|
||||||
isStaying = false;
|
|
||||||
isRunningLeft = true;
|
isRunningLeft = true;
|
||||||
isRunningRight = false;
|
|
||||||
isRunningUp = false;
|
|
||||||
isRunningDown = false;
|
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,12 +148,9 @@ public class RockfordModel extends DisplayableElementModel {
|
|||||||
* Starts moving Rockford to the right
|
* Starts moving Rockford to the right
|
||||||
*/
|
*/
|
||||||
public void startRunningRight() {
|
public void startRunningRight() {
|
||||||
isCollisionDone = false;
|
resetMovement();
|
||||||
isStaying = false;
|
|
||||||
isRunningLeft = false;
|
|
||||||
isRunningRight = true;
|
isRunningRight = true;
|
||||||
isRunningUp = false;
|
|
||||||
isRunningDown = false;
|
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,12 +158,9 @@ public class RockfordModel extends DisplayableElementModel {
|
|||||||
* Rockford running up
|
* Rockford running up
|
||||||
*/
|
*/
|
||||||
public void startRunningUp() {
|
public void startRunningUp() {
|
||||||
isCollisionDone = false;
|
resetMovement();
|
||||||
isStaying = false;
|
|
||||||
isRunningLeft = false;
|
|
||||||
isRunningRight = false;
|
|
||||||
isRunningUp = true;
|
isRunningUp = true;
|
||||||
isRunningDown = false;
|
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,12 +168,9 @@ public class RockfordModel extends DisplayableElementModel {
|
|||||||
* Rockford running down
|
* Rockford running down
|
||||||
*/
|
*/
|
||||||
public void startRunningDown() {
|
public void startRunningDown() {
|
||||||
isCollisionDone = false;
|
resetMovement();
|
||||||
isStaying = false;
|
|
||||||
isRunningLeft = false;
|
|
||||||
isRunningRight = false;
|
|
||||||
isRunningUp = false;
|
|
||||||
isRunningDown = true;
|
isRunningDown = true;
|
||||||
|
|
||||||
previousTime = 0;
|
previousTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,13 +43,12 @@ public abstract class GroundView extends JPanel implements Observer {
|
|||||||
*/
|
*/
|
||||||
public void drawTerrain(int width, int height, Graphics g) {
|
public void drawTerrain(int width, int height, Graphics g) {
|
||||||
// Draw items
|
// Draw items
|
||||||
if (this.levelModel.getMode() == "game") {
|
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
g.drawImage(this.levelModel.getImage(x, y), (x * 16), (y * 16), this);
|
g.drawImage(this.levelModel.getImage(x, y), (x * 16), (y * 16), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.levelModel.getMode() == "game") {
|
||||||
if(!this.levelModel.isGameRunning()) {
|
if(!this.levelModel.isGameRunning()) {
|
||||||
if(!this.levelModel.getRockford().getHasExplosed()) {
|
if(!this.levelModel.getRockford().getHasExplosed()) {
|
||||||
this.displayWin();
|
this.displayWin();
|
||||||
@ -58,11 +57,6 @@ public abstract class GroundView extends JPanel implements Observer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int x = 0; x < width; x++) {
|
|
||||||
for (int y = 0; y < height; y++) {
|
|
||||||
g.drawImage(this.levelModel.getImage(x, y), (x * 16), (y * 16), this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.levelModel.getShowCursor()) {
|
if (this.levelModel.getShowCursor()) {
|
||||||
g.drawImage(
|
g.drawImage(
|
||||||
this.levelModel.getCursorImage(),
|
this.levelModel.getCursorImage(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user