let bootState=0;let bootErrorText="";let bootOnce=!1;let down_timer=0;function drawBootScreen(){fill("black");const gp=getGraphLoadProgress();const sp=getSoundLoadProgress();const total=gp.total+sp.total;const done=gp.done+sp.done;const rate=(total>0)?int(done*100/total):0;fText("Sword Finger R",180,80,36,"white");if(bootState===1){fText("ファイルを読み込んでいます...",120,150,24,"cyan");fText("画像 "+gp.done+" / "+gp.total,160,210,22,"white");fText("音声 "+sp.done+" / "+sp.total,160,245,22,"white");fText("合計 "+rate+"%",240,295,26,"yellow");sRect(80,330,480,24,"white");if(total>0){fRect(82,332,int(476*done/total),20,"lime")} fText("100%完了までゲームは開始しません",95,400,22,"orange")}else if(bootState===3){fText("ファイル読込に失敗しました",135,150,28,"red");fText("タップ / Enter / Space で再試行",95,220,24,"yellow");if(bootErrorText!==""){fTextN(bootErrorText,40,300,120,18,"white")}}} function buildBootError(graphResult,soundResult){const errLines=[];if(graphResult&&graphResult.failed&&graphResult.failed.length>0){errLines.push("画像失敗: "+graphResult.failed.length+"件");for(let i=0;i<graphResult.failed.length&&i<3;i++){errLines.push(graphResult.failed[i].url)}} if(soundResult&&soundResult.failed&&soundResult.failed.length>0){errLines.push("音声失敗: "+soundResult.failed.length+"件");for(let i=0;i<soundResult.failed.length&&i<3;i++){errLines.push(soundResult.failed[i].url)}} if(errLines.length===0){errLines.push("通信が不安定な可能性があります")} errLines.push("再試行してください");return errLines.join("\n")} function startBootLoad(){if(bootOnce===!0)return;bootOnce=!0;bootState=1;bootErrorText="";canvasSize(DISPLAY_SIZE_X,DISPLAY_SIZE_Y);setFPS(GAME_FPS);Promise.all([loadGraphs(),loadSounds()]).then(function(results){const graphResult=results[0];const soundResult=results[1];if(graphResult.ok!==!0||soundResult.ok!==!0){bootState=3;bootErrorText=buildBootError(graphResult,soundResult);return} clear_flag=0;const ls=loadLS(0);clear_flag=(ls==null)?0:ls;initEffect();bootState=2;document.dispatchEvent(new Event("game-ready"))}).catch(function(e){bootState=3;bootErrorText="例外: "+(e&&e.message?e.message:String(e))})} function retryBootLoad(){bootOnce=!1;startBootLoad()} function setup(){startBootLoad()} function mainloop(){if(bootState!==2){drawBootScreen();if(bootState===3){if(tapC!==0||key[13]>0||key[32]>0){tapC=0;clrKey();retryBootLoad()}} return} timer++;switch(gameScene){case SCENE_P_ATTACK:drawBattleBg();battleTimer();drawEnemy();drawEffect();drawHitNum();drawBattlePlayers();drawNowWord();inputNowWord();inputAuto();moveAlphabet();enemyPp();if(enemy.state===E_DELETE0){setAlp(15);drawImgS(Graphs.BAR_EXP,0,0,640,480);setAlp(100)} break;case SCENE_TITLE:battleSwitch=BATTLE_OFF;title();break;case SCENE_IN_NAME:inputName();break;case SCENE_IN_NAME2:inputName2();break;case SCENE_TOWN:battleSwitch=BATTLE_OFF;town();break;case SCENE_SET_PARTY:setParty();break;case SCENE_EQUIPMENT:equipment();break;case SCENE_EQUIPMENT2:equipment2();break;case SCENE_STATES:states();break;case SCENE_SHOP:shop();break;case SCENE_INN:inn();break;case SCENE_INN2:inn2();break;case SCENE_LV_SHOP:lvShop();break;case SCENE_ITEM:useItem();break;case SCENE_DIFFICULTY:selectDifficulty();break;case SCENE_KEYCONFIG:keyConfig();break;case SCENE_WORD_POSITION:wordPosition();break;case SCENE_SELECT_USE_ITEM:selectUseItem();break;case SCENE_SAVE:gameSave();break;case SCENE_GO_TO_DUNGEON:goToDungeon();break;case SCENE_DUNGEON:dungeonMain();break;case SCENE_DUNGEON_MENU:dungeonMenu();break;case SCENE_DUNGEON_ITEM:dungeonUseItem();break;case SCENE_ENCOUNT:battleSwitch=BATTLE_ON;down_timer=0;encountEnemy();break;case SCENE_S_COMMAND:drawBattleBg();drawEnemy();drawBattlePlayers();selectCommand();break;case SCENE_E_DATA:drawBattleBg();drawEnemy();drawBattlePlayers();drawEnemyData();break;case SCENE_TURN_END:drawBattleBg();drawEnemy();enemyPp();drawBattlePlayers();drawEffect();turnEnd();break;case SCENE_ENEMY_ATTACK:drawBattleBg();drawEnemy();drawBattlePlayers();enemyTurn();drawEffect();break;case SCENE_WIN:battleSwitch=BATTLE_OFF;battleWin();down_timer++;if(down_timer===10){playSE(Sounds.SE_DOWN)} break;case SCENE_LOSE:battleSwitch=BATTLE_OFF;battleLose();break;case SCENE_ENDING:ED();break;case SCENE_FREE_BATTLE:freeBattle();break;case SCENE_HELP_BATTLE:helpBattle();break;case SCENE_SELECT_ENEMY:selectEnemy();break;case SCENE_INFO:info();break}}