11_7_3_main | mydatabaseのブログ

mydatabaseのブログ

ブログの説明を入力します。

#include "gameframe.h"
#include "animdraw.h"
#include "battle.h"
#include <stdio.h>
#include <string>

// メニュー項目の表示に必要な構造体を用意する
typedef struct{
int x, y; // 座標格納用変数
char name[128]; // 項目名格納用変数
} MenuElement_t ;
MenuElement_t MenuElement[5]={
{ 80, 100, "ゲームスタート" }, // タグの中身の順番で格納される。xに80が、yに100が、nameに"ゲームスタート"が
{ 100, 150, "おまけ" },
{ 100, 200, "ヘルプ" },
{ 100, 250, "コンフィグ" },
{ 100, 300, "ゲーム終了" }
};
MenuElement_t BattleMenuElement[3]={
{ 80, 300, "たたかう"},
{ 100, 350, "スキル"},
{ 100, 400, "にげる"}
};
MenuElement_t BattleSelectElement[3]={
{ 80, 300, "敵その1"},
{ 100, 350, "敵その2"},
{ 100, 400, "敵その3"}
};
int SelectNum = 0;
typedef struct{
int NUM; // 座標格納用変数
char name[128]; // 項目名格納用変数
int AT;
int TP;
int type; //攻撃かどうか
int zentai; //全体攻撃かどうか
} SE_t;
typedef struct{
int x,y,img,muki,walking_flag,
dx,dy,yuka,fx,fy,stepnum,itvnum;
}ch_t;
ch_t ch;
typedef struct{
int NUM;
char myname[10];
int MAX_HP;/*最大HP*/
int HP;/*ヒットポイント*/
int MAX_TP;
int TP;
int AT;/*攻撃力*/
int DE;/*防御力*/
int AGI;/*素早さ*/
int ATtype;
int target;
SE_t myskill[20];
}st_t;
st_t st[20];
typedef struct{
int turn,flug;
int BattleNum;
int atnum;
int SelectNum;
int dmg,dmg2;
int Mnum,Enum,Cnum;
int Erestnum;
st_t agi[20];
}bt_t;
bt_t bt;

enum MESSAGESTATE{
MSG_APPEAR=1,MSG_MENU,MSG_SKILLMENU,MSG_SELECT,MSG_ATACK,MSG_ESCAPE,MSG_LOSE,MSG_WIN
};

int image[16];
int hantei[15][20] = {
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1 },
{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
};

int IsAbleToGo(int x,int y,int muki){//進めるかを判定する
if(muki==0)//上向きなら
if(hantei[y/8-1][x/8]==1)//進めるか判定
return 1;//エラー
if(muki==1)//左向きなら
if(hantei[y/8][x/8-1]==1)
return 1;
if(muki==2)//下向きなら
if(hantei[y/8+1][x/8]==1)
return 1;
if(muki==3)//右向きなら
if(hantei[y/8][x/8+1]==1)
return 1;
return 0;//正常
}
int IsAbleToBack(int x,int y,int muki){//進めるかを判定する
if(muki==0)//上向きなら
if(hantei[y/8+1][x/8]==1)//進めるか判定
return 1;//エラー
if(muki==1)//左向きなら
if(hantei[y/8][x/8+1]==1)
return 1;
if(muki==2)//下向きなら
if(hantei[y/8-1][x/8]==1)
return 1;
if(muki==3)//右向きなら
if(hantei[y/8][x/8-1]==1)
return 1;
return 0;//正常
}

class DanGame :public GameFrame{
AnimDraw wallanim;
AnimDraw enemyanim;
Battle battle;
MESSAGESTATE mstate;
public:
void loadFiles() throw(int);//画像読み込み
void initStage();
void initBattle();
void drawGameMainMenu();
void drawGameMain();
void drawGameBattle();
void drawEnemy();
void drawStates();
void drawEnemyStates();
void drawBattleMenu();
void drawSkillMenu();
void drawSelectMenu();
void DamageCount();
void initEnemy(int,int);
MESSAGESTATE setMsgState(MESSAGESTATE state);
void countWall( int, int, int, int, int);
};

