Commit 68f4e565 authored by Yuhan Chen's avatar Yuhan Chen
Browse files

New update

parent fb1a77e1
......@@ -54,16 +54,17 @@ public class DemoRule {
public static ArrayList<GeneralObject> objs = new ArrayList<GeneralObject>(4);
/**
* Check if the character is on the left a normal object
* Check if the character is on the right a normal object
* @return the normal object
*/
public static GeneralObject nearObjectLeft(GeneralObject generalObject){
public static GeneralObject atObjectLocation(GeneralObject generalObject){
for (GeneralObject obj: objs) {
if (!obj.equals(generalObject))
if (generalObject.getX() == (obj.getX() - SQUARE_SIZE) && generalObject.getY() == obj.getY()) {
if(!obj.equals(generalObject)) {
if (generalObject.getX() == (obj.getX()) && generalObject.getY() == obj.getY())
return obj;
}
}
}
return generalObject;
}
......@@ -75,7 +76,21 @@ public class DemoRule {
public static GeneralObject nearObjectRight(GeneralObject generalObject){
for (GeneralObject obj: objs) {
if(!obj.equals(generalObject)) {
if (generalObject.getX() == (obj.getX() + SQUARE_SIZE) && generalObject.getY() == obj.getY())
if (generalObject.getX() == (obj.getX()+ SQUARE_SIZE) && generalObject.getY() == obj.getY())
return obj;
}
}
return generalObject;
}
/**
* Check if the character is on the right a normal object
* @return the normal object
*/
public static GeneralObject nearObjectLeft(GeneralObject generalObject){
for (GeneralObject obj: objs) {
if(!obj.equals(generalObject)) {
if (generalObject.getX() == (obj.getX() - SQUARE_SIZE) && generalObject.getY() == obj.getY())
return obj;
}
}
......@@ -89,7 +104,7 @@ public class DemoRule {
public static GeneralObject nearObjectUp(GeneralObject generalObject){
for (GeneralObject obj: objs) {
if (!obj.equals(generalObject)) {
if (generalObject.getX() == (obj.getX()) && generalObject.getY() == obj.getY() - SQUARE_SIZE)
if (generalObject.getX() == (obj.getX()) && generalObject.getY() == obj.getY()-SQUARE_SIZE)
return obj;
}
}
......@@ -103,7 +118,7 @@ public class DemoRule {
public static GeneralObject nearObjectDown(GeneralObject generalObject){
for (GeneralObject obj: objs) {
if (!obj.equals(generalObject)) {
if (generalObject.getX() == (obj.getX()) && generalObject.getY() == obj.getY() + SQUARE_SIZE)
if (generalObject.getX() == (obj.getX()) && generalObject.getY() == obj.getY()+SQUARE_SIZE)
return obj;
}
}
......@@ -128,11 +143,11 @@ public class DemoRule {
if (player.isPushable() == false) {return false;}
switch (key) {
case DOWN:
while (!nearObjectUp(boundaryObj).equals(boundaryObj)) {
while (!atObjectLocation(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getY() == HEIGHT) {
return false;
}
boundaryObj = nearObjectDown(boundaryObj);
boundaryObj = atObjectLocation(boundaryObj);
}
return true;
case UP:
......@@ -144,19 +159,19 @@ public class DemoRule {
}
return true;
case RIGHT:
while (!nearObjectLeft(boundaryObj).equals(boundaryObj)) {
while (!atObjectLocation(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getX() == WIDTH) {
return false;
}
boundaryObj = nearObjectDown(boundaryObj);
boundaryObj = atObjectLocation(boundaryObj);
}
return true;
case LEFT:
while (!nearObjectRight(boundaryObj).equals(boundaryObj)) {
while (!atObjectLocation(boundaryObj).equals(boundaryObj)) {
if (boundaryObj.getX() == 0) {
return false;
}
boundaryObj = nearObjectDown(boundaryObj);
boundaryObj = atObjectLocation(boundaryObj);
}
return true;
}
......@@ -168,29 +183,29 @@ public class DemoRule {
if (isPushable(code)) {
if (code == KeyCode.UP) {
player.move(0,-SQUARE_SIZE);
while(!nearObjectDown(generalObject).equals(generalObject)){
generalObject = nearObjectDown(generalObject);
while(!atObjectLocation(generalObject).equals(generalObject)){
generalObject = atObjectLocation(generalObject);
generalObject.move(0, -SQUARE_SIZE);
}
}
if (code == KeyCode.DOWN) {
player.move(0, SQUARE_SIZE);
while(!nearObjectUp(generalObject).equals(generalObject)){
generalObject = nearObjectUp(generalObject);
while(!atObjectLocation(generalObject).equals(generalObject)){
generalObject = atObjectLocation(generalObject);
generalObject.move(0, SQUARE_SIZE);
}
}
if (code == KeyCode.RIGHT) {
player.move(SQUARE_SIZE,0);
while(!nearObjectLeft(generalObject).equals(generalObject)) {
generalObject = nearObjectLeft(generalObject);
while(!atObjectLocation(generalObject).equals(generalObject)) {
generalObject = atObjectLocation(generalObject);
generalObject.move(SQUARE_SIZE,0);
}
}
if (code == KeyCode.LEFT) {
player.move(-SQUARE_SIZE,0);
while(!nearObjectRight(generalObject).equals(generalObject)) {
generalObject = nearObjectRight(generalObject);
while(!atObjectLocation(generalObject).equals(generalObject)) {
generalObject = atObjectLocation(generalObject);
generalObject.move(-SQUARE_SIZE,0);
}
}
......@@ -214,7 +229,7 @@ public class DemoRule {
if (nearObjectLeft(rockObj).equals(isObj) && nearObjectRight(babaObj).equals(isObj)) {
player = babaObj;
}
if (nearObjectUp(babaObj).equals(isObj) && nearObjectDown(winObj).equals((isObj))) {
if (nearObjectUp(babaObj).equals(isObj) && nearObjectDown(babaObj).equals((isObj))) {
player = babaObj;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment