私は、C++をさわり今年で2年になるのですが、本格的なゲーム開発を一度もしたことが無く、ゲームをどのように作るのか全くわからない状態です。しかし今回、そろそろゲーム開発を真剣に考えてやってみようと、このサイトのサンプルやテキストを読んで自分なりにゲーム開発をしてみたのですが、まだゲームとは言える状態では無く、今後どのような機能が有れば、もっとゲームらしくなるのか、現在のコードをどのようにいじれば、もっとゲーム開発に有っているのか教えてほしく、書き込みしました。作りかけのソースコードしかないですが、一様動くので書き込みよろしくお願いします。画像の宣言が有るので32*32で「KIRAI.bmp」と適当に作って下さい。わかりにくい書き込みですが、優しくお願いします
#include "DxLib.h"
#include "math.h"
///////////////////////////////////////////////////////////////
//宣言
///////////////////////////////////////////////////////////////
#define Window_H 480 //MAP(高さ・Y)
#define Window_W 480 //MAP(広さ・X)
#define BOX 32 //BOXサイズ
#define CH_SPEED 1.0 //移動スピード(PLAY1)
#define SHOTSPEED 4 //移動スピード( 弾 )
#define SHOTMAX 50 //最大弾数
#define SHOT_RANGE 16//弾サイズ
#define SHOT_LONG 10 //弾間隔
#define TAMEMAX 5 //最大保持弾数
#define PI 3.1415926535897932384626433832795//π
///////////////////////////////////////////////////////////////
//構造体
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//PLAYER1(X,Y方向:muki:WALKING_FLAG:)
///////////////////////////////////////////////////////////////
typedef struct{
double x;
double y;
int muki;
int walking_flag;
int range;
}BODY_ch_t1;
BODY_ch_t1 ch;
///////////////////////////////////////////////////////////////
//PLAYER1・弾(X,Y方向:muki:FLAG:)
///////////////////////////////////////////////////////////////
typedef struct{
double x;
double y;
int muki;
int flag;
int counter;
int range;
} SHOT_t;
SHOT_t Shot[SHOTMAX];
///////////////////////////////////////////////////////////////
//PLAYER1・機雷尾(X,Y方向:FLAG:)
///////////////////////////////////////////////////////////////
typedef struct{
double x;
double y;
int flag;
int counter;
int range;
} tame_t;
tame_t tame;
////////////////////////////////////////////////////
//グローバル変数
////////////////////////////////////////////////////
char Key[256];//キー入力
int counter; //カウント
int image; //ハンドルを受け取るためのint型変数を宣言
int hantei[15][15]={
{0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,1,0,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,1,0,0,0,0,0,1},
};//MAP
////////////////////////////////////////////////////
//プロトタイプ宣言
////////////////////////////////////////////////////
void PlayerControl();//PLAY
void WindowMode(); //ウインドウモード切り替え
void Init(); //初期化
void Map(); //MAPデータ
////////////////////////////////////////////////////
//関数
////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//MAP・CANNOT
///////////////////////////////////////////////////////////////
int can_or_cannot(int x,int y){
if(hantei[y/BOX][x/BOX]==1)return 1;
return 0;
}
///////////////////////////////////////////////////////////////
//PLAYER1・表示
///////////////////////////////////////////////////////////////
void PlayerDraw(int x, int y){
DrawBox ( ch.x , ch.y , ch.x+BOX , ch.y+BOX , GetColor(0,255,255) , TRUE );
}
///////////////////////////////////////////////////////////////
//PLAYER1・行動
///////////////////////////////////////////////////////////////
void PlayerControl(){
int i;
if((int)ch.x%32==0 && (int)ch.y%32==0){
ch.walking_flag=1;
if ( Key[ KEY_INPUT_UP ] == 1 )ch.muki=0;
else if( Key[ KEY_INPUT_LEFT ] == 1 )ch.muki=1;
else if( Key[ KEY_INPUT_DOWN ] == 1 )ch.muki=2;
else if( Key[ KEY_INPUT_RIGHT] == 1 )ch.muki=3;
else ch.walking_flag=0;
for(i=0;i<=SHOTMAX;i++)if(Shot[i].flag==0)Shot[i].muki=3-ch.muki;
}
if(ch.walking_flag==1){
if(ch.muki==0)(ch.y< 0 )?ch.y= 0 :ch.y-=CH_SPEED;
if(ch.muki==1)(ch.x< 0 )?ch.x= 0 :ch.x-=CH_SPEED;
if(ch.muki==2)(ch.y>=Window_H-BOX)?ch.y=(Window_H-BOX):ch.y+=CH_SPEED;
if(ch.muki==3)(ch.x>=Window_W-BOX)?ch.x=(Window_W-BOX):ch.x+=CH_SPEED;
tame.flag=0;
}
}
///////////////////////////////////////////////////
//ウインドウモード切り替え
///////////////////////////////////////////////////
void WindowMode(){
if (Key[KEY_INPUT_F1]==1)ChangeWindowMode(TRUE);
else if(Key[KEY_INPUT_F2]==1)ChangeWindowMode(FALSE);
}
///////////////////////////////////////////////////
//初期化
///////////////////////////////////////////////////
void Init(){
ch.x=0;
ch.y=0;
ch.muki=0;
counter=0;
tame.counter=0;
tame.flag=0;
for(int i=0;i<SHOTMAX;i++){
Shot[i].flag=0;
}
image = LoadGraph( "KIRAI.bmp" ) ; //ハンドルを代入
}
///////////////////////////////////////////////////
//MAP・描画
///////////////////////////////////////////////////
void Map(){
int i,j;
DrawBox ( Window_W , 0 , 640 , Window_H , GetColor(255,255,255) , TRUE ) ;
for(i=0;i<15;i++){
for(j=0;j<15;j++)
if(hantei[j][i]==1)DrawGraph( i*32 , j*32 , image , TRUE );
}
for(i=0;i<=480;i+=BOX){
DrawLine(i,0,i,Window_H,GetColor(255,255,255));
DrawLine(0,i,Window_W,i,GetColor(255,255,255));
}
static int FpsTime[2]={0,},FpsTime_i=0;
static double Fps=0.0;
if(FpsTime_i== 0)FpsTime[0]=GetNowCount(); //1周目の時間取得
if(FpsTime_i==49){
FpsTime[1]=GetNowCount(); //50周目の時間取得
Fps = 1000.0f / ((FpsTime[1] - FpsTime[0]) / 50.0f);//測定した値からfpsを計算
FpsTime_i=0;
}
else FpsTime_i++; //現在何周目かカウント
if(Fps != 0)DrawFormatString(565,460,GetColor(0,255,255),"FPS %.1f",Fps);
DrawFormatString(565,420,GetColor(0,255,255),"%d",tame.counter);
}
////////////////////////////////////////////////////
//弾・行動
////////////////////////////////////////////////////
void ShotCalc(){
int j;
if(Key[KEY_INPUT_Z]==1&&counter%SHOT_LONG==0){
for(j=0;j<SHOTMAX;j++){
if(Shot[j].flag==0){
Shot[j].flag=1;
Shot[j].x=ch.x+(BOX/4);
Shot[j].y=ch.y+(BOX/4);
Shot[j].muki=3-ch.muki;//上
break;
}
}
}
for(j=0;j<SHOTMAX;j++){
if(Shot[j].flag==1){
Shot[j].x+= SHOTSPEED * cos(90*Shot[j].muki*PI/180);
Shot[j].y+= SHOTSPEED * sin(90*Shot[j].muki*PI/180);
if( Shot[j].x > 480 || Shot[j].x < 0-BOX || Shot[j].y > 480 || Shot[j].y < 0-BOX )Shot[j].flag=0;
}
}
}
//////////////////////////////////////////
//弾・描画
//////////////////////////////////////////
void ShotDisp(){
int j;
for(j=0;j<50;j++){
Shot[j].range=SHOT_RANGE;
if(Shot[j].flag==1)DrawBox ( Shot[j].x , Shot[j].y , Shot[j].x+Shot[j].range , Shot[j].y+Shot[j].range , GetColor(0,255,255) , TRUE );
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//待ち時間
////////////////////////////////////////////////////////////////////////////////////////////////
void wait_func(){
static int t=0;
int term = GetNowCount()-t;
if(16-term>0)Sleep(16-term);
t=GetNowCount();
}
/////////////////////////////////////////////////////
//機雷
/////////////////////////////////////////////////////
void Kirai(){
if( (int)can_or_cannot((int)ch.x,(int)ch.y)==0 && Key[KEY_INPUT_A] && (int)ch.x%32==0 && (int)ch.y%32==0 && tame.counter<TAMEMAX){
hantei[(int)ch.y/BOX][(int)ch.x/BOX]=1;
tame.counter++;
tame.flag=1;
}
if((int)can_or_cannot((int)ch.x,(int)ch.y)==1 && tame.flag==0 && (int)ch.x%32==0 && (int)ch.y%32==0 ){
hantei[(int)ch.y/BOX][(int)ch.x/BOX]=0;
if(tame.counter>0)tame.counter--;
}
}
/////////////////////////////////////////////////
//main
/////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ) return -1; //ウィンドウ化と初期化処理
SetDrawScreen(DX_SCREEN_BACK);
/////////////////////////////////////////////
//初期値
/////////////////////////////////////////////
Init();
/////////////////////////////////////////////
while(!ProcessMessage() && !ClearDrawScreen() && !GetHitKeyStateAll( Key ) && !Key[KEY_INPUT_ESCAPE]){
////////////////////////////////////////////////////////////////////////////////
//プログラム
////////////////////////////////////////////////////////////////////////////////
PlayerControl();
PlayerDraw((int)ch.x, (int)ch.y);
ShotCalc();
ShotDisp();
Kirai();
Map();
////////////////////////////////////////////////////////////////////////////////////////
counter++;
WindowMode();
ScreenFlip();
wait_func();
}
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}