void DanGame::loadFiles()throw(int){
SetTransColor(255,0,255);
int gh;
gh = LoadGraph("media\\P23 0列 2.png");
wallanim.setImage(0,gh);
gh = LoadGraph("media\\P24 0列 4.png");
wallanim.setImage(1,gh);
gh = LoadGraph("media\\P20 1列 2.png");
wallanim.setImage(2,gh);
gh = LoadGraph("media\\P22 1列 3.png");
wallanim.setImage(3,gh);
gh = LoadGraph("media\\P21 1列 4.png");
wallanim.setImage(4,gh);
gh = LoadGraph("media\\P14 2列 1.png");
wallanim.setImage(5,gh);
gh = LoadGraph("media\\P17 2列 2.png");
wallanim.setImage(6,gh);
gh = LoadGraph("media\\P19 2列 3.png");
wallanim.setImage(7,gh);
gh = LoadGraph("media\\P18 2列 4.png");
wallanim.setImage(8,gh);
gh = LoadGraph("media\\P15 2列 5.png");
wallanim.setImage(9,gh);
gh = LoadGraph("media\\P09 3列 1.png");
wallanim.setImage(10,gh);
gh = LoadGraph("media\\P12 3列 2.png");
wallanim.setImage(11,gh);
gh = LoadGraph("media\\P16 3列 3.png");
wallanim.setImage(12,gh);
gh = LoadGraph("media\\P13 3列 4.png");
wallanim.setImage(13,gh);
gh = LoadGraph("media\\P10 3列 5.png");
wallanim.setImage(14,gh);
gh = LoadGraph("media\\P04 4列 1.png");
wallanim.setImage(15,gh);
gh = LoadGraph("media\\P07 4列 2.png");
wallanim.setImage(16,gh);
gh = LoadGraph("media\\P11 4列 3.png");
wallanim.setImage(17,gh);
gh = LoadGraph("media\\P08 4列 4.png");
wallanim.setImage(18,gh);
gh = LoadGraph("media\\P05 4列 5.png");
wallanim.setImage(19,gh);
gh = LoadGraph("media\\P02 5列 2.png");
wallanim.setImage(20,gh);
gh = LoadGraph("media\\P06 5列 3.png");
wallanim.setImage(21,gh);
gh = LoadGraph("media\\P03 5列 4.png");
wallanim.setImage(22,gh);
gh = LoadGraph("media\\211.png");
enemyanim.setImage(0,gh);
}
void DanGame::initStage(){
ch.x = 80;
ch.y = 40;
ch.dx = 200;
ch.dy = 100;
ch.fx = 0;
ch.fy = 1;
ch.walking_flag=0;
ch.stepnum = 0;
ch.itvnum = 0;
ch.muki=3;
LoadDivGraph( "media\\a.bmp" , 16 , 4 , 4 , 8 , 8 , image ) ;//画像を分割してimage配列に保存
ch.yuka = LoadGraph("media\\P01 床.png");
bt.Mnum = 1;
st[0].NUM = 0;
strcpy(st[0].myname, "ファイター");
st[0].MAX_HP = 100;
st[0].HP = st[0].MAX_HP;
st[0].MAX_TP = 10;
st[0].TP = st[0].MAX_TP;
st[0].AT = 20;
st[0].DE = 20;
st[0].AGI = 20;
st[0].target = 0;
strcpy(st[0].myskill[0].name, "ファイヤ");
st[0].myskill[0].AT = 30;
st[0].myskill[0].NUM = 0;
st[0].myskill[0].TP = 3;
st[0].myskill[0].type = 0;
st[0].myskill[0].zentai = 1;
}
void DanGame::initBattle(){
setMsgState(MSG_APPEAR);
ch.itvnum = 0;
bt.BattleNum = 0;
bt.turn = 0;
bt.flug = 0;
bt.atnum = 0;
bt.Enum = GetRand(2)+1;
bt.Erestnum = bt.Enum;
bt.Cnum = bt.Mnum + bt.Enum;
initEnemy(bt.Mnum,bt.Enum);
for(int i=0; i < bt.Cnum; i++){
bt.agi[i] = st[i];
}
for(int i=0; i < bt.Cnum - 1 ;i++){
for(int j = 0; j < bt.Cnum; j++){
st_t c = bt.agi[j];
if( bt.agi[j].AGI < bt.agi[j + 1].AGI){
bt.agi[j] = bt.agi[j +1];
bt.agi[j + 1] = c;
}
}
}
}
void DanGame::initEnemy(int m, int e){
for(int i=0; i < e; i++){
st[m+i].NUM = m + i;
strcpy(st[m+i].myname, "ホネ");
st[m+i].MAX_HP = 40;
st[m+i].HP = st[m+i].MAX_HP;
st[m+i].MAX_TP = 10;
st[m+i].TP = st[m+i].MAX_TP;
st[m+i].AT = 10;
st[m+i].DE = 10;
st[m+i].AGI = 10;
}
}
void DanGame::drawGameMainMenu(){
if( g_MainData.key[ KEY_INPUT_DOWN ] == 1 ){ // 下キーが押された瞬間だけ処理
SelectNum = ( SelectNum + 1 ) % 5; // 現在の選択項目を一つ下にずらす(ループする)
}
if( g_MainData.key[ KEY_INPUT_UP ] == 1 ){ // 上キーが押された瞬間だけ処理
SelectNum = ( SelectNum + 4 ) % 5; // 現在の選択項目を一つ上にずらす(逆ループする)
}
if( g_MainData.key[ KEY_INPUT_DOWN ] == 1 || g_MainData.key[ KEY_INPUT_UP ] == 1 ){
for( int i=0; i<5; i++ ){ // メニュー項目数である5個ループ処理
if( i == SelectNum ){ // 今処理しているのが、選択番号と同じ要素なら
MenuElement[i].x = 80; // 座標を80にする
} else { // 今処理しているのが、選択番号以外なら
MenuElement[i].x = 100;// 座標を100にする
}
}
}
// 描画フェーズ
for( int i=0; i<5; i++ ){ // メニュー項目を描画
DrawFormatString( MenuElement[i].x, MenuElement[i].y, GetColor(255,255,255), MenuElement[i].name );
}
if( g_MainData.key[ KEY_INPUT_SPACE ] == 1){
if( SelectNum == 0){
GameFrame::setGameStateinit(GAME_MAIN);
}
}
}

