プログラムはこちらです。
#include "DxLib.h"
int MouseInput;
int menu=0,playmusic=1,Key[256],White;
int back1/*menu*/,back2/*play1*/,mato1;
int Sound1/*menu*/,Sound2/*play1*/,Sound3;
/***********色の定義*********/
int Movemato( int *count,int *move,int *x, int *y, int *x1, int *y1,int *x2, int *y2){
if(count%50 == 0 || count == 1 ){
PlaySoundMem( Sound3, DX_PLAYTYPE_BACK ); // 効果音を再生する
count++;
}
if( count == 1 ){
x1=GetRand(500);
y1=GetRand(340);
}
if(move==0){
move=1;
}else{
count=0;
}
if(move == 1){
x2=x1-x;
y2=y1-y;
if(x2 == 0 && y2 == 0){// 座標が一致したら停止
move=0;
}
else{
// 座標がずれていたら近い方へ10ピクセル移動
if (x2) x2 < 0 ? x-=10 : x+=10; // X座標
if (y2) y2 < 0 ? y-=10 : y+=10; // Y座標
}
}
return 0;
}
/*******************************************************
ステージ1
*******************************************************/
void Start1(void){
MouseInput = GetMouseInput(); //マウスの入力状況を取得
static int x=250,y=130,x1=0,y1=0,x2=0,y2=0;
static int count=0,move=0;
White = GetColor( 255 , 255 , 255 );
/*******************************************
的をクリックしたら、点を加算、的を移動させる
*******************************************/
if( ( GetMouseInput() & MOUSE_INPUT_LEFT ) != 0){
move=1;
Movemato( &count, &move, &x, &y, &x1, &y1, &x2, &y2);
}
/************
BGM 再生処理
************/
if(playmusic==0){//playmusicが0ならば音楽を再生(playmusicを2で初期化)
StopSoundMem( Sound1 ) ;
playmusic=2;
}
if(playmusic==2)
PlaySoundMem( Sound2 , DX_PLAYTYPE_LOOP );//バックグラウンド再生
DrawGraph( 0 , 0 , back1 , FALSE ) ;
DrawGraph( x , y , mato1 , TRUE ) ;
playmusic=3;
DrawFormatString( 100, 100, White , "count=%d" , count );//文字列表示
}
int GetHitKeyStateAll_2(int GetHitKeyStateAll_InputKey[]){
char GetHitKeyStateAll_Key[256];
GetHitKeyStateAll( GetHitKeyStateAll_Key );
for(int i=0;i<256;i++){
if(GetHitKeyStateAll_Key[i]==1) GetHitKeyStateAll_InputKey[i]++;
else GetHitKeyStateAll_InputKey[i]=0;
}
return 0;
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
ChangeWindowMode(TRUE);//ウィンドウモード
if(DxLib_Init() == -1 || SetDrawScreen( DX_SCREEN_BACK )!=0) return -1;//初期化と裏画面化
SetMouseDispFlag( TRUE ) ;
/*******色の定義*******************/
White = GetColor( 255 , 255 , 255 );
/*******画像のメモリ読み込み*******/
back1 = LoadGraph( "image/back(play).png" ) ;
back2 = LoadGraph( "image/back(menu).png" ) ;
mato1 = LoadGraph( "image/mato(play1).png") ;
/*******音声のメモリ読み込み*******/
Sound1 = LoadSoundMem( "Sound/backmusic/menu(music).wav" );
Sound2 = LoadSoundMem( "Sound/backmusic/play(music).wav" );
Sound3 = LoadSoundMem( "Sound/se/click1.wav" );
while(ProcessMessage()==0 && ClearDrawScreen()==0 && GetHitKeyStateAll_2(Key)==0 && Key[KEY_INPUT_ESCAPE]==0){
//↑メッセージ処理 ↑画面をクリア ↑入力状態を保存 ↑ESCが押されていない
if(menu==0){ //(menuが0の時)メニュー画面(トップ)
if(playmusic == 1){
PlaySoundMem( Sound1 , DX_PLAYTYPE_LOOP );//バックグラウンド再生
}
DrawGraph( 0 , 0 , back2 , FALSE ) ;
DrawString(100,100,"スペースキーでゲームスタート\n",White);
playmusic=0;
}
if(Key[KEY_INPUT_SPACE]==1 || menu==1){ //スペースキーが押された時、またはmenuが1の時(
Start1();
menu=1;
}
ScreenFlip();
}
DxLib_End();
return 0;
}
改変前のはこちらです。
#include "DxLib.h"
int MouseInput;
int menu=0,playmusic=1,Key[256],White;
int back1/*menu*/,back2/*play1*/,mato1;
int Sound1/*menu*/,Sound2/*play1*/,Sound3;
/***********色の定義*********/
/*******************************************************
ステージ1
*******************************************************/
void Start1(void){
MouseInput = GetMouseInput(); //マウスの入力状況を取得
static int x=250,y=130,x1=0,y1=0,x2=0,y2=0;
static int count=0,move=0;
White = GetColor( 255 , 255 , 255 );
/*******************************************
的をクリックしたら、点を加算、的を移動させる
*******************************************/
if( ( GetMouseInput() & MOUSE_INPUT_LEFT ) != 0){
if(count%50==0 || count==1 ){
PlaySoundMem( Sound3, DX_PLAYTYPE_BACK ); // 効果音を再生する
count++;
}
if(count%50==0 || count==1 ){
x1=GetRand(500);
y1=GetRand(340);
}
if(move==0){
move=1;
}
}else{
count=0;
}
if(move==1){
x2=x1-x;
y2=y1-y;
if(x2==0&&y2==0){// 座標が一致したら停止
move=0;
}
else{
// 座標がずれていたら近い方へ10ピクセル移動
if (x2) x2 < 0 ? x-=10 : x+=10; // X座標
if (y2) y2 < 0 ? y-=10 : y+=10; // Y座標
}
}
/************
BGM 再生処理
************/
if(playmusic==0){//playmusicが0ならば音楽を再生(playmusicを2で初期化)
StopSoundMem( Sound1 ) ;
playmusic=2;
}
if(playmusic==2)
PlaySoundMem( Sound2 , DX_PLAYTYPE_LOOP );//バックグラウンド再生
DrawGraph( 0 , 0 , back1 , FALSE ) ;
DrawGraph( x , y , mato1 , TRUE ) ;
playmusic=3;
DrawFormatString( 100, 100, White , "count=%d" , count );//文字列表示
}
int GetHitKeyStateAll_2(int GetHitKeyStateAll_InputKey[]){
char GetHitKeyStateAll_Key[256];
GetHitKeyStateAll( GetHitKeyStateAll_Key );
for(int i=0;i<256;i++){
if(GetHitKeyStateAll_Key[i]==1) GetHitKeyStateAll_InputKey[i]++;
else GetHitKeyStateAll_InputKey[i]=0;
}
return 0;
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
ChangeWindowMode(TRUE);//ウィンドウモード
if(DxLib_Init() == -1 || SetDrawScreen( DX_SCREEN_BACK )!=0) return -1;//初期化と裏画面化
SetMouseDispFlag( TRUE ) ;
/*******色の定義*******************/
White = GetColor( 255 , 255 , 255 );
/*******画像のメモリ読み込み*******/
back1 = LoadGraph( "image/back(play).png" ) ;
back2 = LoadGraph( "image/back(menu).png" ) ;
mato1 = LoadGraph( "image/mato(play1).png") ;
/*******音声のメモリ読み込み*******/
Sound1 = LoadSoundMem( "Sound/backmusic/menu(music).wav" );
Sound2 = LoadSoundMem( "Sound/backmusic/play(music).wav" );
Sound3 = LoadSoundMem( "Sound/se/click1.wav" );
while(ProcessMessage()==0 && ClearDrawScreen()==0 && GetHitKeyStateAll_2(Key)==0 && Key[KEY_INPUT_ESCAPE]==0){
//↑メッセージ処理 ↑画面をクリア ↑入力状態を保存 ↑ESCが押されていない
if(menu==0){ //(menuが0の時)メニュー画面(トップ)
if(playmusic == 1){
PlaySoundMem( Sound1 , DX_PLAYTYPE_LOOP );//バックグラウンド再生
}
DrawGraph( 0 , 0 , back2 , FALSE ) ;
DrawString(100,100,"スペースキーでゲームスタート\n",White);
playmusic=0;
}
if(Key[KEY_INPUT_SPACE]==1 || menu==1){ //スペースキーが押された時、またはmenuが1の時(
Start1();
menu=1;
}
ScreenFlip();
}
DxLib_End();
return 0;
}
エラーは以下のとおりでした
1>------ ビルド開始: プロジェクト: shootstg, 構成: Debug Win32 ------
1>コンパイルしています...
1>shootstg.cpp
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(13) : error C2296: '%' : 無効です。左オペランドには型 'int *' が指定されています。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(13) : error C2446: '==' : 'int' 型から 'int *' 型への変換ができません。
1> 整数型からポインタ型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(13) : error C2040: '==' : 'int *' は 'int' と間接操作のレベルが異なります。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(18) : error C2446: '==' : 'int' 型から 'int *' 型への変換ができません。
1> 整数型からポインタ型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(18) : error C2040: '==' : 'int *' は 'int' と間接操作のレベルが異なります。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(19) : error C2440: '=' : 'int' から 'int *' に変換できません。
1> 整数型からポインタ型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(20) : error C2440: '=' : 'int' から 'int *' に変換できません。
1> 整数型からポインタ型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(24) : error C2440: '=' : 'int' から 'int *' に変換できません。
1> 整数型からポインタ型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(29) : error C2446: '==' : 'int' 型から 'int *' 型への変換ができません。
1> 整数型からポインタ型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(29) : error C2040: '==' : 'int *' は 'int' と間接操作のレベルが異なります。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(30) : error C2440: '=' : 'int' から 'int *' に変換できません。
1> 整数型からポインタ型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
1>k:\c\dxライブラリ\試作ゲーム\shootstg\shootstg\shootstg.cpp(31) : error C2440: '=' : 'int' から 'int *' に変換できません。
1> 整数型からポインタ型への変換には reinterpret_cast、C スタイル キャストまたは関数スタイル キャストが必要です。
1>ビルドログは "file://k:\C\DXライブラリ\試作ゲーム\shootstg\shootstg\Debug\BuildLog.htm" に保存されました。
1>shootstg - エラー 12、警告 0
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========
>>'%' : 無効です
intで引数を渡す場合、その値に対して割るという演算は出来ないということでしょうか?
その他エラーは調べてみたものの、解説がどれも難しく理解出来ませんでした
ご教示いただけると幸いです。