int checkEncountGauge(Frame* frame, Frame* inventoryFrame, Frame* statusFrame) { encountGauge += 1; if (encountGauge > 8) { int eob = battleSequence(frame); encountGauge = 0; renderMap(*frame, area, &player); frame->update(); renderInventory(inventoryFrame, &player); renderStatus(statusFrame, &player); return eob; } return -1; }
// Game loop void gameLoop() { int c; // char // Init frames Frame viewFrame(COLS-2, LINES-2, RFOrientation::TOP_LEFT); Frame textFrame(COLS-2, 4, RFOrientation::BOTTOM_LEFT); Frame inventoryFrame(18, 4, RFOrientation::BOTTOM_RIGHT); Frame statusFrame(15, 4, RFOrientation::TOP_RIGHT); int hasText = 0; int showedHint = 0; int showedNothingMessage = 0; plA = player.c_area; plX = player.x; plY = player.y; renderMap(viewFrame, area, &player); viewFrame.update(); renderInventory(&inventoryFrame, &player); renderStatus(&statusFrame, &player); while(1) { c = getch(); if (c == KEY_UP){ if (isValid(area, player.c_area, player.x, player.y - 1) && area[player.c_area][player.x][player.y].doorInfo[D_UP] == DC_OPEN && player.direction == D_UP) { player.y = player.y - 1; } player.direction = D_UP; } else if (c == KEY_RIGHT){ if (isValid(area, player.c_area, player.x + 1, player.y) && area[player.c_area][player.x][player.y].doorInfo[D_RIGHT] == DC_OPEN && player.direction == D_RIGHT) { player.x = player.x + 1; } else if (isValid(area, player.c_area, player.x + 1, player.y) && area[player.c_area][player.x][player.y].doorInfo[D_RIGHT] == DC_LOCKED && player.hasKey) { area[player.c_area][player.x][player.y].doorInfo[D_RIGHT] = DC_OPEN; player.hasKey = 0; } player.direction = D_RIGHT; }else if (c == KEY_DOWN){ if ( isValid(area, player.c_area, player.x, player.y + 1) && area[player.c_area][player.x][player.y].doorInfo[D_DOWN] == DC_OPEN ) { if (player.direction == D_DOWN) { player.y = player.y + 1; } } else if (isValid(area, player.c_area, player.y + 1, player.y) && area[player.c_area][player.x][player.y].doorInfo[D_DOWN] == DC_LOCKED && player.hasKey) { area[player.c_area][player.x][player.y].doorInfo[D_DOWN] = DC_OPEN; player.hasKey = 0; } player.direction = D_DOWN; } else if (c == KEY_LEFT){ if ( isValid(area, player.c_area, player.x - 1, player.y) && area[player.c_area][player.x][player.y].doorInfo[D_LEFT] == DC_OPEN ) { if (player.direction == D_LEFT) { player.x = player.x - 1; } } player.direction = D_LEFT; } hasText = 0; // Render view if (c == 'z') { textFrame.clear(); if (area[player.c_area][player.x][player.y].hasKey) { textFrame.println("キーを見つけた...!"); hasText = 1; player.hasKey = 1; area[player.c_area][player.x][player.y].hasKey = 0; } else if (area[player.c_area][player.x][player.y].hint != "" && !showedHint) { textFrame.println("ヒントを見つけた...\n"); textFrame.println(area[player.c_area][player.x][player.y].hint.c_str()); showedHint = 1; showedNothingMessage = 1; hasText = 1; } else if (area[player.c_area][player.x][player.y].hasPotion && player.hasPotion) { textFrame.println("ポーション見つけたが、持てない..."); hasText = 1; } else if (area[player.c_area][player.x][player.y].hasPotion) { textFrame.println("ポーション見つけた...!"); hasText = 1; player.hasPotion = 1; area[player.c_area][player.x][player.y].hasPotion = 0; } else if (area[player.c_area][player.x][player.y].canJump) { viewFrame.move(0, 0); viewFrame.print(filledWith(viewFrame, "□"), 10); player.c_area = 1; player.x = 7; player.y = 2; } else if (!showedNothingMessage) { textFrame.println("何も無いようだ..."); showedNothingMessage = 1; hasText = 1; } else { showedNothingMessage = 0; hasText = 0; showedHint = 0; } } else if (c == 's') { textFrame.clear(); if (player.hasPotion) { textFrame.println("ポーション使う...?"); textFrame.println("z = はい"); textFrame.println("x = いいえ"); while(1) { c = getch(); if (c == 'z') { textFrame.clear(); textFrame.println("ポーション使いました..."); textFrame.println("HP全回しました"); player.hp = 15; hasText = 1; player.hasPotion = 0; break; } else if (c == 'x'){ textFrame.clear(); textFrame.println("ポーション使うのをやめた..."); textFrame.println("HP全回しました、なんてウソです"); hasText = 1; break; } } } else if (!player.hasPotion) { textFrame.println("ポーションない..."); hasText = 1; } } area[player.c_area][player.x][player.y].playerVisited = 1; renderMap(viewFrame, area, &player); viewFrame.update(); if (hasText) textFrame.update(); renderInventory(&inventoryFrame, &player); renderStatus(&statusFrame, &player); // 前回描画した時からプレイヤーは移動したか? if (isPlayerMoved(plA, plX, plY, player.c_area, player.x, player.y)) { // Zakoがいるなら戦闘 int eob = checkEncountGauge(&viewFrame, &inventoryFrame, &statusFrame); if (eob == EOB_PLAYER_LOST) { gameOver(&viewFrame); return; } } // 特殊ボス会敵 if (area[player.c_area][player.x][player.y].uniqueBossId == 1 && !player.beatenHBoss) { int eob = battleSequence(&viewFrame); if (eob == EOB_PLAYER_LOST) { gameOver(&viewFrame); return; } else if (eob == EOB_PLAYER_BEATEN_BOSS) { gameWon(&viewFrame); return; } } else if (area[player.c_area][player.x][player.y].uniqueBossId == 0) { int eob = battleSequence(&viewFrame); if (eob == EOB_PLAYER_LOST) { gameOver(&viewFrame); return; } else if (eob == EOB_PLAYER_BEATEN_BOSS) { gameWon(&viewFrame); return; } } plA = player.c_area; plX = player.x; plY = player.y; } }
void Player::render() { renderInventory(); SpriteHandler::getInstance()->get(SPRITE_CODE::S_player)->draw(this->getPosition(), SPRITE_SIZE, SPRITE_SIZE); miningAnimation(); }