dxlib シューティングで自機から弾を無限に発射するプログラムで一発しかでない原因が知りたい。
shot_controlクラスのUpdate()の部分のあたりなのですがなぜ弾が一発しか発射されないのでしょうか?配列の要素もDraw()関数部で回してるのですが原因がわからないのですが原因も知りたいので質問しました設計の仕方自体に問題があればそれも教えてくれますでしょうか?
#include "DxLib.h"
#include "math.h"
#include <string>
using namespace std;
static int key[256];
static int Color = GetColor(255, 255, 255);
int KeyBord_Get(int keycode)
{
char tmpkey[256];
GetHitKeyStateAll(tmpkey);
for (int i = 0; i < 256; i++)
{
if (tmpkey[i] != 0)
{
key[i]++;
}
else
{
key[i] = 0;
}
}
return key[keycode];
}
//--------------ショット攻撃
class Shot_Control
{
private:
typedef struct
{
int x;
int y;
int width;
int height;
int shot_gh;
int flag = false;
}shot;
int shot_flag = false;
int count = 0;
shot gh[40];
public:
int start_x;
int start_y;
void Draw()
{
for (int i = 0; i < 40; i++)
{
DrawGraph(gh[i].x, gh[i].y, gh[i].shot_gh, true);
}
}
void Move()
{
for (int i = 0; i < 45; i++)
{
if (gh[i].flag == false)
{
gh[i].x = start_x;
gh[i].y = start_y;
}
if(gh[i].flag == true)
{
gh[i].y -= 4;
}
}
if (shot_flag == true)
{
for (int i = 0; i < 45; i++)
{
gh[i].flag = true;
}
}
}
void Finalize()
{
for (int i = 0; i < 40; i++)
{
if (gh[i].y < -10)
{
gh[i].flag = false;
}
}
}
void Update(int xx,int yy)
{
start_x = xx;
start_y = yy;
if (key[KEY_INPUT_Z] >= 1)
{
if (count % 6 == 0)
{
shot_flag = true;
}
else
{
shot_flag = false;
}
}
DrawFormatString(0, 10, Color, "flag: %d", shot_flag);
DrawFormatString(0,0,Color,"x: %d , y: %d",start_x,start_y);
Move();
count++;
}
void Initialize(const char *str,int w, int h)
{
for (int i = 0; i < 40; i++)
{
gh[i].shot_gh = LoadGraph(str);
//gh[i].x = xx;
//gh[i].y = yy;
gh[i].width = w;
gh[i].height = h;
gh[i].flag = false;
}
}
};
//------------------プレイヤークラス
class Player_Control
{
private:
int gh;
int width;
int height;
bool flag;
public:
int x;
int y;
Player_Control()
{
}
void Draw()
{
DrawGraph(x,y,gh,true);
//DrawGraph(x,y - 3,gh,true);
}
void Update()
{
if (KeyBord_Get(KEY_INPUT_UP) >= 1)
{
y = y - 2;
}
if (KeyBord_Get(KEY_INPUT_RIGHT) >= 1)
{
x = x + 2;
}
if (KeyBord_Get(KEY_INPUT_LEFT) >= 1)
{
x = x - 2;
}
if (KeyBord_Get(KEY_INPUT_DOWN) >= 1)
{
y = y + 2;
}
if (KeyBord_Get(KEY_INPUT_Z) >= 1)
{
}
}
void Initialize()
{
gh = LoadGraph("resources/Player.png");
//DrawFormatString(0,0,Color,"aaaaa");
x = 200;
y = 200;
width = 45;
height = 45;
}
};
Player_Control player;
Shot_Control player_shot;
//初期化
void Game_Initialize()
{
player_shot.Initialize("resources/Player_Shot.png",14,3);
player.Initialize();
}
//計算
void Game_Update()
{
player.Update();
player_shot.Update(player.x,player.y);
}
//描画
void Game_Draw()
{
player.Draw();
player_shot.Draw();
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
ChangeWindowMode(TRUE);
if (DxLib_Init() == -1) { return -1; }
Game_Initialize();
while (ClearDrawScreen() == 0 && SetDrawScreen(DX_SCREEN_BACK) == 0 && ProcessMessage() == 0)
{
Game_Update();
Game_Draw();
ScreenFlip();
if (CheckHitKey(KEY_INPUT_ESCAPE) == 1) { break; }
}
return 0;
}