#include"DxLib.h" #include #define WIDTH 640 #define HEIGHT 480 #define ENEMY 20 #define ITEM 30 #define BULLET 200 //自機のstruct struct S_player{ int x,y; //座標 int vx,vy; //座標方向の速度 int hp; //hit point int score; //得点 int size_x;//x軸方向の大きさ int size_y;//y軸方向の大きさ }; //敵のstruct struct S_enemy{ int x,y; int vx,vy; int hp; int t; //その敵が作られてからのフレーム数を格納するメンバ int size_x; int size_y; }; //弾のstruct struct S_bullet{ double x,y; double vx,vy; int hp; //hpが0なら画面上に存在していない、1なら存在している int atk; //弾の攻撃力 int size_x; int size_y; }; //アイテムのstruct struct S_item{ int x,y; int vx,vy; int hp; //hpが0なら画面上に存在していない、1なら存在している int size_x; int size_y; }; //背景のstruct struct S_background{ int x,y; int vy; int size_x; int size_y; }; //画像のstruct struct S_image{ int img_player; //自機の画像を格納 int img_enemy; //敵の画像 int img_bullet; //弾の画像 int img_item; //アイテム int img_gameover; //ゲームオーバー画面 int img_title; //タイトル画面 int img_background; //背景 }; enum e_flag{ //列挙型 enum ここでは title, //title=0 gameplay, //gameplay=1 gameover, //gameover=2 }; //の定数を定義していると考える //グローバル変数の宣言 S_player player; //自機のstructをインスタンス化   S_enemy enemy[ENEMY]; //敵のstructを S_bullet playerbullet[BULLET]; //弾のstructを自機の弾用に S_bullet enemybullet[ENEMY][BULLET]; //弾のstructを敵の弾用に S_item item[ITEM]; //アイテムのstructを S_background background; //背景のstructを S_image imglist; //画像のstructを e_flag flag; //e_flag型の変数(中身がtitle,gameplay,gameoverの3つにしかならない変数) char key[256]; //キーボードの入力状況を格納するための変数 int white=GetColor(255,255,255); //画面に表示する文字の色を格納 //初期化用関数 int initialize(){ //playerの初期化 player.hp=100; player.score=0; player.size_x=50; player.size_y=50; player.x=(WIDTH - player.size_x) / 2; player.y=HEIGHT - player.size_y; player.vx=10; player.vy=10; //playerbulletの初期化 for(int i=0;i WIDTH){ player.x = WIDTH - player.size_x; } if(player.y<0){ player.y=0; } if(player.y + player.size_y > HEIGHT){ player.y = HEIGHT - player.size_y; } } //敵を動かす関数 void move_enemy(){ //すべての敵 for(int i=0;iHEIGHT){ enemy[i].hp=0; } } } } //背景を動かす関数 void move_background(){ //x,y方向の速度を現座標に加え,背景の大きさでループさせる background.y = (background.y + background.vy) % background.size_y; } //敵を作る関数 void create_enemy(){ //0〜30の乱数で0だったら if(GetRand(30)==0){ //すべての敵から for(int i=1;i HEIGHT+enemybullet[i][j].size_y){ 【穴埋め】=0; } } } } } //自機の弾を作る関数 void create_playerbullet(){ static int t=0; //Xが連続で入力されていたフレーム数を格納,staticだから初回だけ初期化されて、それからずっと値は保持される //Xが入力されていたら if(【穴埋め】){ t++; //連続入力フレーム数を1増加 //3フレームごとに if(t%3==1){ //すべての弾から for(int i=0;i