Skip to content

Commit

Permalink
Finally fixed FireworkChallenge.java's excess firework issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
MF42-DZH committed Aug 28, 2019
1 parent 1c71311 commit a438493
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 85 deletions.
84 changes: 44 additions & 40 deletions src/zeroxfc/nullpo/custom/libs/FieldManipulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,46 +45,54 @@ public class FieldManipulation {
private static final Logger log = Logger.getLogger(FieldManipulation.class);

/**
* Check for split line clears. To be executed in gamemode's onLineClear.
* Check for split line clears. To be executed in gamemode's onLineClear.<br />
* Credit goes to MandL27
* @param field Field to check
* @return <code>true</code> if line clear is split. <code>false</code> otherwise.
*/
public static boolean checkLineForSplit(Field field) {
if (field.lastLinesCleared == null){
field.lastLinesCleared = new ArrayList<Block[]>();
}
field.lastLinesCleared.clear();

boolean previousFlag = false;
boolean atLeastOne = false;

Block[] row = new Block[field.getWidth()];

for(int i = (field.getHiddenHeight() * -1); i < field.getHeightWithoutHurryupFloor(); i++) {
boolean flag = true;

for(int j = 0; j < field.getWidth(); j++) {
row[j] = new Block(field.getBlock(j, i));
if((field.getBlockEmpty(j, i)) || (field.getBlock(j, i).getAttribute(Block.BLOCK_ATTRIBUTE_WALL))) {
flag = false;
break;
}
}
/* if (field.lastLinesCleared == null){
* field.lastLinesCleared = new ArrayList<Block[]>();
* }
* field.lastLinesCleared.clear();
*
* boolean previousFlag = false;
* boolean atLeastOne = false;
*
* Block[] row = new Block[field.getWidth()];
*
* for(int i = (field.getHiddenHeight() * -1); i < field.getHeightWithoutHurryupFloor(); i++) {
* boolean flag = true;
*
* for(int j = 0; j < field.getWidth(); j++) {
* row[j] = new Block(field.getBlock(j, i));
* if((field.getBlockEmpty(j, i)) || (field.getBlock(j, i).getAttribute(Block.BLOCK_ATTRIBUTE_WALL))) {
* flag = false;
* break;
* }
* }
*
* field.setLineFlag(i, flag);
*
* if (flag != previousFlag && atLeastOne && flag) {
* return true;
* }
*
* if(flag) {
* atLeastOne = true;
* }
*
* previousFlag = flag;
} */
int regions = 0;
int lines = 0;

field.setLineFlag(i, flag);

if (flag != previousFlag && atLeastOne && flag) {
return true;
}

if(flag) {
atLeastOne = true;
}

previousFlag = flag;
for (int i = field.getHiddenHeight() * -1; i < field.getHeight(); i++) {
if (field.getLineFlag(i)) lines++;
if (lines > 0) regions++;
}

return false;
return regions > lines;
}

/**
Expand Down Expand Up @@ -397,7 +405,7 @@ public static double fieldCompare(Field a, Field b, boolean exact, boolean colou
if (a.getWidth() != b.getWidth()) return 0d;
if ((a.getHiddenHeight() + a.getHiddenHeight()) != (b.getHiddenHeight() + b.getHiddenHeight())) return 0d;

final int total = 2 * a.getWidth() * (a.getHeight() + a.getHiddenHeight());
final int total = 2 * getNumberOfBlocks(b);
int current = 0;

for (int y = (-1 * a.getHiddenHeight()); y < a.getHeight(); y++) {
Expand All @@ -407,9 +415,7 @@ public static double fieldCompare(Field a, Field b, boolean exact, boolean colou

if (blkA != null && blkB != null) {
if (colourMatch) {
if (blkA.isEmpty() && blkB.isEmpty()) {
current += 2;
} else {
if (!blkA.isEmpty() || !blkB.isEmpty()) {
if (!blkA.isEmpty() && blkB.isEmpty()) {
current -= 6;
} else if (!blkA.isEmpty() && !blkB.isEmpty()) {
Expand All @@ -421,9 +427,7 @@ public static double fieldCompare(Field a, Field b, boolean exact, boolean colou
}
}
} else {
if (blkA.isEmpty() && blkB.isEmpty()) {
current += 2;
} else {
if (!blkA.isEmpty() || !blkB.isEmpty()) {
if (!blkA.isEmpty() && blkB.isEmpty()) {
current -= 6;
} else if (!blkA.isEmpty() && !blkB.isEmpty()) {
Expand Down
15 changes: 9 additions & 6 deletions src/zeroxfc/nullpo/custom/libs/ProfileProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public static class LoginScreen {
private boolean signup;
private boolean success;
private ProfileProperties playerProperties;
private int colourHeading;
private final int colourHeading;

/**
* Creates a new login screen for a <code>ProfileProperties</code> instance.
Expand Down Expand Up @@ -681,13 +681,13 @@ private boolean onNameInput(GameEngine engine, int playerID) {
*/
if (nameEntry.length() == 3) currentChar = ProfileProperties.ENTRY_CHARS.length() - 1;

if (engine.ctrl.isPress(Controller.BUTTON_DOWN)) {
if (engine.ctrl.isPress(Controller.BUTTON_RIGHT)) {
if (engine.statc[1] % 6 == 0) {
engine.playSE("change");
currentChar++;
}
engine.statc[1]++;
} else if (engine.ctrl.isPress(Controller.BUTTON_UP)) {
} else if (engine.ctrl.isPress(Controller.BUTTON_LEFT)) {
if (engine.statc[1] % 6 == 0) {
engine.playSE("change");
currentChar--;
Expand All @@ -700,7 +700,7 @@ private boolean onNameInput(GameEngine engine, int playerID) {
engine.playSE("change");
currentChar = 0;
} else if (s.equals("q")) {
if (nameEntry.length() < 3) nameEntry = String.format("%3s", nameEntry);
if (nameEntry.length() < 3) nameEntry = String.format("%-3s", nameEntry);
engine.playSE("decide");
currentChar = 0;

Expand All @@ -724,7 +724,7 @@ private boolean onNameInput(GameEngine engine, int playerID) {
engine.statc[1] = 0;
}

return false;
return true;
}

private boolean onPasswordInput(GameEngine engine, int playerID) {
Expand Down Expand Up @@ -822,7 +822,10 @@ public void renderScreen(EventReceiver receiver, GameEngine engine, int playerID
GameTextUtilities.ALIGN_TOP_MIDDLE, "ENTRY", colourHeading,
2f);

receiver.drawMenuFont(engine, playerID, 2, 8,nameEntry + ProfileProperties.getCharAt(currentChar), 2f);
receiver.drawMenuFont(engine, playerID, 2, 8, nameEntry, 2f);
int c = 0;
if ((engine.statc[0] / 6) % 2 == 0) c = EventReceiver.COLOR_YELLOW;
receiver.drawMenuFont(engine, playerID, 2 + (nameEntry.length() * 2), 8, ProfileProperties.getCharAt(currentChar), c, 2f);

receiver.drawMenuFont(engine, playerID, 0, 18, "ENTER ACCOUNT\nNAME.");
// endregion
Expand Down
2 changes: 1 addition & 1 deletion src/zeroxfc/nullpo/custom/modes/Accelerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public void renderLast(GameEngine engine, int playerID) {
for(int i = 0; i < RANKING_MAX; i++) {
receiver.drawScoreFont(engine, playerID, 0, topY+i, String.format("%2d", i + 1), EventReceiver.COLOR_YELLOW, scale);
String s = String.valueOf(rankingScore[goaltype][i]);
receiver.drawScoreFont(engine, playerID, (s.length() > 6) ? 6 : 3, (s.length() > 6) ? (topY+i) * 2 : (topY+i), s, (i == rankingRank), (s.length() > 6) ? scale * 0.5f : scale);
receiver.drawScoreFont(engine, playerID, (s.length() > 6 && receiver.getNextDisplayType() != 2) ? 6 : 3, (s.length() > 6 && receiver.getNextDisplayType() != 2) ? (topY+i) * 2 : (topY+i), s, (i == rankingRank), (s.length() > 6 && receiver.getNextDisplayType() != 2) ? scale * 0.5f : scale);
receiver.drawScoreFont(engine, playerID, 10, topY+i, String.format("%.1f", rankingLines[goaltype][i]), (i == rankingRank), scale);
receiver.drawScoreFont(engine, playerID, 16, topY+i, GeneralUtil.getTime(rankingTime[goaltype][i]), (i == rankingRank), scale);
}
Expand Down
26 changes: 15 additions & 11 deletions src/zeroxfc/nullpo/custom/modes/ColourPower.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public void renderLast(GameEngine engine, int playerID) {
for(int i = 0; i < RANKING_MAX; i++) {
receiver.drawScoreFont(engine, playerID, 0, topY+i, String.format("%2d", i + 1), EventReceiver.COLOR_YELLOW, scale);
String s = String.valueOf(rankingScore[ruleboundMode ? 1 : 0][goaltype][i]);
receiver.drawScoreFont(engine, playerID, (s.length() > 6) ? 6 : 3, (s.length() > 6) ? (topY+i) * 2 : (topY+i), s, (i == rankingRank), (s.length() > 6) ? scale * 0.5f : scale);
receiver.drawScoreFont(engine, playerID, (s.length() > 6 && receiver.getNextDisplayType() != 2) ? 6 : 3, (s.length() > 6 && receiver.getNextDisplayType() != 2) ? (topY+i) * 2 : (topY+i), s, (i == rankingRank), (s.length() > 6 && receiver.getNextDisplayType() != 2) ? scale * 0.5f : scale);
receiver.drawScoreFont(engine, playerID, 10, topY+i, String.valueOf(rankingLines[ruleboundMode ? 1 : 0][goaltype][i]), (i == rankingRank), scale);
receiver.drawScoreFont(engine, playerID, 15, topY+i, GeneralUtil.getTime(rankingTime[ruleboundMode ? 1 : 0][goaltype][i]), (i == rankingRank), scale);
}
Expand Down Expand Up @@ -539,16 +539,20 @@ public void renderLast(GameEngine engine, int playerID) {

// Power-up progess
float scale = 1f;
if (receiver.getNextDisplayType() >= 1) scale = 0.5f;
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(12 / scale), "POWER-UPS", EventReceiver.COLOR_PINK, scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(13 / scale), " GREY:" + String.format("%d/%d", meterValues[0], POWER_METER_MAX), POWERUP_TEXT_COLOURS[0], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(14 / scale), " RED:" + String.format("%d/%d", meterValues[1], POWER_METER_MAX), POWERUP_TEXT_COLOURS[1], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(15 / scale), "ORANGE:" + String.format("%d/%d", meterValues[2], POWER_METER_MAX), POWERUP_TEXT_COLOURS[2], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(16 / scale), "YELLOW:" + String.format("%d/%d", meterValues[3], POWER_METER_MAX), POWERUP_TEXT_COLOURS[3], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(17 / scale), " GREEN:" + String.format("%d/%d", meterValues[4], POWER_METER_MAX), POWERUP_TEXT_COLOURS[4], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(18 / scale), " CYAN:" + String.format("%d/%d", meterValues[5], POWER_METER_MAX), POWERUP_TEXT_COLOURS[5], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(19 / scale), " BLUE:" + String.format("%d/%d", meterValues[6], POWER_METER_MAX), POWERUP_TEXT_COLOURS[6], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(20 / scale), "PURPLE:" + String.format("%d/%d", meterValues[7], POWER_METER_MAX), POWERUP_TEXT_COLOURS[7], scale);
int base = 12;
if (receiver.getNextDisplayType() >= 1) {
scale = 0.5f;
base = 24;
}
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(base / scale), "POWER-UPS", EventReceiver.COLOR_PINK, scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(base + 1 / scale), " GREY:" + String.format("%d/%d", meterValues[0], POWER_METER_MAX), POWERUP_TEXT_COLOURS[0], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(base + 2 / scale), " RED:" + String.format("%d/%d", meterValues[1], POWER_METER_MAX), POWERUP_TEXT_COLOURS[1], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(base + 3 / scale), "ORANGE:" + String.format("%d/%d", meterValues[2], POWER_METER_MAX), POWERUP_TEXT_COLOURS[2], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(base + 4 / scale), "YELLOW:" + String.format("%d/%d", meterValues[3], POWER_METER_MAX), POWERUP_TEXT_COLOURS[3], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(base + 5 / scale), " GREEN:" + String.format("%d/%d", meterValues[4], POWER_METER_MAX), POWERUP_TEXT_COLOURS[4], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(base + 6 / scale), " CYAN:" + String.format("%d/%d", meterValues[5], POWER_METER_MAX), POWERUP_TEXT_COLOURS[5], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(base + 7 / scale), " BLUE:" + String.format("%d/%d", meterValues[6], POWER_METER_MAX), POWERUP_TEXT_COLOURS[6], scale);
receiver.drawScoreFont(engine, playerID, (int)(10 / scale), (int)(base + 8 / scale), "PURPLE:" + String.format("%d/%d", meterValues[7], POWER_METER_MAX), POWERUP_TEXT_COLOURS[7], scale);

receiver.drawScoreFont(engine, playerID, 0, 15, "MULTI.", EventReceiver.COLOR_BLUE);
receiver.drawScoreFont(engine, playerID, 0, 16, String.valueOf(scoreMultiplier) + "X");
Expand Down
34 changes: 34 additions & 0 deletions src/zeroxfc/nullpo/custom/modes/DrawMode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package zeroxfc.nullpo.custom.modes;

import mu.nu.nullpo.game.component.Block;
import mu.nu.nullpo.game.component.Field;

import java.util.ArrayList;

public class DrawMode extends MarathonModeBase {
/** This mode always has 0G gravity */
private static final int GRAVITY_CONSTANT = 0;
Expand Down Expand Up @@ -119,8 +124,37 @@ public class DrawMode extends MarathonModeBase {
//endregion
};

private static final ArrayList<Field> SHAPE_FIELDS = new ArrayList<>();

private static final int[] SHAPE_TO_PIECE_ID = {
0, 0, 1, 1, 1, 1, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6
};

private static final int[] SHAPE_TO_PIECE_DIRECTION = {
0, 1, 0, 1, 2, 3, 0, 2, 1, 0, 1, 2, 3, 0, 1, 2, 3, 2, 3
};

static {
for (int i = 0; i < SHAPES.length; i++) {
int[][] shape = SHAPES[i];
int dimX = shape[0].length;
int dimY = shape.length;

SHAPE_FIELDS.add(new Field(dimX, dimY, 0));

for (int y = 0; y < dimY; y++) {
for (int x = 0; x < dimX; x++) {
SHAPE_FIELDS.get(i).getBlock(x, y).copy(new Block(shape[y][x], 0));
}
}
}
}

// endregion SHAPES

/** The match confidence of the field to each piece. */
private ArrayList<Double> matchConfidences;

/** Mode Name */
@Override
public String getName() {
Expand Down
Loading

0 comments on commit a438493

Please sign in to comment.