今回は、前回のインベーダーゲームが完成したので、龍神録を参考にシューティングを作ってみようと思い、作っています。22章のボムを撃ってみようで躓いたので質問をしにきました。
effect.cpp
#include "DxLib.h"
#include <math.h>
#include "effect.h"
#include "define.h"
#include "struct.h"
#include "common.h"
static int img_deth_eff[5];
static int img_eff_bomb[5];
static int se_bomb;
void effect_load_and_ini(){
LoadDivGraph("dat/hit_effect.png",5,5,1,140,140,img_deth_eff);
img_eff_bomb[0] = LoadGraph("dat/bom0.png"); //ボムeff1
img_eff_bomb[1] = LoadGraph("dat/bom1.png"); //ボムeff2
img_eff_bomb[2] = LoadGraph("dat/bom_title0.png"); //the shot of power
img_eff_bomb[3] = LoadGraph("dat/face_mr00_0.png"); //カットイン
se_bomb = LoadSoundMem("dat/se/bomb.wav"); //ボム
memset(effect,0,sizeof(effect_t)*EFFECT_MAX);
memset(deth_eff,0,sizeof(del_effect_t)*DETH_EFFECT_MAX);
memset(&dn,0,sizeof(dn_t));
memset(&bright_set,0,sizeof(bright_set_t));
memset(&bomb,0,sizeof(bomb_t));
}
int effect_search(){
for(int i=0;i<EFFECT_MAX;i++){
if(deth_eff[i].flag>0)
return i;
}
return -1;
}
void effect_calc(){
for(int i=0;i<EFFECT_MAX;i++){
if(effect[i].flag>0){
switch(effect[i].knd){
case 0:
effect[i].cnt++;
effect[i].r+=0.08;
if(effect[i].cnt>10)//10カウント以上になったら
effect[i].brt-=25;//明るさを低くする
if(effect[i].cnt>20)//20カウント以上になったら
effect[i].flag=0;//消す
break;
case 1:
//座標計算
effect[i].x+=cos(effect[i].mvang)*effect[i].spd;
effect[i].y+=sin(effect[i].mvang)*effect[i].spd;
//スピード計算
if(effect[i].cnt<60)
effect[i].spd-=(0.2+effect[i].cnt*effect[i].cnt/3000.0);
if(effect[i].cnt==60){
effect[i].spd=0;
dn.flag=1;
dn.cnt=0;
dn.size=11;
dn.time=20;
}
//明るさと大きさ計算
effect[i].r+=0.015;
if(effect[i].cnt<51)
effect[i].brt+=5;
if(effect[i].cnt>=60){
effect[i].r+=0.04;
effect[i].brt-=255/30.0;
}
//カウントアップと消去計算
effect[i].cnt++;
if(effect[i].cnt>=90)
effect[i].flag=0;
break;
case 2:
//座標計算
effect[i].x+=cos(effect[i].mvang)*effect[i].spd;
effect[i].y+=sin(effect[i].mvang)*effect[i].spd;
//明るさ計算
if(effect[i].cnt<51)
effect[i].brt+=4;
if(effect[i].cnt>130-51)
effect[i].brt-=4;
//カウントアップと消去計算
effect[i].cnt++;
if(effect[i].cnt>=130)
effect[i].flag=0;
break;
case 3:
//座標計算
effect[i].x+=cos(effect[i].mvang)*effect[i].spd;
effect[i].y+=sin(effect[i].mvang)*effect[i].spd;
//明るさ計算
if(effect[i].cnt<51)
effect[i].brt+=2;
if(effect[i].cnt>130-51)
effect[i].brt-=2;
//カウントアップと消去計算
effect[i].cnt++;
if(effect[i].cnt>=130)
effect[i].flag=0;
break;
default:
printfDx("effect設定エラー^q^\n");
break;
}
}
}
}
int effect_deth_search(){
for(int i=0;i<DETH_EFFECT_MAX;i++){
if(deth_eff[i].flag==0)
return i;
}
return -1;
}
void effect_enter_deth(int s){
int k=effect_deth_search();
if(k != -1){
deth_eff[k].flag=1;
deth_eff[k].cnt =0;
deth_eff[k].col=Enemy[s].back_col;
deth_eff[k].x=Enemy[s].x;
deth_eff[k].y=Enemy[s].y;
}
}
void effect_deth_calc(){
int k;
for(int i=0;i<DETH_EFFECT_MAX;i++){
if(deth_eff[i].flag>0){
if(deth_eff[i].cnt%2==0){
if((k=effect_search())!=-1){
effect[k].flag=1;
effect[k].brt=255;
effect[k].ang=rang(PI);
effect[k].col=deth_eff[i].col;
effect[k].eff=1;//光エフェクト
effect[k].img=img_deth_eff[i];
effect[k].knd=0;//消滅effect
effect[k].x=deth_eff[i].x;
effect[k].y=deth_eff[i].y;
}
}
if(deth_eff[i].cnt>8){//8カウント以上なら
deth_eff[i].flag=0;
}
deth_eff[i].cnt++;
}
}
}
void effect_graph(int knd){
for(int i=0;i<EFFECT_MAX;i++){
if(effect[i].flag>0 && effect[i].knd==knd){
if(effect[i].eff==1)
SetDrawBlendMode(DX_BLENDMODE_ADD,effect[i].brt);//光エフェクト
if(effect[i].eff==2)
SetDrawBlendMode(DX_BLENDMODE_ALPHA,effect[i].brt);
DrawRotaGraph(effect[i].x+FIELD_X+dn.x,effect[i].y+FIELD_Y+dn.y,effect[i].r,effect[i].ang,effect[i].img,TRUE);
if(effect[i].eff==1 || effect[i].eff==2)
SetDrawBlendMode(DX_BLENDMODE_NOBLEND,0);
}
}
}
void effect_enter_bomb(){
int k;
bomb.flag=1;
bomb.cnt=0;
bomb.knd=0;
Player.mutekicnt=1;//無敵
PlaySoundMem(se_bomb,DX_PLAYTYPE_BACK);
if((k=effect_search())!=-1){
effect[k].flag =1;
effect[k].cnt =0;
effect[k].brt =0;
effect[k].knd =3;
effect[k].ang =-PI/2;
effect[k].mvang=-PI/2;
effect[k].spd =1;
effect[k].r =1;
effect[k].eff =2;
effect[k].img =img_eff_bomb[2];
effect[k].x =70;
effect[k].y =300;
}
if((k=effect_search())!=-1){
effect[k].flag =1;
effect[k].cnt =0;
effect[k].knd =3;//ボムの線のエフェクト
effect[k].brt =0;
effect[k].ang =0;
effect[k].mvang=0;
effect[k].spd =1;
effect[k].r =1;
effect[k].eff =2;
effect[k].img =img_eff_bomb[2];
effect[k].x =100;
effect[k].y =350;
}
if((k=effect_search())!=-1){
effect[k].flag =1;
effect[k].cnt =0;
effect[k].knd =2;//立ち絵
effect[k].brt =0;
effect[k].ang =0;
effect[k].mvang=-PI/2;
effect[k].spd =0.7;
effect[k].r =1;
effect[k].eff =2;
effect[k].img =img_eff_bomb[3];
effect[k].x =260;
effect[k].y =300;
}
}
void effect_bomb_calc(){
int n,k,shot_angle[4]={0,PI,PI/2,PI*1.5};//4発エフェクトが飛ぶ角度
if(Player.flag==0 && bomb.flag==0){//キャラが通常状態で、ボムがオフなら
if(CheckStatePad(configpad.bomb)==1 || CheckHitKey(KEY_INPUT_X)==1){//ボムボタンが押されたら
effect_enter_bomb();
}
}
if(bomb.flag==1){//ボムが登録されていたら
if(bomb.cnt%10==0){//1/6秒に1回
n=(bomb.cnt/10);
if(n<4 && (k=effect_search())!=-1){
effect[k].flag=1;
effect[k].cnt=0;
effect[k].knd=1;//エフェクト番号1:ボムのエフェクト
effect[k].brt=0;
effect[k].ang=rang(PI);//画像の向きはランダム
effect[k].mvang=shot_angle[n]-PI/4;//飛ぶ方向
effect[k].spd=13+rang(2);//スピード
effect[k].r=0.5;//大きさ
effect[k].eff=2;//αブレンド
effect[k].img=img_eff_bomb[(bomb.cnt/10)/3];//画像
effect[k].x=Player.x;//座標
effect[k].y=Player.y;
}
}
bomb.cnt++;
if(bomb.cnt<40){
bright_set.brt=255-bomb.cnt*5;//画面の明るさ設定(暗く)
}
if(bomb.cnt>90){
bright_set.brt=255-40*5+(bomb.cnt-90)*5;//画面の明るさ設定(明るく)
}
if(bomb.cnt>300){
bomb.flag=0;
bright_set.brt=255;
}
}
}
void dn_calc(){
if(dn.flag==1){
dn.x=(int)rang(dn.size);
dn.y=(int)rang(dn.size);
dn.cnt++;
if(dn.cnt>dn.time){
dn.flag=0;
dn.x=0;
dn.y=0;
}
}
}
void effect_main(){
dn_calc();
effect_deth_calc();
effect_calc();
effect_bomb_calc();
}
void effect_main(){
dn_calc();
effect_deth_calc();
effect_calc();
effect_bomb_calc();
}
void effect_main(){
dn_calc();
effect_deth_calc();
effect_calc();
effect_bomb_calc();
}
#include "DxLib.h"
#include "graph.h"
#include "struct.h"
#include "player.h"
#include "effect.h"
#include "Enemy.h"
#include "common.h"
static int img_board[4];//ボード
static int img_back[5]; //背景。stage5まで
static int i=0;
void graph_load(){
img_board[0] = LoadGraph("dat/board/front_00.png");
img_board[1] = LoadGraph("dat/board/front_01.png");
img_board[2] = LoadGraph("dat/board/front_02.png");
img_board[3] = LoadGraph("dat/board/front_03.png");
img_back[0] = LoadGraph("dat/board/back0.png");
/*---------------------------------------
img_back[1] = LoadGraph("dat/board/");
img_back[2] = LoadGraph("dat/board/");
img_back[3] = LoadGraph("dat/board/");
img_back[4] = LoadGraph("dat/board/");
---------------------------------------*/
bright_set.brt=255;
}
void graph_and_effect_load_main(){
graph_load();
effect_load_and_ini();
}
void graph_draw_board(){
DrawGraph( 0, 0,img_board[2],FALSE);
DrawGraph( 0, 16,img_board[1],FALSE);
DrawGraph( 0,464,img_board[2],FALSE);
DrawGraph(416, 0,img_board[3],FALSE);
}
void graph_draw_back(){
SetDrawArea( 32 , 16 , 416 , 464 ) ;//描画可能エリアを設定
DrawGraph(32,i%700-700,img_back[0],false);
DrawGraph(32,i%700,img_back[0],false);
SetDrawArea( 0, 0, 640, 480);//エリアを戻す
i++;
}
void graph_main(){
if(bright_set.brt!=255)SetDrawBright(bright_set.brt,bright_set.brt,bright_set.brt);
graph_back_main();//背景描画メイン
effect_graph(0);//敵が死ぬエフェクト
Enemy_Draw();//敵の描画
player_shot_draw();//自機ショットの描画
if(bright_set.brt!=255)SetDrawBright(255,255,255);
player_draw();//自機の描画
if(bright_set.brt!=255)SetDrawBright(bright_set.brt,bright_set.brt,bright_set.brt);
//此処に弾の画像の関数を入れる
if(bright_set.brt!=255)SetDrawBright(255,255,255);
effect_graph(1); //ボムのエフェクト
effect_graph(2); //ボム線のエフェクト
effect_graph(3); //ボムキャラのエフェクト
graph_draw_board(); //ボードの描画
player_board(); //スコアとかの文字表示
}
新・C言語 ~ゲームプログラミングの館~ で、グローバル変数は使わない方が良い、と知ったので、使わないように
しました。そちらの方も何か問題が有りましたら教えて頂けるとありがたいです。
ソースコードは相変わらず汚いですが、ご教授の方宜しくお願いします。
ちなみに、エラーは出ませんでした。