DXライブラリを使ったゲーム制作で・・・
Posted: 2013年1月31日(木) 20:09
下に記載するプログラミングでRPGの戦闘画面を制作しています。
初期画面→ボタン入力で技の選択画面→技の選択→敵ダメージ値の減少→敵ダメージの値が0になれば次の戦闘へ
という工程が制作したいのですが、
技の選択→敵ダメージ値の減少の過程で思うようにいきません。
1、選択画面で下キーを押したら移動を開始してほしいのに、「下キー→Zキー」を押さないと項目が下に行かない。
2、ダメージ計算を行うにあたりダメージが20ずつしか減少しない。
この2つの原因はなんなのでしょうか?
_______________________________________
#include "DxLib.h"
int Key[256]; // キーが押されているフレーム数を格納する
// キーの入力状態を更新する
int gpUpdateKey(){
char tmpKey[256]; // 現在のキーの入力状態を格納する
GetHitKeyStateAll( tmpKey ); // 全てのキーの入力状態を得る
for( int i=0; i<256; i++ ){
if( tmpKey != 0 ){ // i番のキーコードに対応するキーが押されていたら
Key++; // 加算
} else { // 押されていなければ
Key = 0; // 0にする
}
}
return 0;
}
typedef struct{
int x,y;
char name[128];
} MenuElement_t ;
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE); //ウィンドウモード
SetWindowSizeChangeEnableFlag(TRUE);//ウィンドウモードサイズ変更
DxLib_Init(); //初期化
LoadGraphScreen(0,0,"op.jpg",TRUE);
int op,Count=0;
op=LoadSoundMem("op.mp3");
PlaySoundMem(op,DX_PLAYTYPE_BACK);
WaitKey();
MenuElement_t MenuElement[5]={
{ 450,250,"昇竜拳"},
{ 450,300,"竜巻旋風脚"},
{ 450,350,"ヨガファイア"},
{ 450,400,"ヨガフレイム"},
{ 450,450,"火中天津甘栗拳"},
};
int SelectNum = 0;
int x=0;
while(ScreenFlip() == 0&&
ProcessMessage()==0&&ClearDrawScreen()==0&&gpUpdateKey()==0){
if(Key[ KEY_INPUT_DOWN] == 1){
SelectNum = (SelectNum +1) %5;
for(int i=0; i<5; i++){
if( i== SelectNum){
MenuElement.x=430;
}else{
MenuElement.x=450;
}
}
if(Key[KEY_INPUT_Z] == 1){
if(SelectNum == 1){
DrawFormatString(250,175,GetColor(255,255,255),"10ダメージ");
}else if(SelectNum == 2){
DrawFormatString(250,175,GetColor(255,255,255),"20ダメージ");
}else if(SelectNum == 3){
DrawFormatString(250,175,GetColor(255,255,255),"30ダメージ");
}else if(SelectNum == 4){
DrawFormatString(250,175,GetColor(255,255,255),"40ダメージ");
}else if(SelectNum == 5){
DrawFormatString(250,175,GetColor(255,255,255),"50ダメージ");
}
}
if(vz<=0)
LoadGraphScreen(0,0,"op.jpg",TRUE);
WaitKey();
}
for(int i=0; i<5; i++){
DrawFormatString( MenuE
int damage;
int life;
int vx,vy,vz;
if(SelectNum == 0){
damage=10;
}else if(SelectNum == 1){
damage=20;
}else if(SelectNum == 2){
damage=30;
}else if(SelectNum == 3){
damage=40;
}else if(SelectNum == 4){
damage=50;
}
vx=100;
vy=damage;
life = vx - damage;
vz=life-damage;
DrawFormatString(0,0,GetColor(255,255,255),"%d",vz);
WaitKey(); lement.x,
MenuElement.y,GetColor(255,255,255),MenuElement.name);
}
}
return 0;
}
初期画面→ボタン入力で技の選択画面→技の選択→敵ダメージ値の減少→敵ダメージの値が0になれば次の戦闘へ
という工程が制作したいのですが、
技の選択→敵ダメージ値の減少の過程で思うようにいきません。
1、選択画面で下キーを押したら移動を開始してほしいのに、「下キー→Zキー」を押さないと項目が下に行かない。
2、ダメージ計算を行うにあたりダメージが20ずつしか減少しない。
この2つの原因はなんなのでしょうか?
_______________________________________
#include "DxLib.h"
int Key[256]; // キーが押されているフレーム数を格納する
// キーの入力状態を更新する
int gpUpdateKey(){
char tmpKey[256]; // 現在のキーの入力状態を格納する
GetHitKeyStateAll( tmpKey ); // 全てのキーの入力状態を得る
for( int i=0; i<256; i++ ){
if( tmpKey != 0 ){ // i番のキーコードに対応するキーが押されていたら
Key++; // 加算
} else { // 押されていなければ
Key = 0; // 0にする
}
}
return 0;
}
typedef struct{
int x,y;
char name[128];
} MenuElement_t ;
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE); //ウィンドウモード
SetWindowSizeChangeEnableFlag(TRUE);//ウィンドウモードサイズ変更
DxLib_Init(); //初期化
LoadGraphScreen(0,0,"op.jpg",TRUE);
int op,Count=0;
op=LoadSoundMem("op.mp3");
PlaySoundMem(op,DX_PLAYTYPE_BACK);
WaitKey();
MenuElement_t MenuElement[5]={
{ 450,250,"昇竜拳"},
{ 450,300,"竜巻旋風脚"},
{ 450,350,"ヨガファイア"},
{ 450,400,"ヨガフレイム"},
{ 450,450,"火中天津甘栗拳"},
};
int SelectNum = 0;
int x=0;
while(ScreenFlip() == 0&&
ProcessMessage()==0&&ClearDrawScreen()==0&&gpUpdateKey()==0){
if(Key[ KEY_INPUT_DOWN] == 1){
SelectNum = (SelectNum +1) %5;
for(int i=0; i<5; i++){
if( i== SelectNum){
MenuElement.x=430;
}else{
MenuElement.x=450;
}
}
if(Key[KEY_INPUT_Z] == 1){
if(SelectNum == 1){
DrawFormatString(250,175,GetColor(255,255,255),"10ダメージ");
}else if(SelectNum == 2){
DrawFormatString(250,175,GetColor(255,255,255),"20ダメージ");
}else if(SelectNum == 3){
DrawFormatString(250,175,GetColor(255,255,255),"30ダメージ");
}else if(SelectNum == 4){
DrawFormatString(250,175,GetColor(255,255,255),"40ダメージ");
}else if(SelectNum == 5){
DrawFormatString(250,175,GetColor(255,255,255),"50ダメージ");
}
}
if(vz<=0)
LoadGraphScreen(0,0,"op.jpg",TRUE);
WaitKey();
}
for(int i=0; i<5; i++){
DrawFormatString( MenuE
int damage;
int life;
int vx,vy,vz;
if(SelectNum == 0){
damage=10;
}else if(SelectNum == 1){
damage=20;
}else if(SelectNum == 2){
damage=30;
}else if(SelectNum == 3){
damage=40;
}else if(SelectNum == 4){
damage=50;
}
vx=100;
vy=damage;
life = vx - damage;
vz=life-damage;
DrawFormatString(0,0,GetColor(255,255,255),"%d",vz);
WaitKey(); lement.x,
MenuElement.y,GetColor(255,255,255),MenuElement.name);
}
}
return 0;
}