OneHourProcessing 十三日目
OneHourProcessing 十三日目
ぷよぷよ計画三日目です
#OneHourProcessing #Proessing
— 霜暮黒夢@V高専生 (@V_hero_aid) August 16, 2020
十三日目の作品です
よりぷよぷよしてきましたが、不具合がわりと…
今日かかった時間は「49分11秒」
トータル時間は「3時間51分32秒」 pic.twitter.com/N0GOVsq1wG
今日かかった時間は「49分11秒」
トータル時間は「3時間51分32秒」
バグが…不具合が…
コード
Controller controller; void setup() { size(800, 450); reset(); } void draw() { background(0); controller.update(); controller.display(); } void keyPressed() { controller.keyPress(); } void keyReleased() { controller.keyRelease(); } void mousePressed() { reset(); } void reset() { controller = null; controller = new Controller(new PVector (8, 15), 30); }
Controllerクラス
class Controller { PVector squareNum; float squareSize; ArrayList<Puyo> puyos = new ArrayList<Puyo>(); ArrayList<Puyo> movePuyos = new ArrayList<Puyo>(); Puyo[][] squares; Puyo operatePuyo; Puyo subPuyo; Controller(PVector squareNum, float squareSize) { this.squareNum = squareNum; this.squareSize = squareSize; squares = new Puyo[int(squareNum.x)][int(squareNum.y)]; addPuyo(true); addPuyo(false); } void update() { for (Puyo puyo : movePuyos) puyo.update(); for (int i = 0; i < movePuyos.size(); i++) if (movePuyos.get(i).pos.y % squareSize > squareSize / 2) { Puyo puyo = movePuyos.get(i); int puyoX = puyo.returnX(squareSize); int puyoY = puyo.returnY(squareSize); boolean isStop = false; if (puyoY >= squareNum.y - 1) { isStop = true; squares[puyoX][int(squareNum.y - 1)] = puyo; puyo.pos.y = squareSize * (squareNum.y - 0.5); } else if (squares[puyoX][puyoY + 1] != null) { isStop = true; squares[puyoX][puyoY] = puyo; puyo.pos.y = squareSize * (puyoY + 0.5); } if (isStop) { puyo.setStatus("STOP"); movePuyos.remove(puyo); if (puyo == operatePuyo) { operatePuyo = subPuyo; subPuyo = null; } else if (puyo == subPuyo) subPuyo = null; i--; } } if (movePuyos.size() > 0) return; operatePuyo = null; subPuyo = null; for (Puyo puyo : puyos) puyo.flag = true; for (Puyo puyo : puyos) if (puyo.flag) checkPuyo(puyo, null); for (int i = 0; i < puyos.size(); i++) { Puyo puyo = puyos.get(i); if (puyo.connectNum + 1 >= 4) { erasePuyo(puyo); i--; } println(puyo.pos.x + " : " + puyo.pos.y); } for (Puyo puyo : puyos) { int puyoX = puyo.returnX(squareSize); int puyoY = puyo.returnY(squareSize); if (puyoY < squareNum.y - 1) if (squares[puyoX][puyoY + 1] == null) { puyo.setStatus("FALL"); squares[puyoX][puyoY] = null; movePuyos.add(puyo); } } if (movePuyos.size() > 0) return; addPuyo(true); addPuyo(false); } void display() { for (Puyo puyo : puyos) puyo.display(); } void keyPress() { if (operatePuyo == null) return; int rotate = 1; switch(keyCode) { case LEFT: if (operatePuyo.returnX(squareSize) <= 0) break; if (subPuyo != null) if (subPuyo.returnX(squareSize) <= 0) break; operatePuyo.pos.x -= squareSize; if (subPuyo != null) subPuyo.pos.x -= squareSize; break; case RIGHT: if (operatePuyo.returnX(squareSize) >= squareNum.x - 1) break; if (subPuyo != null) if (subPuyo.returnX(squareSize) >= squareNum.x - 1) break; operatePuyo.pos.x += squareSize; if (subPuyo != null) subPuyo.pos.x += squareSize; break; case DOWN: operatePuyo.vec.y = 6; if (subPuyo != null) subPuyo.vec.y = 6; break; case ENTER: rotate = -1; case SHIFT: if (subPuyo == null) break; int operateX = operatePuyo.returnX(squareSize); int operateY = operatePuyo.returnY(squareSize); int subX = subPuyo.returnX(squareSize); int subY = subPuyo.returnY(squareSize); int nextX, nextY; if (operateX == subX) { nextX = (operateY - subY) * rotate; nextY = 0; } else { nextY = -(operateX - subX) * rotate; nextX = 0; } boolean cannotRotate = false; cannotRotate |= operateX + nextX < 0; cannotRotate |= operateY + nextY < 0; cannotRotate |= operateX + nextX > squareNum.x - 1; cannotRotate |= operateY + nextY > squareNum.y - 1; if (cannotRotate) break; if (squares[operateX + nextX][operateY + nextY] != null) break; subPuyo.pos.x = operatePuyo.pos.x + nextX * squareSize; subPuyo.pos.y = operatePuyo.pos.y + nextY * squareSize; break; } } void keyRelease() { if (operatePuyo != null) operatePuyo.vec.y = 3; if (subPuyo != null) subPuyo.vec.y = 3; } void addPuyo(boolean isSub) { PVector puyoPos; PVector puyoVec = new PVector (0, 3); float puyoRad = squareSize; String puyoSta = "FALL"; String puyoTyp; int random = int(random(3)); if (isSub) puyoPos = new PVector (squareNum.x / 2 * squareSize - squareSize / 2, squareSize / 2); else puyoPos = new PVector (squareNum.x / 2 * squareSize - squareSize / 2, squareSize * 3 / 2); if (random == 0) puyoTyp = "RED"; else if (random == 1) puyoTyp = "YELLOW"; else if (random == 2) puyoTyp = "GREEN"; else if (random == 3) puyoTyp = "BLUE"; else puyoTyp = "PURPLE"; Puyo puyo = new Puyo(puyoPos, puyoVec, puyoRad, puyoSta, puyoTyp); if (isSub) operatePuyo = puyo; else subPuyo = puyo; puyos.add(puyo); movePuyos.add(puyo); if (squares[puyo.returnX(squareSize)][puyo.returnY(squareSize)] != null) reset(); } void checkPuyo(Puyo puyo, Puyo beforePuyo) { int puyoX = puyo.returnX(squareSize); int puyoY = puyo.returnY(squareSize); puyo.connectNum = 0; puyo.flag = false; for (int x = -1; x <= 1; x += 2) if (puyoX + x >= 0 && puyoX + x < squareNum.x) { Puyo checkPuyo = squares[puyoX + x][puyoY]; if (checkPuyo != null) if (puyo.checkParents(checkPuyo)) { checkPuyo(checkPuyo, puyo); puyo.connectNum += checkPuyo.connectNum + 1; } } for (int y = -1; y <= 1; y += 2) if (puyoY + y >= 0 && puyoY + y < squareNum.y) { Puyo checkPuyo = squares[puyoX][puyoY + y]; if (checkPuyo != null && checkPuyo != beforePuyo) if (puyo.checkParents(checkPuyo)) { checkPuyo(checkPuyo, puyo); puyo.connectNum += checkPuyo.connectNum + 1; } } } void erasePuyo(Puyo puyo) { println(puyo.parents.size()); for (int i = 0; i < puyo.parents.size(); i++) { erasePuyo(puyo.parents.get(i)); } puyos.remove(puyo); movePuyos.remove(puyo); squares[puyo.returnX(squareSize)][puyo.returnY(squareSize)] = null; } void resetPuyo() { for (Puyo puyo : puyos) { int puyoX = puyo.returnX(squareSize); int puyoY = puyo.returnY(squareSize); if (puyoY <= squareNum.y - 2) if (squares[puyoX][puyoY + 1] == null) { puyo.vec = new PVector(0, 3); puyo.status = "FALL"; puyo.connectNum = 0; puyo.parents.clear(); squares[puyoX][puyoY] = null; } } } }
Puyoクラス
class Puyo { PVector pos; PVector vec; float radius; String status; // STOP, FALL String type; //RED, YELLOW, GREEN, BLUE, PURPLE boolean flag; ArrayList<Puyo> parents = new ArrayList<Puyo>(); int connectNum; Puyo(PVector pos, PVector vec, float radius, String status, String type) { this.pos = pos; this.vec = vec; this.radius = radius; this.status = status; this.type = type; flag = true; connectNum = 0; } void update() { pos.add(vec); } void display() { if (type.equals("RED")) fill(255, 0, 0); else if (type.equals("YELLOW")) fill(255, 255, 0); else if (type.equals("GREEN")) fill(0, 255, 0); else if (type.equals("BLUE")) fill(0, 0, 255); else if (type.equals("PURPLE")) fill(255, 0, 255); ellipse(pos.x, pos.y, radius, radius); } void setStatus(String nextStatus) { switch(nextStatus) { case "STOP": status = "STOP"; vec = new PVector(0, 0); break; case "FALL": status = "FALL"; vec = new PVector(0, 3); break; } } void setParents(Puyo puyo) { parents.add(puyo); } boolean checkParents(Puyo puyo) { if (!type.equals(puyo.type)) return false; if (!puyo.flag) return false; parents.add(puyo); return true; } int returnX(float squareSize) { return int(pos.x / squareSize); } int returnY(float squareSize) { return int(pos.y / squareSize); } }