コードを端折ってすいません
コード:
[main.cpp]
#include "pch.h"
#include "control.h"
//キー取得用配列
char key[256];
int g_count;
int state = 0;
// プログラムは WinMain から始まります
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )
{
ChangeWindowMode(TRUE);
if( DxLib_Init() == -1 ) // DXライブラリ初期化処理
{
return -1 ; // エラーが起きたら直ちに終了
}
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 && GetHitKeyStateAll(key) == 0) {
CONTROL::GetInstance().All();
}
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}
コード:
[back.cpp]
#include "back.h"
#include "pch.h"
//***********************************************************************************************
//
// コンストラクタ(初期設定)
//
//***********************************************************************************************
BACK::BACK()
{
gh = LoadGraph("DATA/BG/back_org.png");
x = y = MARGIN;
}
//***********************************************************************************************
//
// 描画処理
//
//***********************************************************************************************
void BACK::Draw()
{
//1枚目描画
DrawGraph(x, y, gh, FALSE);
//2枚目描画
DrawGraph(x, y - 460, gh, FALSE);
//一番下までスクロールしたら初期値に戻す
if (y == 460 + MARGIN)
y = 10;
}
//***********************************************************************************************
//
// 更新処理
//
//***********************************************************************************************
void BACK::Move()
{
y += SCROLL_SPEED;
}
//***********************************************************************************************
//
// All関数
//
//***********************************************************************************************
void BACK::All()
{
Draw();
Move();
}
コード:
[back.h]
class BACK {
private:
//座標
double x, y;
//グラフィックハンドル
int gh;
private:
void Draw();
public:
void Move();
void All();
BACK();
};
コード:
[player.cpp]
#include "pch.h"
#include"control.h"
//***********************************************************************************************
//
// コンストラクタ(初期設定)
//
//***********************************************************************************************
PLAYER::PLAYER()
{
//画像読み込み
if(-1==LoadDivGraph("DATA/CHR/char_org.png",12,3,4,29,40,gh))
{
MSG("エラー発生");
}
width=29;
height=40;
//移動係数
move=1.0f;
//横方向と縦方向のカウント数。
xcount=0,ycount=0;
//添字用変数
ix=0,iy=0,result=0;
//初期位置
x=180;
y=400;
//生死確認
life = 1;
//弾初期化
memset(shot, 0, sizeof(shot));
//弾画像読み込み
int temp = LoadGraph("DATA/BG/shot_org.png");
int w, h;
GetGraphSize(temp, &w, &h);
//フラグ全部falseにしとく
//グラッフィックハンドルと画像のサイズを代入しとく
for (int i = 0; i < PSHOT_NUM; ++i)
{
shot[i].flag = false;
shot[i].gh = temp;
shot[i].width = w;
shot[i].height = h;
}
count = 0;
dcount = 0;
damageflag = false;
s_dead = false;
}
//***********************************************************************************************
//
// 動作(更新処理)
//
//***********************************************************************************************
void PLAYER::Move()
{
if(key[KEY_INPUT_LEFT]==1 || key[KEY_INPUT_RIGHT]==1)
{
if(key[KEY_INPUT_UP]==1 || key[KEY_INPUT_DOWN]==1)
{
//移動係数を0.71に設定
move=0.71f;
}
else
{
//斜めじゃなければ1.0に設定
move=1.0f;
}
}
else if(key[KEY_INPUT_UP]==1 || key[KEY_INPUT_DOWN]==1)
{
move=1.0f;
}
if(key[KEY_INPUT_LEFT]==1)
{
x-=(int)PLAYER_SPEED*move;
}
if(key[KEY_INPUT_RIGHT]==1)
{
x+=(int)PLAYER_SPEED*move;
}
if(key[KEY_INPUT_UP]==1)
{
y-=(int)PLAYER_SPEED*move;
}
if(key[KEY_INPUT_DOWN]==1)
{
y+=(int)PLAYER_SPEED*move;
}
//左キーが押されてて、かつxcountが0以上なら0にしてから1引く。
//それ以外は1引く
if(key[KEY_INPUT_LEFT]==1)
{
if(xcount>0)
xcount=0;
--xcount;
}
//右キーが押されてて、かつxcountが0以下なら0にしてから1足す。
//それ以外は1引く
if(key[KEY_INPUT_RIGHT]==1)
{
if(xcount<0)
xcount=0;
++xcount;
}
//上キーが押されてて、かつycountが0以上なら0にしてから1引く。
//それ以外は1引く
if(key[KEY_INPUT_UP]==1)
{
if(ycount>0)
ycount=0;
--ycount;
}
//下キーが押されてて、かつycountが0以下なら0にしてから1足す。
//それ以外は1足す
if(key[KEY_INPUT_DOWN]==1)
{
if(ycount<0)
ycount=0;
++ycount;
}
//カウント数から添字を求める。
ix=abs(xcount)%30/10;
iy=abs(ycount)%30/10;
//xカウントがプラスなら右向きなので2行目の先頭添字番号を足す。
if(xcount>0)
{
ix+=3;
result=ix;
}
else if(xcount<0)
{
//マイナスなら左向きなので、4行目の先頭添字番号を足す。
ix+=9;
result=ix;
}
//yカウントがプラスなら下向きなので、3行目の先頭添字番号を足す。
if(ycount>0)
{
iy+=6;
result=iy;
}
else if(ycount<0)
{
//1行目の先頭添字番号は0なので何もする必要なし。(分かりやすくするために書いときました)
iy+=0;
result=iy;
}
//斜め移動の場合は横顔を優先
if(move==0.71f)
result=ix;
//押されてなければカウントをゼロにする。
if(key[KEY_INPUT_LEFT]!=1 && key[KEY_INPUT_RIGHT]!=1)
{
xcount=0;
}
if(key[KEY_INPUT_UP]!=1 && key[KEY_INPUT_DOWN]!=1)
{
ycount=0;
}
//< span class="strees">
//キャラの移動制御
if (x > 400 - MARGIN)
{
x = 400 - MARGIN;
}
else if (x < MARGIN)
{
x = MARGIN;
}
if (y > 480 - height / 2 - MARGIN)
{
y = 480 - height / 2 - MARGIN;
}
else if (y < height / 2 + MARGIN)
{
y = height / 2 + MARGIN;
}
//←キーが押されてて、かつxcountが0以上なら0にしてから1引く
//それ以外は1引く
if (key[KEY_INPUT_LEFT] == 1)
{
if (xcount > 0)
xcount = 0;
--xcount;
}
//→キーが押されてて、かつxcountが0以下なら0にしてから1足す
//それ以外は1引く
if (key[KEY_INPUT_RIGHT] == 1)
{
if (xcount < 0)
xcount = 0;
++xcount;
}
//↑キーが押されてて、かつycountが0以下なら0にしてから1足す
//それいがいは1引く
if (key[KEY_INPUT_UP] == 1)
{
if (ycount > 0)
ycount = 0;
--ycount;
}
//↓キーが押されてて、かつycountが0以下なら0にしてから1足す
//それいがいは1足す
if (key[KEY_INPUT_DOWN] == 1)
{
if (ycount < 0)
ycount = 0;
++ycount;
}
//カウント数から添字を求める
ix = abs(xcount) % 30 / 10;
iy = abs(ycount) % 30 / 10;
//xカウントがプラスなら右向きなので2行目の先頭添字番号を足す
if (xcount > 0)
{
ix += 3;
result = ix;
}
else if (xcount < 0)
{
//マイナスなら左向きなので4行目の先頭添字を足す
ix += 9;
result = ix;
}
//yカウントがプラスなら下向きなので,3行目の先頭添字を足す
if (ycount > 0)
{
iy += 6;
result = iy;
}
else if (ycount < 0)
{
//1行目の先頭添字番号は0なので何も刷る必要なし
iy += 0;
result = iy;
}
//斜めの移動の場合は横顔を優先
if (move == 0.71f)
result = ix;
//描画
DrawGraph(x - width / 2, y - height / 2, gh[result], TRUE);
//押されていなければカウントをゼロにする
if (key[KEY_INPUT_LEFT] != 1 && key[KEY_INPUT_RIGHT != 1])
{
xcount = 0;
}
if (key[KEY_INPUT_UP] != 1 && key[KEY_INPUT_DOWN] != 1)
{
ycount = 0;
}
}
//***********************************************************************************************
//
// 描画処理
//
//***********************************************************************************************
void PLAYER::Draw()
{
//弾描画
for (int i = 0; i<PSHOT_NUM; ++i)
{
if (shot[i].flag) {
DrawGraph(shot[i].x - shot[i].width / 2, shot[i].y - shot[i].height / 2, shot[i].gh, TRUE);
}
}
//生きてれば描画
if (damageflag)
{
if (dcount>20)
{
if (dcount % 2 == 0)
{
SetDrawBlendMode(DX_BLENDMODE_ALPHA, 140);
DrawGraph(PLAYER_INITX - width / 2, PLAYER_INITY - height / 2 + 60 - (dcount - 20), gh[1], TRUE);
SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
}
else
{
DrawGraph(PLAYER_INITX - width / 2, PLAYER_INITY - height / 2 + 60 - (dcount - 20), gh[1], TRUE);
}
}
++dcount;
if (dcount == 80)
{
damageflag = false;
dcount = 0;
//座標を初期値に戻す
x = PLAYER_INITX;
y = PLAYER_INITY;
//上向きの画像にする
result = 1;
}
}
else
{
//通常描画
DrawGraph(x - width / 2, y - height / 2, gh[result], TRUE);
}
}
//***********************************************************************************************
//
// 弾処理
//
//***********************************************************************************************
void PLAYER::Shot()
{
s_shot = false;
if (!damageflag)
{
//キーが押されててかつ、6ループに一回発射
if (key[KEY_INPUT_Z] == 1 && count % 6 == 0)
{
for (int i = 0; i < PSHOT_NUM; ++i)
{
if (shot[i].flag == false)
{
shot[i].flag = true;
shot[i].x = x;
shot[i].y = y;
break;
}
}
//ショットサウンドフラグを立てる
s_shot = true;
}
//弾を移動させる処理
for (int i = 0; i < PSHOT_NUM; ++i)
{
//発射してる弾だけ
if (shot[i].flag)
{
shot[i].y -= PSHOT_SPEED;
//画面の外にはみ出したらフラグを戻す
if (shot[i].y < -10)
{
shot[i].flag = false;
}
}
}
}
}
//***********************************************************************************************
//
// 位置処理(プレイヤー、弾)
//
//***********************************************************************************************
void PLAYER::GetPosition(double *x, double *y)
{
*x = this->x;
*y = this->y;
}
bool PLAYER::GetShotPosition(int index, double *x, double *y)
{
if (shot[index].flag)
{
*x = shot[index].x;
*y = shot[index].y;
return true;
}
else
{
return false;
}
}
//***********************************************************************************************
//
// SE処理
//
//***********************************************************************************************
void PLAYER::SetDamageFlag()
{
damageflag = true;
//消滅エフェクトのフラグを立てる
effect_pdead.SetFlag(x, y);
}
bool PLAYER::GetDamageFlag()
{
return damageflag;
}
void PLAYER::SetShotFlag(int index, bool flag)
{
shot[index].flag = flag;
}
bool PLAYER::GetShotSound()
{
return s_shot;
}
bool PLAYER::GetDeadSound()
{
return s_dead;
}
//***********************************************************************************************
//
// All関数
//
//***********************************************************************************************
bool PLAYER::All()
{
//消滅していないときだけ実行
if (!damageflag)
{
Move();
}
Shot();
Draw();
SetDamageFlag();
count++;
return endflag;
}
コード:
[player.h]
class PLAYER{
private:
//x座標,y座標
double x,y;
//画像幅
int width,height;
//グラフィックハンドル格納用配列
int gh[12];
//移動係数
float move;
//横方向と縦方向のカウント数。
int xcount,ycount;
//添字用変数
int ix,iy,result;
//プレイヤーのライフ
int life;
bool damageflag;
bool endflag;
//ダメージ中のカウント
int dcount;
//弾
SHOT shot[PSHOT_NUM];
//カウント
int count;
bool s_shot;
bool s_dead;
EFFECT_PDEAD effect_pdead;
private:
void Move();
void Draw();
void Shot();
public:
bool All();
PLAYER();
bool GetShotSound();
bool GetDeadSound();
bool GetShotPosition(int index, double *x, double *y);
void SetShotFlag(int index, bool flag);
void GetPosition(double *x, double *y);
void SetDamageFlag();
bool GetDamageFlag();
};
コード:
[playereffect.cpp]
#include"pch.h"
#include"control.h"
#include<ctime>
#include<cstdlib>
#include<math.h>
EFFECT_PDEAD::EFFECT_PDEAD()
{
gh[0] = LoadGraph("DATA/BG/playereffect1.png");
gh[1] = LoadGraph("DATA/BG/playereffect2.png");
gh[2] = LoadGraph("DATA/BG/playereffect3.png");
for (int i = 0; i < 3; i++)
{
GetGraphSize(gh[i], &width[i], &height[i]);
}
rate = 1;
alpha = 255;
count = 0;
flag = false;
srand((unsigned int)time(NULL));
}
void EFFECT_PDEAD::Move()
{
//初回だけ角度を保存
if (count == 0)
{
for (int i = 0; i < EFFECT_PDEADNUM; i++)
{
expand[i].rad = rand() % 628 / 100;
expand[i].speed = rand() % 10;
expand[i].x = x;
expand[i].y = y;
}
}
rate = 0.5 + (count*0.05);
alpha = 255 - (255 / 40)*count;
rota = 0.05*count;
//座標の移動
for (int i = 0; i < EFFECT_PDEADNUM; i++)
{
expand[i].x += cos(expand[i].rad)*expand[i].speed;
expand[i].y += sin(expand[i].rad)*expand[i].speed;
}
++count;
if (count == 40)
{
flag = false;
count = 0;
}
}
void EFFECT_PDEAD::Draw()
{
SetDrawBlendMode(DX_BLENDMODE_ALPHA, alpha);
//円形のエフェクト描画
DrawRotaGraph(x, y, rate, 0, gh[0], TRUE);
//円盤のエフェクト描画(2つ)
DrawRotaGraph(x, y, 1.0, rota, gh[1], TRUE);
DrawRotaGraph(x, y, 1.0, 6.26 - rota, gh[1], TRUE);
//パーティクルエフェクト描画
for (int i = 0; i < EFFECT_PDEADNUM; i++)
{
DrawGraph(expand[i].x - width[2] / 2, expand[i].y - height[2] / 2, gh[2], TRUE);
}
SetDrawBlendMode(DX_BLENDMODE_NOBLEND,0);
}
void EFFECT_PDEAD::All()
{
//フラグが立っているときだけ実行
if (flag)
{
Move();
Draw();
}
}
void EFFECT_PDEAD::SetFlag(double x, double y)
{
count = 0;
flag = true;
this->x = x;
this->y = y;
}
bool EFFECT_PDEAD::GetFlag()
{
return flag;
}
コード:
[playereffect.h]
#pragma once
struct PEFFECT_EXPAND
{
double x, y;
double rad;
int speed;
};
class EFFECT_PDEAD {
private:
//座標
double x, y;
//画像のサイズ
int width[3];
int height[3];
//グラフィックハンドル
int gh[3];
//拡大率
double rate;
//透明度
int alpha;
//パーティクルエフェクト構造体
PEFFECT_EXPAND expand[EFFECT_PDEADNUM];
//回転させる画像用の角度
double rota;
//カウント
int count;
//実行中かどうかのフラグ
bool flag;
private:
void Move();
void Draw();
public:
EFFECT_PDEAD();
void SetFlag(double x, double y);
bool GetFlag();
void All();
};
コード:
[enemy.cpp]
#define _USE_MATH_DEFINES
#include"pch.h"
#include"control.h"
#include"math.h"
#include<ctime>
#include<cstdlib>
//***********************************************************************************************
//
// コンストラクタ(初期設定)
//
//***********************************************************************************************
ENEMY::ENEMY(int type, int stype,int m_pattern,int s_pattern,int in_time,int stop_time, int shot_time, int out_time,
int x, int y, int speed, int hp, int item)
{
//サイズ
width = 27;
height = 25;
//敵の種類
this->type = type;
this->stype = stype;
//移動パターンとショットパターン
this->m_pattern = m_pattern;
this->s_pattern = s_pattern;
//座標セット
this->x = x;
this->y = y;
//出現、停止、発射、帰還時間セット
this->in_time = in_time;
this->stop_time = stop_time;
this->shot_time = shot_time;
this->out_time = out_time;
//HPとアイテム代入
this->hp = hp;
this->item = item;
//敵画像読み込み
if (type == 0)
{
LoadDivGraph("DATA/ENEMY/enemy_org.png", 3, 1, 3, 27, 25, gh);
}
if (type == 1)
{
LoadDivGraph("DATA/ENEMY/enemy_org_2.png", 3, 1, 3, 27, 25, gh);
}
if (type == 2)
{
LoadDivGraph("DATA/ENEMY/enemy_org_3.png", 3, 1, 3, 27, 25, gh);
}
int temp = 0;
//弾画像読み込み
switch (stype)
{
case 0:
temp = LoadGraph("DATA/ENEMY/enemyshot_org1.png");
break;
case 1:
temp = LoadGraph("DATA/ENEMY/enemyshot_org1.png");
break;
case 2:
temp = LoadGraph("DATA/ENEMY/enemyshot_org2.png");
break;
}
int w, h;
GetGraphSize(temp, &w, &h);
//弾の初期化
for (int i = 0; i < ENEMY_SNUM; ++i)
{
shot[i].flag = false;
shot[i].gh = temp;
shot[i].width = w;
shot[i].height = h;
shot[i].pattern = s_pattern;
shot[i].speed = speed;
shot[i].x = x;
shot[i].y = y;
}
count = 0;
scount = 0;
num = 0;
rad = 0;
deadflag = false;
endflag = false;
sflag = false;
s_shot = false;
s_dead = false;
}
//***********************************************************************************************
//
// 動作(更新処理)
//
//***********************************************************************************************
void ENEMY::Move()
{
//まだ生きてるか画面内に居るときだけ処理
if (!deadflag)
{
switch (m_pattern)
{
//途中で止まって、そのまま後ろに帰るパターン
case 0:
if (in_time<g_count && g_count<stop_time)
{
y += 2;
//帰還時間を過ぎたら戻る。
}
else if (g_count>out_time)
{
y -= 2;
}
break;
case 1:
if (in_time <= g_count)
{
y += 2;
}
break;
case 2:
if (in_time <= g_count)
{
y += 1;
if (count % 10 == 0)
{
x -= 2;
}
}
break;
case 3:
if (in_time <= g_count)
{
y += 1;
if (count % 10 == 0)
{
x += 3;
}
}
break;
}
//画面からはみ出したら、deadflag(はみ出すか死ぬかのフラグ)をtrueにする。
if (g_count >= stop_time)
{
if (OutCheck())
{
deadflag = true;
}
}
++count;
}
}
//***********************************************************************************************
//
// 弾処理
//
//***********************************************************************************************
void ENEMY::Shot()
{
//CONTROLクラスの参照
CONTROL &control = CONTROL::GetInstance();
double px, py;
//発射タイミングになったら、フラグを立てる
if (shot_time == g_count)
{
sflag = true;
}
//フラグ立ってるときだけ
if (sflag)
{
//ショット音フラグを戻す
s_shot = false;
//プレイヤーの位置取得
control.GetPlayerPosition(&px, &py);
//敵とプレイヤーとの座標の差から逆正接を求める。
//初回だけ実行
if (scount == 0)
rad = atan2(py - y, px - x);
switch (s_pattern)
{
//前方にショット
case 0:
//5ループに一回発射。20までなので5発発射。
if (scount % 5 == 0 && scount <= 20)
{
for (int i = 0; i<ENEMY_SNUM; ++i) {
//フラグが立ってない弾を探して、座標等をセット
if (shot[i].flag == false)
{
shot[i].flag = true;
shot[i].x = x;
shot[i].y = y;
shot[i].rad = rad;
break;
}
}
//ショットサウンドフラグを立てる
s_shot = true;
}
break;
//プレイヤーに向かって直線ショット
case 1:
//6ループに一回発射。54までなので10発発射。
if (scount % 6 == 0 && scount <= 54)
{
for (int i = 0; i<ENEMY_SNUM; ++i)
{
//フラグが立ってない弾を探して、座標等をセット
if (shot[i].flag == false)
{
shot[i].flag = true;
shot[i].x = x;
shot[i].y = y;
shot[i].rad = rad;
break;
}
}
//ショットサウンドフラグを立てる
s_shot = true;
}
break;
//3直線ショット
case 2:
//10ループに一回発射。1ループに3発なので5ループさせると15発発射
if (scount % 10 == 0 && scount <= 40)
{
for (int i = 0; i<ENEMY_SNUM; ++i)
{
//フラグが立ってない弾を探して、座標等をセット
if (shot[i].flag == false)
{
shot[i].flag = true;
shot[i].x = x;
shot[i].y = y;
//0はキャラクターに向かって発射
if (num == 0)
{
//敵とプレイヤーとの逆正接から30度引いたラジアンを代入
shot[i].rad = rad - (10 * 3.14 / 180);
}
else if (num == 1)
{
//敵とプレイヤーとの逆正接を代入
shot[i].rad = rad;
}
else if (num == 2)
{
//敵とプレイヤーとの逆正接から30度足したラジアンを代入
shot[i].rad = rad + (10 * M_PI / 180);
}
++num;
//3発発射したら,numを0にしてループを抜ける。
if (num == 3)
{
num = 0;
break;
}
}
}
//ショットサウンドフラグを立てる
s_shot = true;
}
break;
//乱射ショット
case 3:
//10ループに一回発射。42までなので15発発射。
if (scount % 1 == 0 && scount <= 42)
{
for (int i = 0; i<ENEMY_SNUM; ++i)
{
//フラグが立ってない弾を探して、座標等をセット
if (shot[i].flag == false)
{
shot[i].flag = true;
shot[i].x = x;
shot[i].y = y;
//初回だけ乱数初期化
if (num == 0)
srand((unsigned int)time(NULL));
shot[i].rad = atan2(py - y, px - x) - (60 * M_PI / 180) + ((rand() % 120)*M_PI / 180);
++num;
break;
}
}
//ショットサウンドフラグを立てる
s_shot = true;
}
break;
}
//フラグが立ってる弾の数
int s = 0;
//フラグ立ってる弾だけ、弾の移動を行う
for (int i = 0; i<ENEMY_SNUM; ++i)
{
if (shot[i].flag)
{
switch (shot[i].pattern)
{
//単純に下に発射
case 0:
shot[i].y += shot[i].speed;
break;
case 1:
shot[i].x += shot[i].speed*cos(shot[i].rad);
shot[i].y += shot[i].speed*sin(shot[i].rad);
break;
case 2:
shot[i].x += shot[i].speed*cos(shot[i].rad);
shot[i].y += shot[i].speed*sin(shot[i].rad);
break;
case 3:
shot[i].x += shot[i].speed*cos(shot[i].rad);
shot[i].y += shot[i].speed*sin(shot[i].rad);
break;
}
//弾が画面をはみ出たらフラグを戻す。
if (ShotOutCheck(i))
{
shot[i].flag = false;
continue;
}
++s;
}
}
//sがゼロということは発射中の弾がない。
//かつdeadflagがTRUEということはこの敵のクラスは消滅させてもよい
if (s == 0 && deadflag)
{
//敵クラス消滅フラグをTRUEにする
endflag = true;
s_dead = true;
}
++scount;
}
}
//***********************************************************************************************
//
// 弾範囲処理
//
//***********************************************************************************************
bool ENEMY::ShotOutCheck(int i)
{
//弾が画面をはみ出たらフラグを戻す。
if (shot[i].x < -20 || shot[i].x>420 || shot[i].y < -20 || shot[i].y>500)
{
return true;
}
else
{
return false;
}
}
bool ENEMY::OutCheck()
{
if (x<-50 || x>520 || y<-50 || y>530) {
return true;
}
else {
return false;
}
}
//***********************************************************************************************
//
// 描画処理
//
//***********************************************************************************************
void ENEMY::Draw()
{
int temp;
//弾から最初に描画
for (int i = 0; i<ENEMY_SNUM; ++i)
{
if (shot[i].flag)
{
if (stype == 0 || stype == 2)
{
DrawGraph(shot[i].x - shot[i].width / 2, shot[i].y - shot[i].height / 2, shot[i].gh, true);
}
else
{
DrawRotaGraph(shot[i].x, shot[i].y, 1.0, shot[i].rad - (90 * M_PI / 180), shot[i].gh, true);
}
}
}
if (!deadflag)
{
temp = count % 40 / 10;
if (temp == 3)
temp = 1;
DrawGraph(x - width / 2, y - height / 2, gh[temp], TRUE);
}
}
//***********************************************************************************************
//
// 位置処理(敵、弾)
//
//***********************************************************************************************
void ENEMY::GetPosition(double *x, double *y)
{
*x = this->x;
*y = this->y;
}
bool ENEMY::GetShotPosition(int index, double *x, double *y)
{
if (shot[index].flag)
{
*x = shot[index].x;
*y = shot[index].y;
return true;
}
else
{
return false;
}
}
//***********************************************************************************************
//
// SE処理
//
//***********************************************************************************************
//弾の種類
int ENEMY::GetShotType()
{
return stype;
}
//弾
void ENEMY::SetShotFlag(int index, bool flag)
{
shot[index].flag = flag;
}
bool ENEMY::GetShotSound()
{
return s_shot;
}
//死
void ENEMY::SetDeadFlag()
{
deadflag = true;
}
bool ENEMY::GetDeadFlag()
{
return deadflag;
}
bool ENEMY::GetDeadSound()
{
return s_dead;
}
//***********************************************************************************************
//
// All関数
//
//***********************************************************************************************
bool ENEMY::All()
{
Move();
Shot();
OutCheck();
Draw();
GetShotSound();
++count;
return endflag;
}
コード:
[enemy.h]
class ENEMY {
private:
//座標とグラフィックハンドル
double x, y;
int gh[3];
//画像サイズ
int width, height;
//出現、停止、帰還、発射タイミング
int in_time, stop_time, out_time, shot_time;
//敵の種類
int type;
//弾の種類
int stype;
//移動パターン
int m_pattern;
//ショットパターン
int s_pattern;
//HP
int hp;
//アイテム
int item;
//敵が出現してからのカウント
int count;
//発射した段数
int num;
//発射直後のラジアン
double rad;
//敵消滅フラグ
bool deadflag;
//敵クラス消滅フラグ
bool endflag;
//弾構造体
E_SHOT shot[ENEMY_SNUM];
//ショットが撃てるようになったかのフラグ
bool sflag;
//ショットが打てるようになってからのカウント
int scount;
bool s_shot;
bool s_dead;
private:
void Move();
void Shot();
void Draw();
bool OutCheck();
bool ShotOutCheck(int i);
public:
bool All();
void GetPosition(double *x, double *y);
bool GetShotPosition(int index, double *x, double *y);
void SetShotFlag(int index, bool flag);
int GetShotType();
ENEMY(int type, int stype, int m_pattern, int s_pattern, int in_time, int stop_time, int shot_time, int out_time,
int x, int y, int speed, int hp, int item);
bool GetShotSound();
void SetDeadFlag();
bool GetDeadFlag();
bool GetDeadSound();
};
コード:
[enemyeffect.cpp]
#include"pch.h"
#include"control.h"
#include<ctime>
#include<cstdlib>
int EFFECT_EDEAD::gh[3];
EFFECT_EDEAD::EFFECT_EDEAD()
{
x = y = 0;
//画像読み込み
if (gh[0] == 0)
{
gh[0] = LoadGraph("DATA/ENEMY/effect1.png");
gh[1] = LoadGraph("DATA/ENEMY/effect2.png");
gh[2] = LoadGraph("DATA/ENEMY/effect3.png");
}
srand((unsigned int)time(NULL));
rad = 0;
rate = 1;
alpha = 255;
count = 0;
flag = false;
index = 0;
}
void EFFECT_EDEAD::Move()
{
if (flag)
{
//角度と添字セット
if (count == 0)
{
rad = rand() % 624 / 100;
index = rand() % 3;
}
rate = 0.5 + count*0.05;
alpha = 255 - 255 / 30 * count;
++count;
if (count == 30)
{
count = 0;
flag = false;
}
}
}
void EFFECT_EDEAD::Draw()
{
SetDrawBlendMode(DX_BLENDMODE_ALPHA, alpha);
DrawRotaGraph(x, y, rate, rad, gh[index], TRUE);
SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0);
}
void EFFECT_EDEAD::All()
{
Move();
Draw();
}
void EFFECT_EDEAD::SetFlag(double x, double y)
{
this->x = x;
this->y = y;
flag = true;
}
bool EFFECT_EDEAD::GetFlag()
{
return flag;
}
コード:
[enemyeffect.h]
#pragma once
class EFFECT_EDEAD {
private:
//座標
double x, y;
//グラフィックハンドル
static int gh[3];
//エフェクト画像の角度
double rad;
//拡大率
double rate;
//透明度
int alpha;
//どの画像を使うかの添字
int index;
//カウント
int count;
//実行中かどうかのフラグ
bool flag;
private:
void Move();
void Draw();
public:
EFFECT_EDEAD();
bool GetFlag();
void SetFlag(double x, double y);
void All();
};
コード:
[control.cpp]
#pragma once
class EFFECT_EDEAD {
private:
//座標
double x, y;
//グラフィックハンドル
static int gh[3];
//エフェクト画像の角度
double rad;
//拡大率
double rate;
//透明度
int alpha;
//どの画像を使うかの添字
int index;
//カウント
int count;
//実行中かどうかのフラグ
bool flag;
private:
void Move();
void Draw();
public:
EFFECT_EDEAD();
bool GetFlag();
void SetFlag(double x, double y);
void All();
};
コード:
[control.h]
#include "player.h"
#include"back.h"
#include"enemy.h"
#include"title.h"
#include"enemyefect.h"
#include"playereffect.h"
class CONTROL{
private:
//プレイヤークラス
PLAYER *player;
//背景クラス
BACK *back;
//エネミークラス
ENEMY *enemy[ENEMY_NUM];
TITLE *title;
//敵消滅エフェクトクラス
EFFECT_EDEAD *effect_edead[EFFECT_EDEADNUM];
//サウンドハンドル
int s_eshot;
int s_pshot;
int s_edead;
int s_pdead;
//サウンドを鳴らすかどうかのフラグ
bool eshot_flag;
bool pshot_flag;
//敵死亡
bool edead_flag;
//プレイヤー死亡
bool pdead_flag;
private:
CONTROL();
~CONTROL();
void SoundAll();
void CollisionAll();
bool CircleCollision(double c1, double c2, double cx1, double cx2, double cy1, double cy2);
void EnemyDeadEffect(double x, double y);
public:
void All();
void GetPlayerPosition(double *x, double *y);
void GetEnemyPosition(int index, double *x, double *y);
static CONTROL& GetInstance() {
static CONTROL control;
return control;
}
};
コード:
[pch.h]
//警告を消すための記述
#pragma warning(disable:4244)
#define _CRT_SECURE_NO_WARNINGS
//DXライブラリとdefine.hの取り込み
#include "DxLib.h"
#include "define.h"
コード:
[define.h]
#include <windows.h>
//プレイヤーの歩くスピード
#define PLAYER_SPEED 4
//プレイヤー初期位置
#define PLAYER_INITX 180
#define PLAYER_INITY 400
//x = 180;
//y = 400;
//座標取得
#define MARGIN 10
//背景スクロールスピード
#define SCROLL_SPEED 2
//弾処理
#define PSHOT_NUM 20
#define PSHOT_SPEED 14
//当たり判定用半径定義
#define PLAYER_COLLISION 4
#define ENEMY1_COLLISION 14
#define PSHOT_COLLISION 3
#define ESHOT0_COLLISION 10
#define ESHOT1_COLLISION 3
#define ESHOT2_COLLISION 2
//敵消滅エフェクト
#define EFFECT_EDEADNUM 20
//プレイヤー消滅エフェクト
#define EFFECT_PDEADNUM 20
//メッセージボックス
#define MSG(m) {\
MessageBox(NULL,m,"メッセージ",MB_OK);}
//extern宣言してkey配列にどこからでもアクセスできるようにする
extern char key[256];
extern int g_count;
//プレイヤー弾
struct SHOT
{
bool flag; //弾が発射中かどうか
double x; //x座標
double y; //y座標
int gh; //グラフィックハンドル
int width, height; //画像の幅と高さ
};
//エネミー弾
struct E_SHOT
{
bool flag; //弾が発射中かどうか
double x; //x座標
double y; //y座標
double rad; //角度(ラジアン)
int gh; //グラフィックハンドル
int width, height; //画像の幅と高さ
int pattern; //ショットパターン
int speed; //弾スピード
};
#define ENEMY_SNUM 50
//エネミーデータ
struct ENEMY_DATA
{
int type; //敵種類
int stype; //弾種類
int m_pattern; //移動パターン
int s_pattern; //発射パターン
int in_time; //出現時間
int stop_time; //停止時間
int shot_time; //弾発射時間
int out_time; //帰還時間
int x; //x座標
int y; //y座標
int speed; //弾スピード
int hp; //HP
int item; //アイテム
};
#define ENEMY_NUM 20
エラーは先ほど記述したものだけでした。