void DanGame::drawGameMain(){
drawStates();
/*白い壁を描画*/
for(int i=0;i<15;i++){
for(int j=0;j<20;j++){
if(hantei[i][j]==1){
DrawBox(j*8,i*8+100,(j+1)*8,(i+1)*8+100,GetColor(255,255,255),TRUE);
}
}
}
if(ch.x%8==0 && ch.y%8==0){ //座標が8で割り切れたら入力可能
if ( g_MainData.key[ KEY_INPUT_UP ] == 1 ){ //上ボタンが押されたら
ch.walking_flag=1; //歩くフラグを立てる。
ch.stepnum++; //歩数を増やす
ch.itvnum++;
}
else if( g_MainData.key[ KEY_INPUT_LEFT ] == 1 ){ //左ボタンが押されたら
ch.muki++; //左に向く
if(ch.muki == 4)ch.muki = 0;
ch.walking_flag=0; //歩かないフラグを立てる
}
else if( g_MainData.key[ KEY_INPUT_DOWN ] == 1 ){ //下ボタンが押されたら
ch.walking_flag=-1; //下に歩くフラグを立てる
ch.stepnum++; //歩数を増やす
ch.itvnum++;
}
else if( g_MainData.key[ KEY_INPUT_RIGHT] == 1 ){ //右ボタンが押されたら
ch.muki--; //右向きフラグを立てる
if(ch.muki == -1) ch.muki = 3;
ch.walking_flag=0; //歩かないフラグを立てる
}
else //何のボタンも押されてなかったら
ch.walking_flag=0; //歩かないフラグを立てる

if(ch.walking_flag==1) //もし歩くなら
if(IsAbleToGo(ch.x,ch.y,ch.muki)==1)//行き先が歩けないなら
ch.walking_flag=0; //歩かないフラグを立てる。
if(ch.walking_flag==-1) //もし下に歩くなら
if(IsAbleToBack(ch.x,ch.y,ch.muki)==1)//行き先が歩けないなら
ch.walking_flag=0; //歩かないフラグを立てる。
}
if(ch.walking_flag==1){ //歩くフラグが立っていたら
if (ch.muki==0) //上向きならch.y座標を減らす
ch.y--;
else if(ch.muki==1) //左向きならch.x座標を減らす
ch.x--;
else if(ch.muki==2) //下向きならch.y座標を増やす
ch.y++;
else if(ch.muki==3) //右向きならch.x座標を増やす
ch.x++;
}
if(ch.walking_flag==-1){ //下に歩くフラグが立っていたら
if (ch.muki==0) //上向きならch.y座標を減らす
ch.y++;
else if(ch.muki==1) //左向きならch.x座標を減らす
ch.x++;
else if(ch.muki==2) //下向きならch.y座標を増やす
ch.y--;
else if(ch.muki==3) //右向きならch.x座標を増やす
ch.x--;
}
if((ch.walking_flag==1 || ch.walking_flag == -1) && ch.itvnum > 1 && ch.x%8==0 && ch.y%8==0){
int i = 15 - ch.itvnum;
if( i < 4 ) i = 4;
if(GetRand(i)==0)
GameFrame::setGameStateinit(GAME_BATTLE);
}
ch.img=image[ch.muki]; //画像をセット
DrawGraph( ch.x , ch.y+100 , ch.img , TRUE ) ;//画像を描画
DrawFormatString(500,20, GetColor(255,255,255), "歩数 %d",ch.stepnum );
DrawFormatString(500,50, GetColor(255,255,255), "間隔 %d",ch.itvnum );
DrawGraph( ch.dx, ch.dy, ch.yuka, TRUE);
int dx,dy;
if(ch.muki==0){dy=1;dx=0;}
else if(ch.muki==1){dy=0;dx=-1;} //hidari
else if(ch.muki==2){dy=-1;dx=0;} //sita
else if(ch.muki==3){dy=0;dx=1;}
//countWall( i, j, dx, dy, wall)i: 何列目かj:xからの変動数 dx,dy:向きの設定 wall:
//5列目表示
countWall( 5, -1, dx, dy, 1); //20
countWall( 5, 1, dx, dy, 1); //22
countWall( 5, 0, dx, dy, 1); //21
//4列目から2列目まで x-2, x+2, x-1, x+1, xの順に表示
for(int i = 4; i >= 2; i--){
countWall( i, -2, dx, dy, 2); //15, 10, 5
countWall( i, 2, dx, dy, 2); //19, 14, 9
countWall( i, -1, dx, dy, 2); //16, 11, 6
countWall( i, 1, dx, dy, 2); //18, 13, 8
countWall( i, 0, dx, dy, 2); //17, 12, 7
}
//1列目表示(5列目と大体同じ)
countWall( 1, -1, dx, dy, 3); //2
countWall( 1, 1, dx, dy, 3); //4
countWall( 1, 0, dx, dy, 3); //3
//0列目表示
countWall( 0, -1, dx, dy, 6);
countWall(0, 1, dx, dy, 5);
}

