bool Player::currPosHasLadder(int x, int y, int &row, int &col) { for (int tempRow = 0; tempRow < ROWS; tempRow++) { for (int tempCol = 0; tempCol < COLUMNS; tempCol++) { if (map[blockNumber(tempRow, tempCol)] == LADDER) { int tempX1 = tempCol*TILE_WIDTH; int tempX2 = (tempCol*TILE_WIDTH)+TILE_WIDTH; int tempY1 = tempRow*TILE_HEIGHT; int tempY2 = (tempRow*TILE_HEIGHT)+TILE_HEIGHT; if (x > tempX1 && x<tempX2 && y>tempY1 && y < tempY2) { row = tempRow; col = tempCol; return true; } } } } return false; }
int Player::getBottomLimOfLadder(int row, int col) { int tempRow = row; while (true) { tempRow++; if (map[blockNumber(tempRow, col)] != LADDER) return ((--tempRow)*TILE_HEIGHT); } return false; }
bool Player::wallIsAhead(int x,int y) { for (int tempRow = 0; tempRow < ROWS; tempRow++) { for (int tempCol = 0; tempCol < COLUMNS; tempCol++) { if (map[blockNumber(tempRow, tempCol)] == FLOOR1 || map[blockNumber(tempRow, tempCol)] == FLOOR2) { int floorX1 = tempCol*TILE_WIDTH; int floorX2 = (tempCol*TILE_WIDTH) + TILE_WIDTH; int floorY1 = tempRow*TILE_HEIGHT; int floorY2 = (tempRow*TILE_HEIGHT) + TILE_HEIGHT; if (x > floorX1 && x < floorX2 && y > floorY1 && y < floorY2) return true; } } } return false; }
bool FBMReference::inSameBlock( const int p1, const int p2, const int p3 = -1, const int p4 = -1 ) const { if( blockNumber( p1 ) != blockNumber( p2 ) ) { return false; } if( p3 != -1 && blockNumber( p3 ) != blockNumber( p1 ) ) { return false; } if( p4 != -1 && blockNumber( p4 ) != blockNumber( p1 ) ) { return false; } return true; // They're all the same! }
void LrcEditor::addTag(const QString &attr, const QString &value) { // ignore empty value if (value.isEmpty()) return ; QRegExp exp("^\\[" + attr + ":.*\\][\\s]{0,}$"); QString newValue = "[" + attr + ":" + value + "]"; bool found = false; for (auto it = document()->begin(); it != document()->end(); it = it.next()) { if (exp.indexIn(it.text()) >= 0) { found = true; qDebug() << "found tag at line: " << it.blockNumber() << qPrintable(it.text()); if (it.text().trimmed() != newValue) { QTextCursor cursor(it); cursor.beginEditBlock(); cursor.select(QTextCursor::LineUnderCursor); cursor.removeSelectedText(); cursor.insertText(newValue); cursor.endEditBlock(); } // we assume there's only one break; } } if (!found) { QTextCursor cursor = textCursor(); cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); cursor.insertText(newValue + m_charNewLine); } }
void Enemy::update() { int playerRow = player->getRow(); int playerCol = player->getCol(); if (checkRow) { if (row == playerRow) { path = dijsktra(AIMap,new Node(AIMap[blockNumber(row, col)], row, col, 0),new Node(AIMap[blockNumber(playerRow,playerCol)],playerRow,playerCol,0)); count = 1; pathLastCol = path[path.size() - 1] % COLUMNS; pathLastRow = path[path.size() - 1] / COLUMNS; checkRow = false; checkCol = true; } } if (checkCol) { if (col == playerCol) { path = dijsktra(AIMap, new Node(AIMap[blockNumber(row, col)], row, col, 0), new Node(AIMap[blockNumber(playerRow, playerCol)], playerRow, playerCol, 0)); count = 1; pathLastCol = path[path.size() - 1] % COLUMNS; pathLastRow = path[path.size() - 1] / COLUMNS; checkCol = false; checkRow = true; } } if (row == pathLastRow && col == pathLastCol) { path = dijsktra(AIMap, new Node(AIMap[blockNumber(row, col)], row, col, 0), new Node(AIMap[blockNumber(playerRow, playerCol)], playerRow, playerCol, 0)); count = 1; pathLastCol = path[path.size() - 1] % COLUMNS; pathLastRow = path[path.size() - 1] / COLUMNS; } indexCol = path[count] % COLUMNS; indexRow = path[count] / COLUMNS; if (row < indexRow) { spriteCurrRow = FOR_DOWN; y += speed; if (y+yOffSet > indexRow * TILE_HEIGHT) { row = indexRow; count++; } if (++currFrame >= frameDelay) { if (++sourceX > 2) sourceX = 1; currFrame = 0; } } if (row > indexRow) { spriteCurrRow = FOR_UP; y -= speed; if ((y+height-yOffSet) < (indexRow+1) * TILE_HEIGHT) { row = indexRow; count++; } if (++currFrame >= frameDelay) { if (++sourceX > 2) sourceX = 1; currFrame = 0; } } if (col < indexCol) { spriteCurrRow = FOR_RIGHT; x += speed; if (x+xOffSet > indexCol * TILE_WIDTH) { col = indexCol; count++; } if (++currFrame >= frameDelay) { if (++sourceX > 2) sourceX = 1; currFrame = 0; } } if (col > indexCol) { spriteCurrRow = FOR_LEFT; x -= speed; if ((x+width-xOffSet) < (indexCol+1) * TILE_WIDTH) { col = indexCol; count++; } if (++currFrame >= frameDelay) { if (++sourceX > 2) sourceX = 1; currFrame = 0; } } }
Enemy::Enemy(ALLEGRO_BITMAP *enemySprite, int map[],Player*player, int curRow, int curCol,PlayerSpriteRow spriteCurrRow) { //copying original map to Player::map for (int i = 0; i < ROWS*COLUMNS; i++) { this->map[i] = map[i]; } //Generating A different map for for dijkstra algorithm for (int row = 0; row < ROWS; row++) { for (int col = 0; col < COLUMNS; col++) { if (map[blockNumber(row + 1, col)] == FLOOR1 || map[blockNumber(row + 1, col)] == FLOOR2 || map[blockNumber(row, col)] == LADDER|| map[blockNumber(row+1, col)] == LADDER) AIMap[blockNumber(row, col)] = 1; else AIMap[blockNumber(row, col)] = 10; } } //setting player up this->spriteCurrRow = spriteCurrRow; this->row = curRow; this->col = curCol; x = col * TILE_WIDTH; y = row * TILE_HEIGHT; indexRow = 0; indexCol = 0; width = TILE_WIDTH; height = TILE_HEIGHT; sourceX = 0; this->enemySprite = enemySprite; this->frameDelay = 8; this->currFrame = 0; this->player = player; checkRow = checkCol = true; xOffSet = 19; yOffSet = 2; count = 1; int playerRow = player->getRow(); int playerCol = player->getCol(); path = dijsktra(AIMap, new Node(AIMap[blockNumber(row, col)], row, col, 0), new Node(AIMap[blockNumber(playerRow, playerCol)], playerRow, playerCol, 0)); pathLastCol = path[path.size() - 1] % COLUMNS; pathLastRow = path[path.size() - 1] / COLUMNS; speed = 4; }