ここのページ(
https://bituse.info/game/shot/10)を見ながら敵に弾を撃たせようとしたのですがcontrol.cppで敵クラスを作成したときに引数リストが一致しませんとエラーが出てしまいます。サイトでも()内の引数が違うにもかかわらずエラーが出ないので疑問に思ってます。エラーはコード内にメモしておきます。
コード:
//enemy.h敵クラス
#include "pch.h"
//pch.hはDxLibや様々な定数を宣言
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;
//カウント
int count;
//敵消滅フラグ
bool deadflag;
//敵クラス消滅フラグ
bool endflag;
//敵弾用構造体宣言
E_SHOT shot[ENEMY_SNUM];
//ショットが打てるようになったのかどうかのフラグ
bool sflag;
//ショットが打てるようになってからのカウント
int scount;
public:
bool All();
void Move();
void Shot();
void Draw();
ENEMY(char *fff, int type, int m_pattern, int x, int y, int in_time, int stop_time, int shot_time, int out_time, char *ggg, int stype, int s_pattern, int speed);
//control.cppで11個の引数を持つ関数を定義,fffは敵の画像,gggは弾の画像
};
コード:
//enemy.cpp関数定義
#include "pch.h"
#include "enemy.h"
ENEMY::ENEMY(char *fff, int type, int m_pattern, int x, int y, int in_time, int stop_time, int shot_time, int out_time, char *ggg, int stype, int s_pattern, int speed)
{
LoadDivGraph("fff.png", 3, 1, 3, 27, 25, gh); //fffが敵本体の画像、gggが敵の弾画像。
width = 27;
height = 25;
//敵の種類
this->type = type;
//弾の種類
this->stype = stype;
//移動パターンとショットパターン
this->in_time = in_time;
this->stop_time = stop_time;
this->shot_time = shot_time;
this->out_time = out_time;
//弾画像とサイズ取得
int temp = LoadGraph(ggg);
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;
deadflag = false;
endflag = false;
sflag = false;
}
void ENEMY::Move()
{
//出てきてから止まる時間までの間ならば下に移動
if (in_time < g_count && g_count < stop_time) {
y += 2;
}
else if (g_count > out_time) {
y -= 2;
if (y < -40) {
endflag = true; //y=-40すなわち画面外に出たら描写終了フラグを真にしておく
}
}
}
void ENEMY::Shot()
{
//発射タイミングになったらフラグを真にする
if (shot_time == g_count) {
sflag = true;
}
//フラグが真のときだけ
if (sflag) {
switch (s_pattern) {
case 0:
//10回に一回発射。40までなので4発発射
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;
}
}
}
break;
}
//フラグが真の弾の数
int s = 0;
//フラグが真の弾だけ、弾の移動を行う
for (int i = 0; i < ENEMY_SNUM; ++i) {
if (shot[i].flag) {
shot[i].y += shot[i].speed;
//画面外に弾が移動したときフラグをfalseに戻す
if (shot[i].x < -20 || shot[i].x>420 || shot[i].y < -20 || shot[i].y>500) {
shot[i].flag = false;
continue;
}
++s;
}
}
//sがゼロならば発射中の弾はない
//かつdeadflagがTRUEならこの敵のクラスは消滅させていい
if (s == 0 && deadflag) {
//敵クラス消滅フラグをTRUEにする
endflag = true;
}
++scount;
}
}
//他の関数の定義は省略させていただきます。
コード:
//control.cpp
#include "pch.h"
#include "control.h"
CONTROL::CONTROL()
{
//プレイヤークラスの生成
player = new PLAYER;
//背景クラスの作成
back = new BACK;
//ENEMYクラスの生成
enemy = new ENEMY("enemy.png", 0, 50, -40, 120, 180, 181, 360, "enemyshot1.png", 0, 4);
//ここでコンストラクターENEMY::ENEMYのインスタンスが引数リストと一致しませんと出てきてしまう。
}