void DanGame::countWall(int i, int j, int dx, int dy, int wall) {
//i:列の数 j:xからの変動数 dx,dy:向きの設定 wall:行の数
if(hantei[ ch.y/8+(-1*i)*dy+j*dx][ch.x/8+j*dy+i*dx]==1)
wallanim.drawWall((i-1)*5+j+wall);
}

void DanGame::drawGameBattle(){
//敵の表示
drawEnemy();
//メニューの表示
switch (mstate){
case MSG_APPEAR:
DrawFormatString(200,300, GetColor(255,255,255), "モンスターがあらわれた!");
if( g_MainData.key[ KEY_INPUT_SPACE ] == 1)
setMsgState(MSG_MENU);
break;
case MSG_MENU:
drawBattleMenu();
if( g_MainData.key[ KEY_INPUT_SPACE ] == 1){
switch(bt.BattleNum){
case 0:
st[0].ATtype = 1;
if(bt.Erestnum == 1){
for(int i = 0; i < bt.Enum; i++){
if(st[bt.Mnum+i].HP > 0){
st[0].target = i;
}
}
DamageCount();
setMsgState(MSG_ATACK);
} else {
for(int i= bt.Enum -1; i >= 0; i--){
if(st[bt.Mnum+i].HP > 0)
bt.SelectNum = i;
}
setMsgState(MSG_SELECT);
}
break;
case 1:
setMsgState(MSG_SKILLMENU);
break;
case 2:
setMsgState(MSG_ESCAPE);
break;
}
}
switch(bt.BattleNum){
case 0:
DrawString(200,300,"相手に攻撃します", GetColor(255,255,255));
break;
case 1:
DrawString(200,300,"アイテムを使います", GetColor(255,255,255));
break;
case 2:
DrawString(200,300,"逃げます", GetColor(255,255,255));
break;
}
break;
case MSG_SKILLMENU:
drawSkillMenu();
if( g_MainData.key[ KEY_INPUT_SPACE ] == 1){
st[0].ATtype = 2;
if(st[0].TP < st[0].myskill[0].TP){
setMsgState(MSG_MENU);
} else {
if(bt.Erestnum == 1){
for(int i = 0; i < bt.Enum; i++){
if(st[bt.Mnum+i].HP > 0){
st[0].target = i;
}
}
DamageCount();
setMsgState(MSG_ATACK);
} else {
bt.SelectNum = 0;
setMsgState(MSG_SELECT);
}
}
}
break;
case MSG_SELECT:
drawSelectMenu();
if( g_MainData.key[ KEY_INPUT_SPACE ] == 1){
switch(bt.SelectNum){
case 0:
st[0].target = 0;
break;
case 1:
st[0].target = 1;
break;
case 2:
st[0].target = 2;
break;
}
DamageCount();
setMsgState(MSG_ATACK);
}
break;
case MSG_ATACK:
switch(st[bt.atnum].ATtype){
case 2:
DrawFormatString(200,300, GetColor(255,255,255), "%sの%s!相手に%dのダメージ",st[bt.atnum].myname,st[bt.atnum].myskill[0].name,bt.dmg );
break;
default:
DrawFormatString(200,300, GetColor(255,255,255), "%sの攻撃!相手に%dのダメージ",st[bt.atnum].myname,bt.dmg );
break;
}
if( g_MainData.key[ KEY_INPUT_SPACE ] == 1){
bt.atnum++;
if(bt.atnum >= bt.Cnum){
bt.atnum = 0;
if(bt.Erestnum == 0){
setMsgState(MSG_WIN);
} else {
setMsgState(MSG_MENU);
}
} else {
if(bt.Erestnum == 0){
setMsgState(MSG_WIN);
} else {
DamageCount();
}
}
}
break;
case MSG_ESCAPE:
DrawFormatString(200,300, GetColor(255,255,255), "%sは逃げ出した!",st[0].myname);
if( g_MainData.key[ KEY_INPUT_SPACE ] == 1)
GameFrame::setGameState(GAME_MAIN);
break;
case MSG_WIN:
DrawFormatString(200,300, GetColor(255,255,255), "モンスターを倒した!");
if( g_MainData.key[ KEY_INPUT_SPACE ] == 1)
GameFrame::setGameState(GAME_MAIN);
break;
case MSG_LOSE:
DrawFormatString(200,300, GetColor(255,255,255), "%sは倒れた!",st[0].myname );
break;
}
//ステータスの表示
drawStates();
drawEnemyStates();
//ターンの表示
if(bt.turn > 0){
DrawFormatString( 500 , 20 , GetColor(255,255,255), "ターン数 %d",bt.turn);
}
}

