void TetrisPiece::undoRotation() { if(m_type != TETRIS_SQUARE_PIECE) { if(m_type <= 3){ rotatePiece(); }else{ switch(m_current_rotation) { case 0: setRotation(ROT_270); break; case 1: setRotation(ROT_0); break; case 2: setRotation(ROT_90); break; case 3: setRotation(ROT_180); break; } } } m_current_rotation--; }
void PlayState::update(sf::Time dtTime) { if (moveLeft) { moveLeft = false; move(-1, 0); } if (moveRight) { moveRight = false; move(1, 0); } if (moveDown) { moveDown = false; move(0, 1); } if (moveRotate) { moveRotate = false; rotatePiece(); } if (tickCount.getElapsedTime().asSeconds() > dropDelay) { move(0, 1); tickCount.restart(); } }
void Individual::mutate(unsigned mutationCount) { for (; mutationCount != 0; --mutationCount) { const size_t i = rand() % getArrangedPieces().size(); rotatePiece(i); movePiece(i); } }
static void rotatePieces(PIECE_T *pPieces, uint8_t rot) { if ((pPieces[0].rot ^ rot) & 4) { PIECE_T *p = pPieces; for (int i = 0; i < PIECES; i++, p++) { p->y = 8 - p->y; p->rot = flipPiece(i, p->rot); } } while (pPieces[0].rot != rot) { PIECE_T *p = pPieces; for (int i = 0; i < PIECES; i++, p++) { uint8_t x = p->x; p->x = 12 - p->y; p->y = x - 4; p->rot = rotatePiece(i, p->rot, 1); } } }
static void movePiece(int8_t vx, int8_t vy) { PIECE_T *p = &pieceAry[focusPieceIdx]; if (arduboy.buttonPressed(A_BUTTON)) { int vr = 0; if (arduboy.buttonDown(LEFT_BUTTON)) vr--; if (arduboy.buttonDown(RIGHT_BUTTON)) vr++; if (vr != 0) { arduboy.playScore2(soundRotate, 3); p->rot = rotatePiece(focusPieceIdx, p->rot, vr); isDirty = true; toDrawAll = true; } else if (arduboy.buttonDown(UP_BUTTON | DOWN_BUTTON)) { arduboy.playScore2(soundFlip, 3); p->rot = flipPiece(focusPieceIdx, p->rot); isDirty = true; toDrawAll = true; } if (toDrawAll) { dprint(F("Rotate rot=")); dprintln(p->rot); } } else { int g = (focusPieceIdx < 3) ? 0 : 1; if (p->x + vx < g || p->x + vx >= BOARD_W - g) vx = 0; if (p->y + vy < g || p->y + vy >= BOARD_H - g) vy = 0; if (vx != 0 || vy != 0) { playSoundTick(); p->x += vx; p->y += vy; isDirty = true; toDrawAll = true; } if (arduboy.buttonDown(B_BUTTON)) { if (putPieces()) { arduboy.playScore2(soundPut, 2); state = STATE_FREE; dprintln(F("Release")); } else { uint8_t idx = checkAndRegisterPieces(); isNew = (idx == clearCount); if (idx == lastPatternIdx) { arduboy.playScore2(soundPut, 2); state = STATE_FREE; } else { lastPatternIdx = idx; if (isNew) { arduboy.playScore2(soundNewPattern, 1); clearCount++; saveAndResetCreep(); setGalleryIndex(idx); clearEffectCount = 120; } else { arduboy.playScore2(soundExistedPattern, 1); clearEffectCount = 60; } state = STATE_CLEAR; } dprint(F("Completed! isNew=")); dprintln(isNew); } cursorX = p->x; cursorY = p->y; if (board[p->y][p->x].idx != focusPieceIdx) { cursorY += (board[p->y - 1][p->x].idx == focusPieceIdx) ? -1 : 1; } toDrawAll = true; } } }
void special (int key, int x, int y) { int i = 0; switch (key) { case GLUT_KEY_RIGHT: { if (pausedMode == 0) movePieceX (1); i++; } break; case GLUT_KEY_LEFT: { if (pausedMode == 0) movePieceX (-1); i++; } break; case GLUT_KEY_DOWN: { if ((gameMode == 2) && (pausedMode == 0)) movePieceY (-1); if (gameMode == 1) { startCnt += 1; if (gameInProgress) { if (startCnt > 2) startCnt = 2; } else { if (startCnt > 1) startCnt = 1; } } i++; } break; case GLUT_KEY_UP: { if ((gameMode == 2) && (pausedMode == 0)) { rotatePiece (); break; } if (gameMode == 1) { startCnt -= 1; if (startCnt < 0) startCnt = 0; } i++; } break; case GLUT_KEY_F1: { if ((gameMode == 1) && (startCnt == 0)) { gameMode = 2; pausedMode = 0; resetPit (); gameInProgress = 1; //PlaySound("Sounds/war_cry.wav",NULL,SND_ASYNC); initNewPiece (); } if ((gameMode == 1) && (startCnt == 1)) { exit (0); } if ((gameMode == 1) && (startCnt == 2)) { gameMode = 2; pausedMode = 0; gameInProgress = 1; } i++; } break; } if (i) glutPostRedisplay (); }