改造したいこととしては、敵であるモグラ(今回はゴーストとしています)をただ配置するのではなく、動かしたいなと思っています。
#define GHOST_NUM 10
#include"DxLib.h"
#include<stdlib.h>
#include<time.h>
struct Ghost{
int x;
int y;
int r;
int hit;
int width;
int height;
};
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR lpC, int nC)
{
const int n = GHOST_NUM;
struct Ghost enermy[GHOST_NUM], player;
for (i = 0; i < n; i++) {
enermy[i].x = rand() % 640;
enermy[i].y = rand() % 480;
enermy[i].r = 30;
enermy[i].hit = 0;
enermy[i].width = 80;
enermy[i].height = 40;
}
player.r = 55;
player.width = 100;
player.height = 110;
GetMousePoint(&player.x, &player.y);
mouseInput = GetMouseInput();
//左クリック当たり判定
if ((mouseInput & MOUSE_INPUT_LEFT) != 0) {
for (i = 0; i < n; i++) {
if (enermy[i].hit == 0) {
d[0] = player.r + enermy[i].r;
d[1] = player.x - enermy[i].x;
d[2] = player.y - enermy[i].y;
if (d[0] * d[0] >= d[1] * d[1] + d[2] * d[2]) {
enermy[i].hit = 1;
count++;
PlaySoundMem(hitSound, DX_PLAYTYPE_BACK);
}
}
}
DrawGraph(0, 0, backImg, FALSE);
for (ghostX = 0; ghostX < 640; ghostX+=2) {
ClearDrawScreen();
for (i = 0; i < n; i++) {
if (enermy[i].hit == 0) {
DrawRotaGraph(ghostX, enermy[i].y - enermy[i].height / 2, 0.15, 0.15, ghostImg, TRUE);
//※1
}
}
}
DrawRotaGraph(player.x - player.width / 2, player.y - player.height / 2,0.1,0.1, sword, TRUE);
今の状態だと、ゴーストがすでに動き終わった状態での表示になり、また当たり判定も本来ゴーストが配置されていたであろう場所に残ってしまいます。
※1のところにScreenFilpかなと思っていれてみたのですが、すると背景が消えてしまうので、今は消している状態です。
背景の上をゴーストが移動し、当たり判定も同時に動くようにするには、どうしたら良いですか?