#4
by just_started_PG » 5年前
サンプルコードの続きです。
コード:
//menu.h
void menu_main(void);//メインメニュープロト
void menu_item(void);//アイテムプロト
void menu_sta(void);//ステータスプロト
void menu_skill(void);//特技プロト
void menu_equip(void);//装備プロト
void menu_save(void);//セーブプロト
void menu_title(void);//タイトルプロト
void menu_sta_draw(void);//描画関数プロト
void save_file(int a);//セーブ仕様関数プロト
void load_menu(void);//ロードメニュープロト
void load_file(int a);//ロード仕様関数プロト
void menu_mode(void){
DrawGraph(0,0,window[3],FALSE);//メニュー背景
if(menu == 0){//メイン
menu_main();
}
else if(menu == 1){//アイテム
menu_item();
}
else if(menu == 2){//ステータス
menu_sta();
}
else if(menu == 3){//特技
menu_skill();
}
else if(menu == 4){//装備
menu_equip();
}
else if(menu == 5){//セーブ
menu_save();
}
else if(menu == 6){//タイトル
menu_title();
}
}
void menu_main(void){//メインメニュー
SetFontSize(30);//フォントサイズ変更
DrawString(480,20,"アイテム",color[0]);
DrawString(480,80,"ステータス",color[0]);
DrawString(480,140,"特技",color[0]);
DrawString(480,200,"装備",color[0]);
DrawString(480,260,"セーブ",color[0]);
DrawString(480,320,"タイトル",color[0]);
SetFontSize(20);
DrawString(410,440,"メニューを閉じる【M】",color[0]);
SetFontSize(30);
DrawGraph(440,20 + (60 * menu_cursor),chara[0].chip[1],TRUE);
//カーソル描画
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 5;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 5){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_M] == 1 || key[KEY_INPUT_B] == 1){
now_mode = 0;//マップモードへ
menu_cursor = 0;
SetFontSize(24);//文字サイズを戻す
while(CheckHitKey(KEY_INPUT_M) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
}
else if(key[KEY_INPUT_RETURN] == 1){
switch(menu_cursor){
case 0:menu = 1;//アイテム画面へ
break;
case 1:menu = 2;//ステータス画面へ
break;
case 2:menu = 3;//特技画面へ
break;
case 3:menu = 4;//装備画面へ
break;
case 4:menu = 5;//セーブ画面へ
break;
case 5:menu = 6;//タイトル画面へ
break;
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
}
}
void menu_item(void){//アイテム
char count[5];//個数描画のため
char heal_point[5];//回復量描画のため
int heal;//回復量計算のための変数
int box[5];//アイテム欄の上から何が格納されているか
int item_count = 0;
for(i = 0;i < item_all;i++){
if(bag[i] > 0 && item[i].type == 3){//アイテム[i]がバッグに0より入っていて道具なら
DrawGraph(40,22 + (40 * item_count),item[i].icon,TRUE);//アイコン描画
DrawString(70,20 + (40 * item_count),item[i].name,color[0]);//名前表示
sprintf(count,"%d",bag[i]);
DrawString(200,20 + (40 * item_count),"×",color[0]);
DrawString(240,20 + (40 * item_count),count,color[0]);
box[item_count] = i;//boxにiを格納
item_count += 1;
}
}
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(500,280,"戻る",color[0]);//戻る表示
if(item_step == 0){
if(menu_cursor == item_count){//最大の場合は戻るへ
DrawGraph(460,280,chara[0].chip[1],TRUE);
DrawString(30,350,"メニュー画面へ戻ります",color[0]);//戻るボタン時
}
else{
DrawGraph(10,20 + (40 * menu_cursor),chara[0].chip[1],TRUE);
for(i = 0;i < item[box[menu_cursor]].text_count;i++){
DrawString(30,350 + (35 * i),item[box[menu_cursor]].text[i],color[0]);
//テキスト描画
}
}
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = item_count;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == item_count){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_RETURN] == 1){
if(menu_cursor == item_count){
menu = 0;//メインメニューへ
}
else{
use_item = box[menu_cursor];
menu_cursor = 0;//初期化
item_step = 1;//次のステップへ
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
}
else if(key[KEY_INPUT_B] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
menu = 0;//メインメニューへ
}
}
else if(item_step == 1){
DrawString(30,350 ,item[use_item].name,color[0]);
DrawString(150,350 ,"を使用しますか?",color[0]);
DrawString(80,385 ,"はい",color[0]);
DrawString(80,420 ,"いいえ",color[0]);
DrawGraph(42,380 + (35 * menu_cursor),chara[0].chip[1],TRUE);
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 1;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 1){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_RETURN] == 1){
if(menu_cursor == 0){
item_step = 2;//メインメニューへ
}
else{
use_item = box[menu_cursor];
menu_cursor = 0;//初期化
item_step = 0;//次のステップへ
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
}
else if(key[KEY_INPUT_B] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
item_step = 0;//戻る
}
}
else if(item_step == 2){
DrawString(30,350,"主人公のHPが",color[0]);
if(battle[0].hp + item[use_item].point > status[0].hp){//もし回復量が主人公ステータスを上回ったなら本来のMAXHPまで回復
heal = status[0].hp - battle[0].hp;
sprintf(heal_point,"%d",heal);
battle[0].hp = status[0].hp;
DrawString(260,350,heal_point,color[0]);
DrawString(340,350,"回復しました!",color[0]);
}
else{
sprintf(heal_point,"%d",item[use_item].point);
DrawString(260,350,heal_point,color[0]);
DrawString(340,350,"回復しました!",color[0]);
battle[0].hp = battle[0].hp + item[use_item].point;
}
DrawString(380,425,"PUSH ENTER KEY",color[0]);
while(CheckHitKey(KEY_INPUT_RETURN) == 0);//エンターキー待ち
while(CheckHitKey(KEY_INPUT_RETURN) == 1);//連打抑制
bag[use_item] -= 1;//使用したアイテムを-1する
item_step = 0;//初期化
use_item = 0;//初期化
}
}
void menu_sta(void){//ステータス
menu_sta_draw();//sta描画関数
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 7;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 7){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_LEFT] == 1 &&
bonus - (bonus_dumy[0] + bonus_dumy[1] + bonus_dumy[2] + bonus_dumy[3] + bonus_dumy[4] + bonus_dumy[5]) > 0 && menu_cursor < 6){
if(menu_cursor != 5 || bonus_dumy[5] / (2 + (chara_skill[0].flag * chara_skill[0].flag) - skill_pt )< 1 && chara_skill[0].flag < 7){
//割振り合計が所持BPを超えないように
bonus_dumy[menu_cursor] += 1;
while(CheckHitKey(KEY_INPUT_LEFT) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
}
else if(key[KEY_INPUT_RIGHT] == 1 && bonus_dumy[menu_cursor] > 0 && menu_cursor < 6){//割振りが1以上あるなら
bonus_dumy[menu_cursor] -= 1;
while(CheckHitKey(KEY_INPUT_RIGHT) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == 7 && key[KEY_INPUT_RETURN] == 1){
for(i = 0;i < 6;i++){
bonus_dumy[i] = 0;//初期化
//戻った時に割振りが保存されているとまた入った時に振ったままになってしまうため
}
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 1;//初期化(カーソルがステータスの上へ)
menu = 0;//メインメニューへ
}
else if(key[KEY_INPUT_RETURN] == 1 && menu_cursor == 6){
if(bonus_dumy[0] > 0 || bonus_dumy[1] > 0 || bonus_dumy[2] > 0 ||
bonus_dumy[3] > 0 || bonus_dumy[4] > 0 || bonus_dumy[5] > 0 ){
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(20,350,"ステータスが上昇しました!",color[0]);
status[0].hp += bonus_dumy[0] * 10;//hpz
battle[0].hp += bonus_dumy[0] * 10;//hpz(現在HPにも上昇値分のみプラス)
status[0].tp += bonus_dumy[1] * 5;//tp
battle[0].tp = status[0].tp;//tp(現在TPはステータスまで回復)
status[0].atk += bonus_dumy[2];//atk
status[0].def += bonus_dumy[3];//def
status[0].spd += bonus_dumy[4];//spd
skill_pt += bonus_dumy[5];//skillpt
if(skill_pt >= 2 + (chara_skill[0].flag * chara_skill[0].flag)){//スキルレベルアップポイントまで振ったら
skill_pt = 0;//初期化
chara_skill[0].flag += 1;
DrawString(20,380,"主人公は特技",color[0]);
DrawString(250,380,skill[chara_skill[0].tokugi[chara_skill[0].flag]].name,color[0]);
DrawString(390,380,"を習得した!",color[0]);
}
bonus = bonus - (bonus_dumy[0] + bonus_dumy[1] + bonus_dumy[2] + bonus_dumy[3] + bonus_dumy[4] + bonus_dumy[5]);
//使用したボーナスを引く
WaitTimer(1000);
for(i = 0;i < 6;i++){
bonus_dumy[i] = 0;//初期化
//戻った時に割振りが保存されているとまた入った時に振ったままになってしまうため
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化(カーソルがステータスの上へ)
}
}
}
void menu_skill(void){//特技
char atk_pt[5];//特技攻撃力
char tp_pt[5];//消費tp
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(570,270,"戻る",color[0]);//戻る描画
for(i = 0;i <= chara_skill[0].flag;i++){//スキルレベルが0からなのでレベル以下なら描画
DrawString(60,10 +(40 * i),skill[chara_skill[0].tokugi[i]].name,color[0]);
}
if(menu_cursor <= chara_skill[0].flag){//スキルレベル以下ならカーソルを特技へ、違うなら戻るへカーソル
DrawGraph(20,10 + (menu_cursor * 40),chara[0].chip[1],TRUE);
}
else{
DrawGraph(530,270,chara[0].chip[1],TRUE);
}
if(menu_cursor <= chara_skill[0].flag){//特技にカーソルが乗っているなら情報を描画
sprintf(atk_pt,"%d",skill[chara_skill[0].tokugi[menu_cursor]].point);
sprintf(tp_pt,"%d",skill[chara_skill[0].tokugi[menu_cursor]].tp);
DrawString(40,360,"特技攻撃力:",color[0]);
DrawString(40,400,"消費TP:",color[0]);
DrawString(260,360,atk_pt,color[0]);
DrawString(260,400,tp_pt,color[0]);
}
else//違うなら戻るへ
DrawString(40,360,"メニュートップへ戻る",color[0]);
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = chara_skill[0].flag + 1;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == chara_skill[0].flag + 1){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == chara_skill[0].flag + 1 && key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 2;//初期化(カーソルがステータスの上へ)
menu = 0;//メインメニューへ
}
}
void menu_equip(void){//装備
int box[2][5];//アイテム欄の上から何が格納されているか
int item_count[2] = {0};
char e_point[5];//武器防具のパラメーター
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(570,270,"戻る",color[0]);//戻る描画
for(i = 0;i < item_all;i++){
if(bag[i] > 0 && item[i].type == 1 ){//アイテム[i]がバッグに0より入っていて武器なら
DrawGraph(40,22 + (40 * item_count[0]),item[i].icon,TRUE);//アイコン描画
DrawString(70,20 + (40 * item_count[0]),item[i].name,color[0]);//名前表示
box[0][item_count[0]] = i;//boxにiを格納
if(s_equip[0] == i){
DrawString(240,20 + (40 * item_count[0]),"E",color[0]);//名前表示
}
item_count[0] += 1;
}
else if(bag[i] > 0 && item[i].type == 2 ){//アイテム[i]がバッグに0より入っていて防具なら
DrawGraph(340,22 + (40 * item_count[1]),item[i].icon,TRUE);//アイコン描画
DrawString(370,20 + (40 * item_count[1]),item[i].name,color[0]);//名前表示
box[1][item_count[1]] = i;//boxにiを格納
if(s_equip[1] == i){
DrawString(540,20 + (40 * item_count[1]),"E",color[0]);//名前表示
}
item_count[1] += 1;
}
}
if(menu_cursor < item_count[0]){//武器のカーソル
sprintf(e_point,"%d",item[box[0][menu_cursor]].point);//武器の攻撃力変換
DrawGraph(10,20 + (menu_cursor * 40),chara[0].chip[1],TRUE);
DrawString(40,340,"武器攻撃力:",color[0]);
DrawString(40,370,"説明:",color[0]);
DrawString(240,340,e_point,color[0]);
for(i = 0;i < item[box[0][menu_cursor]].text_count;i++){//テキストカウント分描画
DrawString(160,370 +(i * 30),item[box[0][menu_cursor]].text[i],color[0]);//テキスト描画
}
}
else if(menu_cursor < item_count[0] + item_count[1]){//防具のカーソル
sprintf(e_point,"%d",item[box[1][menu_cursor - item_count[0]]].point);//防具の防御力変換
DrawGraph(310,20 + ((menu_cursor - item_count[0]) * 40),chara[0].chip[1],TRUE);
DrawString(40,340,"防具防御力:",color[0]);
DrawString(40,370,"説明:",color[0]);
DrawString(240,340,e_point,color[0]);
for(i = 0;i < item[box[1][menu_cursor - item_count[0]]].text_count;i++){//テキストカウント分描画
DrawString(160,370 +(i * 30),item[box[1][menu_cursor - item_count[0]]].text[i],color[0]);//テキスト描画
}
}
else{//戻るの時
DrawGraph(540,270,chara[0].chip[1],TRUE);
DrawString(40,340,"トップメニューに戻る",color[0]);
}
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = item_count[0] + item_count[1];//武器・防具の合計
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == item_count[0] + item_count[1]){//武器防具の合計が最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == item_count[0] + item_count[1] && key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 3;//初期化(カーソルがステータスの上へ)
menu = 0;//メインメニューへ
}
else if(key[KEY_INPUT_RETURN] == 1){
if(menu_cursor < item_count[0]){
//選んでいるのが武器の場合
s_equip[0] = box[0][menu_cursor];
}
else if(menu_cursor < item_count[0] + item_count[1]){
//選んでいるのが防具の場合
s_equip[1] = box[1][menu_cursor - item_count[0]];
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
}
}
void menu_save(void){//セーブ
static int a[3][5];//ステータスを画面で描画するために入れておく配列
char b[5][20];//ステータス描画用
FILE *fp;
fp = fopen("save_0.txt","r");//セーブロード画面用要素テキストファイルオープン
for(i = 0;i < 3;i++){
fscanf(fp,"%d %d %d %d %d",&a[i][0],&a[i][1],&a[i][2],&a[i][3],&a[i][4]);//セーブデータのステータス読み込み
}
fclose(fp);
LoadGraphScreen(0,0,"背景/ロード.jpg",FALSE);
for(i = 0;i < 3;i++){//セーブ枠3つ描画
DrawGraph(0,-20 +(160 * i),window[1],TRUE);
if(a[i][0] <= 0){//セーブデータステータスHPが格納されていない(つまり0)なら
DrawString(200,60 +(160 * i),"データがありません。",color[2]);
}
else{
DrawGraph(50,30 + (160 * i),chara[0].face[0],TRUE);//主人公の顔画像描画
sprintf(b[0],"%d",a[i][0]);//HP変換
sprintf(b[1],"%d",a[i][1]);//TP変換
sprintf(b[2],"%d",a[i][2]);//ATK変換
sprintf(b[3],"%d",a[i][3]);//DEF変換
sprintf(b[4],"%d",a[i][4]);//SPD変換
DrawString(200,20 +(160 * i),"最大HP:",color[2]);//HP描画
DrawString(310,20 +(160 * i),b[0],color[2]);//HP描画
DrawString(400,20 +(160 * i),"最大TP:",color[2]);//TP描画
DrawString(510,20 +(160 * i),b[1],color[2]);//TP描画
DrawString(200,60 +(160 * i),"攻撃力:",color[2]);//ATK描画
DrawString(310,60 +(160 * i),b[2],color[2]);//ATK描画
DrawString(400,60 +(160 * i),"防御力:",color[2]);//DEF描画
DrawString(510,60 +(160 * i),b[3],color[2]);//DEF描画
DrawString(200,100 +(160 * i),"素早さ:",color[2]);//SPD描画
DrawString(310,100 +(160 * i),b[4],color[2]);//SPD描画
}
}
SetFontSize(16);
DrawString(440,460,"メニューに戻る",color[2]);
SetFontSize(30);
if(menu_cursor == 3){
DrawGraph(410,460,chara[0].chip[1],TRUE);
}
else{
DrawGraph(0,60 +(160 * menu_cursor),chara[0].chip[1],TRUE);
}
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 3;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 3){
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == 3 && key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 4;//初期化(カーソルがセーブの上へ)
menu = 0;//メインメニューへ
}
else if(key[KEY_INPUT_RETURN] == 1){ //決定
save_file(menu_cursor);
fp = fopen("save_0.txt","w");
a[menu_cursor][0] = status[0].hp;//主人公のMAXHP
a[menu_cursor][1] = status[0].tp;//主人公のMAXTP
a[menu_cursor][2] = status[0].atk;//主人公のATK
a[menu_cursor][3] = status[0].def;//主人公のDEF
a[menu_cursor][4] = status[0].spd;//主人公のSPD
for(i = 0;i < 3;i++){
fprintf(fp,"%d %d %d %d %d \n",a[i][0],a[i][1],a[i][2],a[i][3],a[i][4]);
}
fclose(fp);
LoadGraphScreen(0,0,"背景/セーブロード.jpg",FALSE);
DrawString(160,240,"セーブしました",color[2]);
WaitTimer(1000);
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
}
}
void menu_title(void){//タイトル
LoadGraphScreen(0,0,"背景/ロード.jpg",FALSE);
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(40,350,"本当にタイトルに戻りますか?",color[0]);
DrawString(490,390,"はい",color[0]);
DrawString(490,430,"いいえ",color[0]);
DrawGraph(450,390 + (menu_cursor * 40),chara[0].chip[1],TRUE);
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 1;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 1){
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == 1 && key[KEY_INPUT_RETURN] == 1){//いいえの場合
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 5;//初期化(カーソルがステータスの上へ)
menu = 0;//メインメニューへ
}
else if(key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
now_mode = 6;//トップ画面へ
SetFontSize(24);//文字サイズを戻す
}
}
void menu_sta_draw(void){//sta描画関数
char st[2][11][20];//ステータス数値描画用
char wari[7][20];//ボーナス割り振り描画用
//ボーナス割り振り後の文字のために2列
DrawGraph(20,20,chara[0].face[0],FALSE);//主人公の顔
DrawString(140,20,chara[0].name,color[0]);//名前描画
DrawString(520,0,"BP振り",color[0]);
DrawString(540,40,"割振る",color[0]);//割振る描画
DrawString(540,80,"戻る",color[0]);//戻る描画
//カーソル画像描画
if(menu_cursor > 5){
DrawGraph(500,40 + ((menu_cursor - 6)* 40),chara[0].chip[1],TRUE);
}
else if(menu_cursor == 5){
DrawGraph(540,360,chara[0].chip[1],TRUE);
}
else{
DrawGraph(540,120 + (menu_cursor * 40),chara[0].chip[1],TRUE);
}
//int型からchar型へ変換
sprintf(st[0][0],"%d",status[0].hp);
sprintf(st[0][1],"%d",status[0].tp);
sprintf(st[0][2],"%d",status[0].atk);
sprintf(st[0][3],"%d",status[0].def);
sprintf(st[0][4],"%d",status[0].spd);
sprintf(st[0][5],"%d",chara_skill[0].flag);
//hpとtpのみ現在数値も変換
sprintf(st[0][6],"%d",battle[0].hp);
sprintf(st[0][7],"%d",battle[0].tp);
//bonusも変換
sprintf(st[0][8],"%d",bonus);
//特技ポイント
sprintf(st[0][9],"%d",skill_pt);
sprintf(st[0][10],"%d",2 + (chara_skill[0].flag * chara_skill[0].flag));//next(2 + レベルの2乗)
//int型からchar型へ変換(bonus後)
sprintf(st[1][0],"%d",status[0].hp + ( 10 * bonus_dumy[0]));
sprintf(st[1][1],"%d",status[0].tp + ( 5 * bonus_dumy[1]));
sprintf(st[1][2],"%d",status[0].atk + bonus_dumy[2]);
sprintf(st[1][3],"%d",status[0].def + bonus_dumy[3]);
sprintf(st[1][4],"%d",status[0].spd + bonus_dumy[4]);
sprintf(st[1][5],"%d",chara_skill[0].flag + bonus_dumy[5] / (2 + (chara_skill[0].flag * chara_skill[0].flag) - skill_pt ));
//hpとtpのみ現在数値も変換
sprintf(st[1][6],"%d",battle[0].hp + ( 10 * bonus_dumy[0]));
sprintf(st[1][7],"%d",status[0].tp + ( 5 * bonus_dumy[1]));
//bonusも変換
sprintf(st[1][8],"%d",bonus - (bonus_dumy[0] + bonus_dumy[1] + bonus_dumy[2] + bonus_dumy[3] + bonus_dumy[4] + bonus_dumy[5]));
//特技ポイント
sprintf(st[1][9],"%d",skill_pt + bonus_dumy[5]);
sprintf(st[1][10],"%d",2 + (chara_skill[0].flag * chara_skill[0].flag));//next(2 + レベルの2乗)
//文字を描画
DrawString(120,120,"HP",color[0]);
DrawString(120,160,"TP",color[0]);
DrawString(120,200,"攻撃力",color[0]);
DrawString(120,240,"防御力",color[0]);
DrawString(120,280,"素早さ",color[0]);
DrawString(120,320,"特技Lv.",color[0]);
DrawString(120,360,"特技pt.",color[0]);
DrawString(120,400,"BONUSpt.",color[0]);
SetFontSize(12);
DrawString(20,450,"←キー:BP振り →キー:BP戻し Bキーor戻るでENTER:前画面へ 割振るでENTER:割り振り確定",color[0]);
SetFontSize(30);
//実際の数値描画
DrawString(310,120,st[0][0],color[0]);//hp
DrawString(310,160,st[0][1],color[0]);//tp
DrawString(240,200,st[0][2],color[0]);//atk
DrawString(240,240,st[0][3],color[0]);//def
DrawString(240,280,st[0][4],color[0]);//spd
DrawString(240,320,st[0][5],color[0]);//特技レベル
DrawString(240,120,st[0][6],color[0]);//hp2
DrawString(240,160,st[0][7],color[0]);//tp2
DrawString(295,120,"/",color[0]);
DrawString(295,160,"/",color[0]);
DrawString(240,400,st[0][8],color[0]);//bonus
if(chara_skill[0].flag >= 7){
DrawString(240,360,"MAX",color[0]);//skill_pt
DrawString(310,360,"MAX",color[0]);//skill_pt
}
else{
DrawString(240,360,st[0][9],color[0]);//skill_pt
DrawString(310,360,st[0][10],color[0]);//skill_pt
}
DrawString(295,360,"/",color[0]);
//カーソル
DrawString(375,120,"→",color[2]);
DrawString(375,160,"→",color[2]);
DrawString(375,200,"→",color[2]);
DrawString(375,240,"→",color[2]);
DrawString(375,280,"→",color[2]);
DrawString(375,320,"→",color[2]);
DrawString(375,360,"→",color[2]);
DrawString(375,400,"→",color[2]);
//ステータス上昇後
DrawString(480,120,st[1][0],color[2]);//hp
DrawString(480,160,st[1][1],color[2]);//tp
DrawString(410,200,st[1][2],color[2]);//atk
DrawString(410,240,st[1][3],color[2]);//def
DrawString(410,280,st[1][4],color[2]);//spd
DrawString(410,320,st[1][5],color[2]);//特技レベル
DrawString(410,120,st[1][6],color[2]);//hp2
DrawString(410,160,st[1][7],color[2]);//tp2
DrawString(470,120,"/",color[2]);
DrawString(470,160,"/",color[2]);
DrawString(410,400,st[1][8],color[2]);//bonus
if(chara_skill[0].flag >= 7){
DrawString(410,360,"MAX",color[2]);//skill_pt
DrawString(480,360,"MAX",color[2]);//skill_pt
}
else{
DrawString(410,360,st[1][9],color[2]);//skill_pt
DrawString(480,360,st[1][10],color[2]);//skill_pt
}
DrawString(470,360,"/",color[2]);
//ボーナス割り振り変換
sprintf(wari[0],"%d",bonus_dumy[0]);
sprintf(wari[1],"%d",bonus_dumy[1]);
sprintf(wari[2],"%d",bonus_dumy[2]);
sprintf(wari[3],"%d",bonus_dumy[3]);
sprintf(wari[4],"%d",bonus_dumy[4]);
sprintf(wari[5],"%d",bonus_dumy[5]);
//ボーナス割り振り
DrawString(580,120,wari[0],color[0]);//hp
DrawString(580,160,wari[1],color[0]);//tp
DrawString(580,200,wari[2],color[0]);//atk
DrawString(580,240,wari[3],color[0]);//def
DrawString(580,280,wari[4],color[0]);//spd
DrawString(580,360,wari[5],color[0]);//特技pt
}
void save_file(int a){
FILE *fp;
char filename[3][255] = {"save_1.txt","save_2.txt","save_3.txt"};
fp = fopen(filename[a],"w");
fprintf(fp,"%d %d %d %d %d %d %d %d %d \n",now_map,s_pos_x,s_pos_y,s_vector,vector_check,now_bgm,en_count,s_equip[0],s_equip[1]);
for(i=0;i < 15;i++){//バッグの中身
fprintf(fp,"%d \n",bag[i]);
}
for(i=0;i < 32;i++){//イベントフラグ
fprintf(fp,"%d \n",chara_eve[i].flag);
}
//主人公ステータス
fprintf(fp,"%d %d %d %d %d %d %d %d %d %d \n",status[0].hp,status[0].tp,battle[0].hp,battle[0].tp,
status[0].atk,status[0].def,status[0].spd,chara_skill[0].flag,bonus,skill_pt);
fclose(fp);
}
void load_menu(void){
SetFontSize(30);
int a[3][5];//ステータスを画面で描画するために入れておく配列
char b[5][5];//ステータス描画用
FILE *fp;
fp = fopen("save_0.txt","r");//セーブロード画面用要素テキストファイルオープン
for(i = 0;i < 3;i++){
fscanf(fp,"%d %d %d %d %d",&a[i][0],&a[i][1],&a[i][2],&a[i][3],&a[i][4]);//セーブデータのステータス読み込み
}
fclose(fp);
LoadGraphScreen(0,0,"背景/ロード.jpg",FALSE);
for(i = 0;i < 3;i++){//セーブ枠3つ描画
DrawGraph(0,-20 +(160 * i),window[1],TRUE);
if(a[i][0] <= 0){//セーブデータステータスHPが格納されていない(つまり0)なら
DrawString(200,60 +(160 * i),"データがありません。",color[2]);
}
else{
DrawGraph(50,30 + (160 * i),chara[0].face[0],TRUE);//主人公の顔画像描画
sprintf(b[0],"%d",a[i][0]);//HP変換
sprintf(b[1],"%d",a[i][1]);//TP変換
sprintf(b[2],"%d",a[i][2]);//ATK変換
sprintf(b[3],"%d",a[i][3]);//DEF変換
sprintf(b[4],"%d",a[i][4]);//SPD変換
DrawString(200,20 +(160 * i),"最大HP:",color[2]);//HP描画
DrawString(310,20 +(160 * i),b[0],color[2]);//HP描画
DrawString(400,20 +(160 * i),"最大TP:",color[2]);//TP描画
DrawString(510,20 +(160 * i),b[1],color[2]);//TP描画
DrawString(200,60 +(160 * i),"攻撃力:",color[2]);//ATK描画
DrawString(310,60 +(160 * i),b[2],color[2]);//ATK描画
DrawString(400,60 +(160 * i),"防御力:",color[2]);//DEF描画
DrawString(510,60 +(160 * i),b[3],color[2]);//DEF描画
DrawString(200,100 +(160 * i),"素早さ:",color[2]);//SPD描画
DrawString(310,100 +(160 * i),b[4],color[2]);//SPD描画
}
}
SetFontSize(16);
DrawString(440,460,"トップ画面に戻る",color[2]);
SetFontSize(30);
if(menu_cursor == 3){
DrawGraph(410,460,chara[0].chip[1],TRUE);
}
else{
DrawGraph(0,60 +(160 * menu_cursor),chara[0].chip[1],TRUE);
}
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 3;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 3){
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == 3 && key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 1;//初期化(カーソルがセーブの上へ)
SetFontSize(24);//初期化
now_mode = 6;//トップ画面へ
}
else if(key[KEY_INPUT_RETURN] == 1 && a[menu_cursor][0] > 0){ //データがない状態じゃない、つまりMAXHPが1以上あるデータなら
load_file(menu_cursor);
LoadGraphScreen(0,0,"背景/セーブロード.jpg",FALSE);
DrawString(160,240,"ロードしました",color[2]);
WaitTimer(1000);
SetFontSize(24);//初期化
now_mode = 0;//マップへ
menu_cursor = 0;
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
}
}
void load_file(int a){
FILE *fp;
char filename[3][255] = {"save_1.txt","save_2.txt","save_3.txt"};
fp = fopen(filename[a],"r");
fscanf(fp,"%d %d %d %d %d %d %d %d %d",&now_map,&s_pos_x,&s_pos_y,&s_vector,&vector_check,&now_bgm,&en_count,&s_equip[0],&s_equip[1]);
for(i=0;i < 15;i++){//バッグの中身
fscanf(fp,"%d",&bag[i]);
}
for(i=0;i < 32;i++){//イベントフラグ
fscanf(fp,"%d",&chara_eve[i].flag);
}
//主人公ステータス
fscanf(fp,"%d %d %d %d %d %d %d %d %d %d",&status[0].hp,&status[0].tp,&battle[0].hp,&battle[0].tp,
&status[0].atk,&status[0].def,&status[0].spd,&chara_skill[0].flag,&bonus,&skill_pt);
fclose(fp);
}
サンプルコードの続きです。
[code]//menu.h
void menu_main(void);//メインメニュープロト
void menu_item(void);//アイテムプロト
void menu_sta(void);//ステータスプロト
void menu_skill(void);//特技プロト
void menu_equip(void);//装備プロト
void menu_save(void);//セーブプロト
void menu_title(void);//タイトルプロト
void menu_sta_draw(void);//描画関数プロト
void save_file(int a);//セーブ仕様関数プロト
void load_menu(void);//ロードメニュープロト
void load_file(int a);//ロード仕様関数プロト
void menu_mode(void){
DrawGraph(0,0,window[3],FALSE);//メニュー背景
if(menu == 0){//メイン
menu_main();
}
else if(menu == 1){//アイテム
menu_item();
}
else if(menu == 2){//ステータス
menu_sta();
}
else if(menu == 3){//特技
menu_skill();
}
else if(menu == 4){//装備
menu_equip();
}
else if(menu == 5){//セーブ
menu_save();
}
else if(menu == 6){//タイトル
menu_title();
}
}
void menu_main(void){//メインメニュー
SetFontSize(30);//フォントサイズ変更
DrawString(480,20,"アイテム",color[0]);
DrawString(480,80,"ステータス",color[0]);
DrawString(480,140,"特技",color[0]);
DrawString(480,200,"装備",color[0]);
DrawString(480,260,"セーブ",color[0]);
DrawString(480,320,"タイトル",color[0]);
SetFontSize(20);
DrawString(410,440,"メニューを閉じる【M】",color[0]);
SetFontSize(30);
DrawGraph(440,20 + (60 * menu_cursor),chara[0].chip[1],TRUE);
//カーソル描画
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 5;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 5){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_M] == 1 || key[KEY_INPUT_B] == 1){
now_mode = 0;//マップモードへ
menu_cursor = 0;
SetFontSize(24);//文字サイズを戻す
while(CheckHitKey(KEY_INPUT_M) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
}
else if(key[KEY_INPUT_RETURN] == 1){
switch(menu_cursor){
case 0:menu = 1;//アイテム画面へ
break;
case 1:menu = 2;//ステータス画面へ
break;
case 2:menu = 3;//特技画面へ
break;
case 3:menu = 4;//装備画面へ
break;
case 4:menu = 5;//セーブ画面へ
break;
case 5:menu = 6;//タイトル画面へ
break;
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
}
}
void menu_item(void){//アイテム
char count[5];//個数描画のため
char heal_point[5];//回復量描画のため
int heal;//回復量計算のための変数
int box[5];//アイテム欄の上から何が格納されているか
int item_count = 0;
for(i = 0;i < item_all;i++){
if(bag[i] > 0 && item[i].type == 3){//アイテム[i]がバッグに0より入っていて道具なら
DrawGraph(40,22 + (40 * item_count),item[i].icon,TRUE);//アイコン描画
DrawString(70,20 + (40 * item_count),item[i].name,color[0]);//名前表示
sprintf(count,"%d",bag[i]);
DrawString(200,20 + (40 * item_count),"×",color[0]);
DrawString(240,20 + (40 * item_count),count,color[0]);
box[item_count] = i;//boxにiを格納
item_count += 1;
}
}
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(500,280,"戻る",color[0]);//戻る表示
if(item_step == 0){
if(menu_cursor == item_count){//最大の場合は戻るへ
DrawGraph(460,280,chara[0].chip[1],TRUE);
DrawString(30,350,"メニュー画面へ戻ります",color[0]);//戻るボタン時
}
else{
DrawGraph(10,20 + (40 * menu_cursor),chara[0].chip[1],TRUE);
for(i = 0;i < item[box[menu_cursor]].text_count;i++){
DrawString(30,350 + (35 * i),item[box[menu_cursor]].text[i],color[0]);
//テキスト描画
}
}
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = item_count;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == item_count){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_RETURN] == 1){
if(menu_cursor == item_count){
menu = 0;//メインメニューへ
}
else{
use_item = box[menu_cursor];
menu_cursor = 0;//初期化
item_step = 1;//次のステップへ
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
}
else if(key[KEY_INPUT_B] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
menu = 0;//メインメニューへ
}
}
else if(item_step == 1){
DrawString(30,350 ,item[use_item].name,color[0]);
DrawString(150,350 ,"を使用しますか?",color[0]);
DrawString(80,385 ,"はい",color[0]);
DrawString(80,420 ,"いいえ",color[0]);
DrawGraph(42,380 + (35 * menu_cursor),chara[0].chip[1],TRUE);
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 1;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 1){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_RETURN] == 1){
if(menu_cursor == 0){
item_step = 2;//メインメニューへ
}
else{
use_item = box[menu_cursor];
menu_cursor = 0;//初期化
item_step = 0;//次のステップへ
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
}
else if(key[KEY_INPUT_B] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化
item_step = 0;//戻る
}
}
else if(item_step == 2){
DrawString(30,350,"主人公のHPが",color[0]);
if(battle[0].hp + item[use_item].point > status[0].hp){//もし回復量が主人公ステータスを上回ったなら本来のMAXHPまで回復
heal = status[0].hp - battle[0].hp;
sprintf(heal_point,"%d",heal);
battle[0].hp = status[0].hp;
DrawString(260,350,heal_point,color[0]);
DrawString(340,350,"回復しました!",color[0]);
}
else{
sprintf(heal_point,"%d",item[use_item].point);
DrawString(260,350,heal_point,color[0]);
DrawString(340,350,"回復しました!",color[0]);
battle[0].hp = battle[0].hp + item[use_item].point;
}
DrawString(380,425,"PUSH ENTER KEY",color[0]);
while(CheckHitKey(KEY_INPUT_RETURN) == 0);//エンターキー待ち
while(CheckHitKey(KEY_INPUT_RETURN) == 1);//連打抑制
bag[use_item] -= 1;//使用したアイテムを-1する
item_step = 0;//初期化
use_item = 0;//初期化
}
}
void menu_sta(void){//ステータス
menu_sta_draw();//sta描画関数
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 7;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 7){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_LEFT] == 1 &&
bonus - (bonus_dumy[0] + bonus_dumy[1] + bonus_dumy[2] + bonus_dumy[3] + bonus_dumy[4] + bonus_dumy[5]) > 0 && menu_cursor < 6){
if(menu_cursor != 5 || bonus_dumy[5] / (2 + (chara_skill[0].flag * chara_skill[0].flag) - skill_pt )< 1 && chara_skill[0].flag < 7){
//割振り合計が所持BPを超えないように
bonus_dumy[menu_cursor] += 1;
while(CheckHitKey(KEY_INPUT_LEFT) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
}
else if(key[KEY_INPUT_RIGHT] == 1 && bonus_dumy[menu_cursor] > 0 && menu_cursor < 6){//割振りが1以上あるなら
bonus_dumy[menu_cursor] -= 1;
while(CheckHitKey(KEY_INPUT_RIGHT) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == 7 && key[KEY_INPUT_RETURN] == 1){
for(i = 0;i < 6;i++){
bonus_dumy[i] = 0;//初期化
//戻った時に割振りが保存されているとまた入った時に振ったままになってしまうため
}
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 1;//初期化(カーソルがステータスの上へ)
menu = 0;//メインメニューへ
}
else if(key[KEY_INPUT_RETURN] == 1 && menu_cursor == 6){
if(bonus_dumy[0] > 0 || bonus_dumy[1] > 0 || bonus_dumy[2] > 0 ||
bonus_dumy[3] > 0 || bonus_dumy[4] > 0 || bonus_dumy[5] > 0 ){
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(20,350,"ステータスが上昇しました!",color[0]);
status[0].hp += bonus_dumy[0] * 10;//hpz
battle[0].hp += bonus_dumy[0] * 10;//hpz(現在HPにも上昇値分のみプラス)
status[0].tp += bonus_dumy[1] * 5;//tp
battle[0].tp = status[0].tp;//tp(現在TPはステータスまで回復)
status[0].atk += bonus_dumy[2];//atk
status[0].def += bonus_dumy[3];//def
status[0].spd += bonus_dumy[4];//spd
skill_pt += bonus_dumy[5];//skillpt
if(skill_pt >= 2 + (chara_skill[0].flag * chara_skill[0].flag)){//スキルレベルアップポイントまで振ったら
skill_pt = 0;//初期化
chara_skill[0].flag += 1;
DrawString(20,380,"主人公は特技",color[0]);
DrawString(250,380,skill[chara_skill[0].tokugi[chara_skill[0].flag]].name,color[0]);
DrawString(390,380,"を習得した!",color[0]);
}
bonus = bonus - (bonus_dumy[0] + bonus_dumy[1] + bonus_dumy[2] + bonus_dumy[3] + bonus_dumy[4] + bonus_dumy[5]);
//使用したボーナスを引く
WaitTimer(1000);
for(i = 0;i < 6;i++){
bonus_dumy[i] = 0;//初期化
//戻った時に割振りが保存されているとまた入った時に振ったままになってしまうため
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 0;//初期化(カーソルがステータスの上へ)
}
}
}
void menu_skill(void){//特技
char atk_pt[5];//特技攻撃力
char tp_pt[5];//消費tp
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(570,270,"戻る",color[0]);//戻る描画
for(i = 0;i <= chara_skill[0].flag;i++){//スキルレベルが0からなのでレベル以下なら描画
DrawString(60,10 +(40 * i),skill[chara_skill[0].tokugi[i]].name,color[0]);
}
if(menu_cursor <= chara_skill[0].flag){//スキルレベル以下ならカーソルを特技へ、違うなら戻るへカーソル
DrawGraph(20,10 + (menu_cursor * 40),chara[0].chip[1],TRUE);
}
else{
DrawGraph(530,270,chara[0].chip[1],TRUE);
}
if(menu_cursor <= chara_skill[0].flag){//特技にカーソルが乗っているなら情報を描画
sprintf(atk_pt,"%d",skill[chara_skill[0].tokugi[menu_cursor]].point);
sprintf(tp_pt,"%d",skill[chara_skill[0].tokugi[menu_cursor]].tp);
DrawString(40,360,"特技攻撃力:",color[0]);
DrawString(40,400,"消費TP:",color[0]);
DrawString(260,360,atk_pt,color[0]);
DrawString(260,400,tp_pt,color[0]);
}
else//違うなら戻るへ
DrawString(40,360,"メニュートップへ戻る",color[0]);
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = chara_skill[0].flag + 1;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == chara_skill[0].flag + 1){//現在最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == chara_skill[0].flag + 1 && key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 2;//初期化(カーソルがステータスの上へ)
menu = 0;//メインメニューへ
}
}
void menu_equip(void){//装備
int box[2][5];//アイテム欄の上から何が格納されているか
int item_count[2] = {0};
char e_point[5];//武器防具のパラメーター
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(570,270,"戻る",color[0]);//戻る描画
for(i = 0;i < item_all;i++){
if(bag[i] > 0 && item[i].type == 1 ){//アイテム[i]がバッグに0より入っていて武器なら
DrawGraph(40,22 + (40 * item_count[0]),item[i].icon,TRUE);//アイコン描画
DrawString(70,20 + (40 * item_count[0]),item[i].name,color[0]);//名前表示
box[0][item_count[0]] = i;//boxにiを格納
if(s_equip[0] == i){
DrawString(240,20 + (40 * item_count[0]),"E",color[0]);//名前表示
}
item_count[0] += 1;
}
else if(bag[i] > 0 && item[i].type == 2 ){//アイテム[i]がバッグに0より入っていて防具なら
DrawGraph(340,22 + (40 * item_count[1]),item[i].icon,TRUE);//アイコン描画
DrawString(370,20 + (40 * item_count[1]),item[i].name,color[0]);//名前表示
box[1][item_count[1]] = i;//boxにiを格納
if(s_equip[1] == i){
DrawString(540,20 + (40 * item_count[1]),"E",color[0]);//名前表示
}
item_count[1] += 1;
}
}
if(menu_cursor < item_count[0]){//武器のカーソル
sprintf(e_point,"%d",item[box[0][menu_cursor]].point);//武器の攻撃力変換
DrawGraph(10,20 + (menu_cursor * 40),chara[0].chip[1],TRUE);
DrawString(40,340,"武器攻撃力:",color[0]);
DrawString(40,370,"説明:",color[0]);
DrawString(240,340,e_point,color[0]);
for(i = 0;i < item[box[0][menu_cursor]].text_count;i++){//テキストカウント分描画
DrawString(160,370 +(i * 30),item[box[0][menu_cursor]].text[i],color[0]);//テキスト描画
}
}
else if(menu_cursor < item_count[0] + item_count[1]){//防具のカーソル
sprintf(e_point,"%d",item[box[1][menu_cursor - item_count[0]]].point);//防具の防御力変換
DrawGraph(310,20 + ((menu_cursor - item_count[0]) * 40),chara[0].chip[1],TRUE);
DrawString(40,340,"防具防御力:",color[0]);
DrawString(40,370,"説明:",color[0]);
DrawString(240,340,e_point,color[0]);
for(i = 0;i < item[box[1][menu_cursor - item_count[0]]].text_count;i++){//テキストカウント分描画
DrawString(160,370 +(i * 30),item[box[1][menu_cursor - item_count[0]]].text[i],color[0]);//テキスト描画
}
}
else{//戻るの時
DrawGraph(540,270,chara[0].chip[1],TRUE);
DrawString(40,340,"トップメニューに戻る",color[0]);
}
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = item_count[0] + item_count[1];//武器・防具の合計
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == item_count[0] + item_count[1]){//武器防具の合計が最大値なら最小値へ
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == item_count[0] + item_count[1] && key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 3;//初期化(カーソルがステータスの上へ)
menu = 0;//メインメニューへ
}
else if(key[KEY_INPUT_RETURN] == 1){
if(menu_cursor < item_count[0]){
//選んでいるのが武器の場合
s_equip[0] = box[0][menu_cursor];
}
else if(menu_cursor < item_count[0] + item_count[1]){
//選んでいるのが防具の場合
s_equip[1] = box[1][menu_cursor - item_count[0]];
}
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
}
}
void menu_save(void){//セーブ
static int a[3][5];//ステータスを画面で描画するために入れておく配列
char b[5][20];//ステータス描画用
FILE *fp;
fp = fopen("save_0.txt","r");//セーブロード画面用要素テキストファイルオープン
for(i = 0;i < 3;i++){
fscanf(fp,"%d %d %d %d %d",&a[i][0],&a[i][1],&a[i][2],&a[i][3],&a[i][4]);//セーブデータのステータス読み込み
}
fclose(fp);
LoadGraphScreen(0,0,"背景/ロード.jpg",FALSE);
for(i = 0;i < 3;i++){//セーブ枠3つ描画
DrawGraph(0,-20 +(160 * i),window[1],TRUE);
if(a[i][0] <= 0){//セーブデータステータスHPが格納されていない(つまり0)なら
DrawString(200,60 +(160 * i),"データがありません。",color[2]);
}
else{
DrawGraph(50,30 + (160 * i),chara[0].face[0],TRUE);//主人公の顔画像描画
sprintf(b[0],"%d",a[i][0]);//HP変換
sprintf(b[1],"%d",a[i][1]);//TP変換
sprintf(b[2],"%d",a[i][2]);//ATK変換
sprintf(b[3],"%d",a[i][3]);//DEF変換
sprintf(b[4],"%d",a[i][4]);//SPD変換
DrawString(200,20 +(160 * i),"最大HP:",color[2]);//HP描画
DrawString(310,20 +(160 * i),b[0],color[2]);//HP描画
DrawString(400,20 +(160 * i),"最大TP:",color[2]);//TP描画
DrawString(510,20 +(160 * i),b[1],color[2]);//TP描画
DrawString(200,60 +(160 * i),"攻撃力:",color[2]);//ATK描画
DrawString(310,60 +(160 * i),b[2],color[2]);//ATK描画
DrawString(400,60 +(160 * i),"防御力:",color[2]);//DEF描画
DrawString(510,60 +(160 * i),b[3],color[2]);//DEF描画
DrawString(200,100 +(160 * i),"素早さ:",color[2]);//SPD描画
DrawString(310,100 +(160 * i),b[4],color[2]);//SPD描画
}
}
SetFontSize(16);
DrawString(440,460,"メニューに戻る",color[2]);
SetFontSize(30);
if(menu_cursor == 3){
DrawGraph(410,460,chara[0].chip[1],TRUE);
}
else{
DrawGraph(0,60 +(160 * menu_cursor),chara[0].chip[1],TRUE);
}
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 3;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 3){
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == 3 && key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 4;//初期化(カーソルがセーブの上へ)
menu = 0;//メインメニューへ
}
else if(key[KEY_INPUT_RETURN] == 1){ //決定
save_file(menu_cursor);
fp = fopen("save_0.txt","w");
a[menu_cursor][0] = status[0].hp;//主人公のMAXHP
a[menu_cursor][1] = status[0].tp;//主人公のMAXTP
a[menu_cursor][2] = status[0].atk;//主人公のATK
a[menu_cursor][3] = status[0].def;//主人公のDEF
a[menu_cursor][4] = status[0].spd;//主人公のSPD
for(i = 0;i < 3;i++){
fprintf(fp,"%d %d %d %d %d \n",a[i][0],a[i][1],a[i][2],a[i][3],a[i][4]);
}
fclose(fp);
LoadGraphScreen(0,0,"背景/セーブロード.jpg",FALSE);
DrawString(160,240,"セーブしました",color[2]);
WaitTimer(1000);
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
}
}
void menu_title(void){//タイトル
LoadGraphScreen(0,0,"背景/ロード.jpg",FALSE);
DrawGraph(0,0,window[0],TRUE);//テキストウィンドウ
DrawString(40,350,"本当にタイトルに戻りますか?",color[0]);
DrawString(490,390,"はい",color[0]);
DrawString(490,430,"いいえ",color[0]);
DrawGraph(450,390 + (menu_cursor * 40),chara[0].chip[1],TRUE);
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 1;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 1){
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == 1 && key[KEY_INPUT_RETURN] == 1){//いいえの場合
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 5;//初期化(カーソルがステータスの上へ)
menu = 0;//メインメニューへ
}
else if(key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
now_mode = 6;//トップ画面へ
SetFontSize(24);//文字サイズを戻す
}
}
void menu_sta_draw(void){//sta描画関数
char st[2][11][20];//ステータス数値描画用
char wari[7][20];//ボーナス割り振り描画用
//ボーナス割り振り後の文字のために2列
DrawGraph(20,20,chara[0].face[0],FALSE);//主人公の顔
DrawString(140,20,chara[0].name,color[0]);//名前描画
DrawString(520,0,"BP振り",color[0]);
DrawString(540,40,"割振る",color[0]);//割振る描画
DrawString(540,80,"戻る",color[0]);//戻る描画
//カーソル画像描画
if(menu_cursor > 5){
DrawGraph(500,40 + ((menu_cursor - 6)* 40),chara[0].chip[1],TRUE);
}
else if(menu_cursor == 5){
DrawGraph(540,360,chara[0].chip[1],TRUE);
}
else{
DrawGraph(540,120 + (menu_cursor * 40),chara[0].chip[1],TRUE);
}
//int型からchar型へ変換
sprintf(st[0][0],"%d",status[0].hp);
sprintf(st[0][1],"%d",status[0].tp);
sprintf(st[0][2],"%d",status[0].atk);
sprintf(st[0][3],"%d",status[0].def);
sprintf(st[0][4],"%d",status[0].spd);
sprintf(st[0][5],"%d",chara_skill[0].flag);
//hpとtpのみ現在数値も変換
sprintf(st[0][6],"%d",battle[0].hp);
sprintf(st[0][7],"%d",battle[0].tp);
//bonusも変換
sprintf(st[0][8],"%d",bonus);
//特技ポイント
sprintf(st[0][9],"%d",skill_pt);
sprintf(st[0][10],"%d",2 + (chara_skill[0].flag * chara_skill[0].flag));//next(2 + レベルの2乗)
//int型からchar型へ変換(bonus後)
sprintf(st[1][0],"%d",status[0].hp + ( 10 * bonus_dumy[0]));
sprintf(st[1][1],"%d",status[0].tp + ( 5 * bonus_dumy[1]));
sprintf(st[1][2],"%d",status[0].atk + bonus_dumy[2]);
sprintf(st[1][3],"%d",status[0].def + bonus_dumy[3]);
sprintf(st[1][4],"%d",status[0].spd + bonus_dumy[4]);
sprintf(st[1][5],"%d",chara_skill[0].flag + bonus_dumy[5] / (2 + (chara_skill[0].flag * chara_skill[0].flag) - skill_pt ));
//hpとtpのみ現在数値も変換
sprintf(st[1][6],"%d",battle[0].hp + ( 10 * bonus_dumy[0]));
sprintf(st[1][7],"%d",status[0].tp + ( 5 * bonus_dumy[1]));
//bonusも変換
sprintf(st[1][8],"%d",bonus - (bonus_dumy[0] + bonus_dumy[1] + bonus_dumy[2] + bonus_dumy[3] + bonus_dumy[4] + bonus_dumy[5]));
//特技ポイント
sprintf(st[1][9],"%d",skill_pt + bonus_dumy[5]);
sprintf(st[1][10],"%d",2 + (chara_skill[0].flag * chara_skill[0].flag));//next(2 + レベルの2乗)
//文字を描画
DrawString(120,120,"HP",color[0]);
DrawString(120,160,"TP",color[0]);
DrawString(120,200,"攻撃力",color[0]);
DrawString(120,240,"防御力",color[0]);
DrawString(120,280,"素早さ",color[0]);
DrawString(120,320,"特技Lv.",color[0]);
DrawString(120,360,"特技pt.",color[0]);
DrawString(120,400,"BONUSpt.",color[0]);
SetFontSize(12);
DrawString(20,450,"←キー:BP振り →キー:BP戻し Bキーor戻るでENTER:前画面へ 割振るでENTER:割り振り確定",color[0]);
SetFontSize(30);
//実際の数値描画
DrawString(310,120,st[0][0],color[0]);//hp
DrawString(310,160,st[0][1],color[0]);//tp
DrawString(240,200,st[0][2],color[0]);//atk
DrawString(240,240,st[0][3],color[0]);//def
DrawString(240,280,st[0][4],color[0]);//spd
DrawString(240,320,st[0][5],color[0]);//特技レベル
DrawString(240,120,st[0][6],color[0]);//hp2
DrawString(240,160,st[0][7],color[0]);//tp2
DrawString(295,120,"/",color[0]);
DrawString(295,160,"/",color[0]);
DrawString(240,400,st[0][8],color[0]);//bonus
if(chara_skill[0].flag >= 7){
DrawString(240,360,"MAX",color[0]);//skill_pt
DrawString(310,360,"MAX",color[0]);//skill_pt
}
else{
DrawString(240,360,st[0][9],color[0]);//skill_pt
DrawString(310,360,st[0][10],color[0]);//skill_pt
}
DrawString(295,360,"/",color[0]);
//カーソル
DrawString(375,120,"→",color[2]);
DrawString(375,160,"→",color[2]);
DrawString(375,200,"→",color[2]);
DrawString(375,240,"→",color[2]);
DrawString(375,280,"→",color[2]);
DrawString(375,320,"→",color[2]);
DrawString(375,360,"→",color[2]);
DrawString(375,400,"→",color[2]);
//ステータス上昇後
DrawString(480,120,st[1][0],color[2]);//hp
DrawString(480,160,st[1][1],color[2]);//tp
DrawString(410,200,st[1][2],color[2]);//atk
DrawString(410,240,st[1][3],color[2]);//def
DrawString(410,280,st[1][4],color[2]);//spd
DrawString(410,320,st[1][5],color[2]);//特技レベル
DrawString(410,120,st[1][6],color[2]);//hp2
DrawString(410,160,st[1][7],color[2]);//tp2
DrawString(470,120,"/",color[2]);
DrawString(470,160,"/",color[2]);
DrawString(410,400,st[1][8],color[2]);//bonus
if(chara_skill[0].flag >= 7){
DrawString(410,360,"MAX",color[2]);//skill_pt
DrawString(480,360,"MAX",color[2]);//skill_pt
}
else{
DrawString(410,360,st[1][9],color[2]);//skill_pt
DrawString(480,360,st[1][10],color[2]);//skill_pt
}
DrawString(470,360,"/",color[2]);
//ボーナス割り振り変換
sprintf(wari[0],"%d",bonus_dumy[0]);
sprintf(wari[1],"%d",bonus_dumy[1]);
sprintf(wari[2],"%d",bonus_dumy[2]);
sprintf(wari[3],"%d",bonus_dumy[3]);
sprintf(wari[4],"%d",bonus_dumy[4]);
sprintf(wari[5],"%d",bonus_dumy[5]);
//ボーナス割り振り
DrawString(580,120,wari[0],color[0]);//hp
DrawString(580,160,wari[1],color[0]);//tp
DrawString(580,200,wari[2],color[0]);//atk
DrawString(580,240,wari[3],color[0]);//def
DrawString(580,280,wari[4],color[0]);//spd
DrawString(580,360,wari[5],color[0]);//特技pt
}
void save_file(int a){
FILE *fp;
char filename[3][255] = {"save_1.txt","save_2.txt","save_3.txt"};
fp = fopen(filename[a],"w");
fprintf(fp,"%d %d %d %d %d %d %d %d %d \n",now_map,s_pos_x,s_pos_y,s_vector,vector_check,now_bgm,en_count,s_equip[0],s_equip[1]);
for(i=0;i < 15;i++){//バッグの中身
fprintf(fp,"%d \n",bag[i]);
}
for(i=0;i < 32;i++){//イベントフラグ
fprintf(fp,"%d \n",chara_eve[i].flag);
}
//主人公ステータス
fprintf(fp,"%d %d %d %d %d %d %d %d %d %d \n",status[0].hp,status[0].tp,battle[0].hp,battle[0].tp,
status[0].atk,status[0].def,status[0].spd,chara_skill[0].flag,bonus,skill_pt);
fclose(fp);
}
void load_menu(void){
SetFontSize(30);
int a[3][5];//ステータスを画面で描画するために入れておく配列
char b[5][5];//ステータス描画用
FILE *fp;
fp = fopen("save_0.txt","r");//セーブロード画面用要素テキストファイルオープン
for(i = 0;i < 3;i++){
fscanf(fp,"%d %d %d %d %d",&a[i][0],&a[i][1],&a[i][2],&a[i][3],&a[i][4]);//セーブデータのステータス読み込み
}
fclose(fp);
LoadGraphScreen(0,0,"背景/ロード.jpg",FALSE);
for(i = 0;i < 3;i++){//セーブ枠3つ描画
DrawGraph(0,-20 +(160 * i),window[1],TRUE);
if(a[i][0] <= 0){//セーブデータステータスHPが格納されていない(つまり0)なら
DrawString(200,60 +(160 * i),"データがありません。",color[2]);
}
else{
DrawGraph(50,30 + (160 * i),chara[0].face[0],TRUE);//主人公の顔画像描画
sprintf(b[0],"%d",a[i][0]);//HP変換
sprintf(b[1],"%d",a[i][1]);//TP変換
sprintf(b[2],"%d",a[i][2]);//ATK変換
sprintf(b[3],"%d",a[i][3]);//DEF変換
sprintf(b[4],"%d",a[i][4]);//SPD変換
DrawString(200,20 +(160 * i),"最大HP:",color[2]);//HP描画
DrawString(310,20 +(160 * i),b[0],color[2]);//HP描画
DrawString(400,20 +(160 * i),"最大TP:",color[2]);//TP描画
DrawString(510,20 +(160 * i),b[1],color[2]);//TP描画
DrawString(200,60 +(160 * i),"攻撃力:",color[2]);//ATK描画
DrawString(310,60 +(160 * i),b[2],color[2]);//ATK描画
DrawString(400,60 +(160 * i),"防御力:",color[2]);//DEF描画
DrawString(510,60 +(160 * i),b[3],color[2]);//DEF描画
DrawString(200,100 +(160 * i),"素早さ:",color[2]);//SPD描画
DrawString(310,100 +(160 * i),b[4],color[2]);//SPD描画
}
}
SetFontSize(16);
DrawString(440,460,"トップ画面に戻る",color[2]);
SetFontSize(30);
if(menu_cursor == 3){
DrawGraph(410,460,chara[0].chip[1],TRUE);
}
else{
DrawGraph(0,60 +(160 * menu_cursor),chara[0].chip[1],TRUE);
}
if(key[KEY_INPUT_UP] == 1){
if(menu_cursor == 0){//現在最小値なら最大値へ
menu_cursor = 3;
}
else{
menu_cursor -= 1;
}
while(CheckHitKey(KEY_INPUT_UP) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_DOWN] == 1){
if(menu_cursor == 3){
menu_cursor = 0;
}
else{
menu_cursor += 1;
}
while(CheckHitKey(KEY_INPUT_DOWN) ==1);//連打抑制
PlaySoundMem(se[0],DX_PLAYTYPE_BACK);//移動音
}
else if(key[KEY_INPUT_B] == 1 || menu_cursor == 3 && key[KEY_INPUT_RETURN] == 1){
while(CheckHitKey(KEY_INPUT_B) ==1);//連打抑制
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
menu_cursor = 1;//初期化(カーソルがセーブの上へ)
SetFontSize(24);//初期化
now_mode = 6;//トップ画面へ
}
else if(key[KEY_INPUT_RETURN] == 1 && a[menu_cursor][0] > 0){ //データがない状態じゃない、つまりMAXHPが1以上あるデータなら
load_file(menu_cursor);
LoadGraphScreen(0,0,"背景/セーブロード.jpg",FALSE);
DrawString(160,240,"ロードしました",color[2]);
WaitTimer(1000);
SetFontSize(24);//初期化
now_mode = 0;//マップへ
menu_cursor = 0;
while(CheckHitKey(KEY_INPUT_RETURN) ==1);//連打抑制
PlaySoundMem(se[1],DX_PLAYTYPE_BACK);//決定音
}
}
void load_file(int a){
FILE *fp;
char filename[3][255] = {"save_1.txt","save_2.txt","save_3.txt"};
fp = fopen(filename[a],"r");
fscanf(fp,"%d %d %d %d %d %d %d %d %d",&now_map,&s_pos_x,&s_pos_y,&s_vector,&vector_check,&now_bgm,&en_count,&s_equip[0],&s_equip[1]);
for(i=0;i < 15;i++){//バッグの中身
fscanf(fp,"%d",&bag[i]);
}
for(i=0;i < 32;i++){//イベントフラグ
fscanf(fp,"%d",&chara_eve[i].flag);
}
//主人公ステータス
fscanf(fp,"%d %d %d %d %d %d %d %d %d %d",&status[0].hp,&status[0].tp,&battle[0].hp,&battle[0].tp,
&status[0].atk,&status[0].def,&status[0].spd,&chara_skill[0].flag,&bonus,&skill_pt);
fclose(fp);
}[/code]