void DanGame::drawEnemy(){
for(int i=0; i < bt.Enum; i++){
if(st[bt.Mnum + i].HP > 0){
enemyanim.draw(0,600/(bt.Enum+1)*(i+1),200);
}
}
}
void DanGame::drawStates(){
int x1 = 30,y1 = 20,x2=x1+130,y2=y1+50;
DrawBox( x1, y1, x2, y2,GetColor(255,255,255), FALSE );
DrawFormatString( x1+10 , y1+10 , GetColor(255,255,255), "HP %d / %d",st[0].HP,st[0].MAX_HP);
DrawFormatString( x1+10 , y1+30 , GetColor(255,255,255), "TP %d / %d",st[0].TP,st[0].MAX_TP);
}
void DanGame::drawEnemyStates(){
int x1 = 200,y1 = 20,x2=x1+130,y2=y1+50;
if(st[bt.Mnum].HP > 0){
DrawBox( x1, y1, x2, y2,GetColor(255,255,255), FALSE );
DrawFormatString( x1+10 , y1+10 , GetColor(255,255,255), "HP %d / %d",st[bt.Mnum].HP,st[bt.Mnum].MAX_HP);
DrawFormatString( x1+10 , y1+30 , GetColor(255,255,255), "TP %d / %d",st[bt.Mnum].TP,st[bt.Mnum].MAX_TP);
}
if(bt.Enum >= 2 && st[bt.Mnum+1].HP > 0){
DrawBox( x1+150, y1, x2+150, y2,GetColor(255,255,255), FALSE );
DrawFormatString( x1+160 , y1+10 , GetColor(255,255,255), "HP %d / %d",st[bt.Mnum+1].HP,st[bt.Mnum+1].MAX_HP);
DrawFormatString( x1+160 , y1+30 , GetColor(255,255,255), "TP %d / %d",st[bt.Mnum+1].TP,st[bt.Mnum+1].MAX_TP);
}
if(bt.Enum >= 3 && st[bt.Mnum+2].HP > 0){
DrawBox( x1+300, y1, x2+300, y2,GetColor(255,255,255), FALSE );
DrawFormatString( x1+310 , y1+10 , GetColor(255,255,255), "HP %d / %d",st[bt.Mnum+2].HP,st[bt.Mnum+2].MAX_HP);
DrawFormatString( x1+310 , y1+30 , GetColor(255,255,255), "TP %d / %d",st[bt.Mnum+2].TP,st[bt.Mnum+2].MAX_TP);
}
}
void DanGame::drawBattleMenu(){
if( g_MainData.key[ KEY_INPUT_DOWN ] == 1 ){ // 下キーが押された瞬間だけ処理
bt.BattleNum = (bt.BattleNum + 1 ) % 3; // 現在の選択項目を一つ下にずらす(ループする)
}
if( g_MainData.key[ KEY_INPUT_UP ] == 1 ){ // 上キーが押された瞬間だけ処理
bt.BattleNum = ( bt.BattleNum + 2 ) % 3; // 現在の選択項目を一つ上にずらす(逆ループする)
}
for( int i=0; i<3; i++ ){ // メニュー項目数である3個ループ処理
if( i == bt.BattleNum ){ // 今処理しているのが、選択番号と同じ要素なら
BattleMenuElement[i].x = 80; // 座標を80にする
} else { // 今処理しているのが、選択番号以外なら
BattleMenuElement[i].x = 100;// 座標を100にする
}
DrawFormatString( BattleMenuElement[i].x, BattleMenuElement[i].y, GetColor(255,255,255), BattleMenuElement[i].name );
}
}
void DanGame::drawSkillMenu(){
DrawFormatString( 100, 300, GetColor(255,255,255), st[0].myskill[0].name );
if(st[0].TP < st[0].myskill[0].TP)
DrawFormatString( 100, 350, GetColor(255,255,255), "TPがたりません" );
}
void DanGame::drawSelectMenu(){
if( g_MainData.key[ KEY_INPUT_DOWN ] == 1 ){ // 下キーが押された瞬間だけ処理
bt.SelectNum = (bt.SelectNum + 1 ) % bt.Enum; // 現在の選択項目を一つ下にずらす(ループする)
if(st[bt.Mnum+bt.SelectNum].HP <= 0){
bt.SelectNum = ( bt.SelectNum + bt.Enum + 1) % bt.Enum;
}
}
if( g_MainData.key[ KEY_INPUT_UP ] == 1 ){ // 上キーが押された瞬間だけ処理
bt.SelectNum = ( bt.SelectNum + bt.Enum -1 ) % bt.Enum; // 現在の選択項目を一つ上にずらす(逆ループする)
if(st[bt.Mnum+bt.SelectNum].HP <= 0){
bt.SelectNum = ( bt.SelectNum + bt.Enum -1 ) % bt.Enum;
}
}
for( int i=0; i<bt.Enum; i++ ){ // メニュー項目数である3個ループ処理
if( i == bt.SelectNum ){ // 今処理しているのが、選択番号と同じ要素なら
BattleSelectElement[i].x = 80; // 座標を80にする
} else { // 今処理しているのが、選択番号以外なら
BattleSelectElement[i].x = 100;// 座標を100にする
}
if(st[bt.Mnum+i].HP > 0 ){
DrawFormatString( BattleSelectElement[i].x, BattleSelectElement[i].y, GetColor(255,255,255), BattleSelectElement[i].name );
}
}
}
void DanGame::DamageCount(){
if(st[bt.atnum].NUM == st[0].NUM){
switch(st[0].ATtype){
case 1:
bt.dmg =20;
if(st[bt.Mnum+st[0].target].HP <= bt.dmg){
bt.dmg = st[bt.Mnum+st[0].target].HP;
bt.Erestnum--;
}
st[bt.Mnum + st[0].target].HP = st[bt.Mnum + st[0].target].HP - bt.dmg;
break;
case 2:
bt.dmg = st[0].myskill[0].AT;
if(st[bt.Mnum+st[0].target].HP <= bt.dmg){
bt.dmg = st[bt.Mnum+st[0].target].HP;
bt.Erestnum--;
}
st[bt.Mnum + st[0].target].HP = st[bt.Mnum + st[0].target].HP - bt.dmg;
st[0].TP = st[0].TP - st[0].myskill[0].TP;
break;
}
} else if(st[bt.atnum].NUM == st[bt.Mnum].NUM && st[bt.Mnum].HP > 0){
bt.dmg = 10;
if(st[0].HP <= bt.dmg){
bt.dmg = st[0].HP;
}
st[0].HP = st[0].HP - bt.dmg;
} else if(st[bt.atnum].NUM == st[bt.Mnum+1].NUM && st[bt.Mnum+1].HP > 0){
bt.dmg = 10;
if(st[0].HP <= bt.dmg){
bt.dmg = st[0].HP;
}
st[0].HP = st[0].HP - bt.dmg;
} else if(st[bt.atnum].NUM == st[bt.Mnum+2].NUM && st[bt.Mnum+1].HP > 0){
bt.dmg = 10;
if(st[0].HP <= bt.dmg){
bt.dmg = st[0].HP;
}
st[0].HP = st[0].HP - bt.dmg;
}
}
MESSAGESTATE DanGame::setMsgState(MESSAGESTATE state){
if(mstate != state){
mstate = state;
}
return mstate;
}
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hp, LPSTR lpC, int nC){
DanGame *sg = new DanGame();
sg->doMainLoop(TRUE);
delete sg;
}