龍神録第13章を参考に敵にショットを撃たせる処理を実装しようとしているのですがうまくいきません。
12章までは問題なく実装できています。
なおエラーの内容は
「初回例外が 0x006F4B97 (GameProg2.exe) で発生しました: 0xC00000FD: Stack overflow (パラメーター: 0x00000000, 0x00DB2000)。」
というものです。
eshot_Drawやdefine.h,struct.hをいじっていたらこういう状況になってしまい画面すら表示できない状況です・・・。
他力本願だと思いますがアドバイスをいただければ幸いです。
以下にコードを書きます。
define.h
#define ENEMY_ORDER_MAX 500
#define ENEMY_MAX 30
#define FIELD_MAX_X 384
#define FIELD_MAX_Y 448
#define F_X 32
#define F_Y 16
#define PI 3.1415926535898
#define ENEMY_PATTERN_MAX 11
#define SHOT_KND_MAX 1
#define SHOT_HYOUZI_MAX 30
struct.h
#define ESHOT_BULLET_MAX 1000
#define SHOT 3
typedef struct
{
int x;
int y;
int ex;
int ey;
int es;
int count;
int sx[SHOT];
int sy[SHOT];
int shot_flag[SHOT];
int angle;
int x_speed;
int y_speed;
int score;
int SE1;
int SE2;
int image1;
int image2;
int image3;
int image4;
int image5;
}ch;
typedef struct
{
int cnt, pattern, knd;
double x, y, sp;
int bltime, blknd, color, hp, blknd2, wait, item_n[6];
}ENEMYDATA;
typedef struct
{
int flag, cnt, pattern, muki, knd, hp, hp_max, item_n[6], img;
double x, y, vx, vy, sp, ang;
int bltime, blknd, blknd2, color, state, wtime, wait;
}ENEMYDATA_T;
typedef struct{
int flag, knd, cnt, col, state, till, eff;
double x, y, angle, spd, base_angle[1], rem_spd[1];
}bullet_t;
typedef struct{
int flag, knd, cnt, num;
double base_angle[1], base_spd[1];
bullet_t bullet[ESHOT_BULLET_MAX];
}shot_t;
main.cpp
#include "DxLib.h"
#include "struct.h"
#include "Player.h"
#include "Shot.h"
#include "Enemy.h"
#include "AtariHantei.h"
#include "BackGround.h"
#include "define.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
ch tama;
ENEMYDATA e[ENEMY_ORDER_MAX];
ENEMYDATA_T e2[ENEMY_MAX];
shot_t shot[SHOT_HYOUZI_MAX];
Player_syokika(&tama,shot);
enemy_data_read(e,e2);
int y=0,count = 0,second= 0,minutes=0;
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 )
{
back_ground(tama,&y,&second,&minutes,&count);
Player_control(&tama,&count);
enemy_enter(e, e2, &count);
enemy_control(e2, shot);
shot_control(&tama, e2, &count);
eshot_main(shot, e2, tama);
enemy_Draw(tama, e2);
Player_Draw(tama);
eshot_Draw(shot, tama);
shot_Draw(tama);
count++;
second++;
}
DxLib_End();
return 0;
}
shot.cpp
#include "DxLib.h"
#include <math.h>
#include "define.h"
#include "struct.h"
#include "eshot_pattern.h"
extern void eshot_pattern_H000(int, shot_t *shot, ENEMYDATA_T *e2, ch tama);
void(*eshot_pattern_[SHOT_KND_MAX])(int,shot_t *shot, ENEMYDATA_T *e2, ch tama) =
{
eshot_pattern_H000,
};
double shotatan2(int n, shot_t *shot, ch tama,ENEMYDATA_T *e2)
{
return atan2(tama.y-e2[shot[n].num].y,tama.x-e2[shot[n].num].x);
}
int shot_search(int n, shot_t *shot)
{
int i;
for (i = 0; i < ESHOT_BULLET_MAX; i++)
{
if (shot[n].bullet[i].flag == 0)
{
return(i);
}
}
return(-1);
}
void eshot_calc(int n, shot_t *shot, ENEMYDATA_T *e2)
{
int i, max = 0;
if (e2[shot[n].num].flag != 1)
{
shot[n].flag = 2;
}
for (i = 0; i < ESHOT_BULLET_MAX; i++)
{
if (shot[n].bullet[i].flag>0)
{
shot[n].bullet[i].x += cos(shot[n].bullet[i].angle)*shot[n].bullet[i].spd;
shot[n].bullet[i].y += sin(shot[n].bullet[i].angle)*shot[n].bullet[i].spd;
shot[n].bullet[i].cnt++;
if (shot[n].bullet[i].x<-50 || shot[n].bullet[i].x>FIELD_MAX_X + 50 || shot[n].bullet[i].y<-50 || shot[n].bullet[i].y>FIELD_MAX_Y + 50)
{
if (shot[n].bullet[i].till < shot[n].bullet[i].cnt)
shot[n].bullet[i].flag = 0;
}
}
}
for (i = 0; i < ESHOT_BULLET_MAX; i++)
{
if (shot[n].bullet[i].flag>0)
{
return;
}
}
if (e2[shot[n].num].flag != 1)
{
shot[n].flag = 0;
e2[shot[n].num].flag = 0;
}
}
void eshot_Draw(shot_t *shot, ch tama)
{
int i, j;
for (i = 0; i < SHOT_HYOUZI_MAX; i++)
{
if (shot[i].flag>0)
{
for (j = 0; ESHOT_BULLET_MAX; j++)
{
if (shot[i].bullet[j].flag != 0)
{
if (shot[i].bullet[j].eff == 1)
DrawRotaGraph(shot[i].bullet[j].x + F_X, shot[i].bullet[j].y + F_Y, 1.0, shot[i].bullet[j].angle + PI / 2, tama.image1, TRUE);
if (shot[i].bullet[j].eff == 1)
{
}
}
}
}
}
SetDrawMode(DX_DRAWMODE_NEAREST);
}
void eshot_main(shot_t *shot, ENEMYDATA_T *e2, ch tama)
{
int i;
for (i = 0; i < SHOT_HYOUZI_MAX; i++)
{
if (shot[i].flag != 0 && 0 <= shot[i].knd&&shot[i].knd < SHOT_KND_MAX)
{
eshot_pattern_[shot[i].knd](i, shot, e2, tama);
eshot_calc(i, shot, e2);
shot[i].cnt++;
}
}
}
enemy.cpp
void shot_enter(int i, ENEMYDATA_T *e2,shot_t *shot)
{
int j;
for (j = 0; j < SHOT_HYOUZI_MAX; j++)
{
if (shot[j].flag == 0)
{
memset(&shot[j], 0, sizeof(shot_t));
shot[j].flag = 1;
shot[j].knd = e2[i].blknd;
shot[j].num = i;
shot[j].cnt = 0;
return;
}
}
}