弾が画面外に出ると 末尾データを代入→末尾データを削除 としたいのですが、
弾の数が3個以上のとき、画面外に出るとフリーズしてしまいます。
intでの解説+サンプルを見ながら自分なりに作ってみたので、
処理順序か何かが変な部分があると思うんですが…
(たぶんフリーズ原因はSHOTHandleだと)
とりあえず関係してる部分のソースを書き出します。
開発環境はBCC Developerです。
#include "DxLib.h"
#include <list>
#include <stdio.h>
struct ShotManage{
int flag; //敵か味方か
double x,y;
double movex,movey;
int sizex,sizey;
int type;
int range;
int atk;
};
list <ShotManage> shot;
void SHOTHandle(void);
void CreateShot(int men,int human,int type,double x,double y);
void SHOTHandle(void){
if( shot.empty()!=1 ){ //空で無ければ
list<ShotManage>::iterator it;
ShotManage obj;
for( it = shot.begin(); it != shot.end() ; ++it){
obj = *it;
if(obj.x>800 || obj.x<-160
||obj.y>480+obj.sizey/2
||obj.y<0-obj.sizey/2 ){ //画面外に出たら
list<ShotManage>::iterator lastobj; //末尾の1つ後
lastobj = shot.end();
lastobj--; //末尾にずらす
obj = *lastobj; //末尾情報を消したい弾に上書き
shot.pop_back(); //末尾削除
if( shot.empty()==1 ){break;}
}
obj.x+=obj.movex;
obj.y+=obj.movey;
*it = obj;
}
}
}
void CreateShot(int men,int human,int type,double x,double y){
ShotManage obj;
obj.flag=human;//敵か味方か
obj.x=x;obj.y=y;
obj.type=type;
GetGraphSize( pic.shot[obj.type] , &obj.sizex , &obj.sizey ) ;
obj.range =(obj.sizex>obj.sizey)? obj.sizey:obj.sizex;
if(human==mikata){
if(type==0){
obj.movex=8;
obj.movey=0;
obj.atk=1;
}
}
if(human==teki){
//敵の弾
}
shot.push_back(obj);
}
何度もすみませんが、よろしくお願いします。