//@STATE=嶌惉拞
//@DESCRIPTION ---------------------------------------------------------------
// Explosion.cpp: Explosion 僋儔僗偺僀儞僾儕儊儞僥乕僔儑儞
//	棜楌丗
// $Log: Explosion.cpp,v $
// Revision 1.1  2001/10/28 21:40:36  fujiwara
// DLL偵暘妱
//
// Revision 1.6  2001/07/09 20:30:08  fujiwara
// 椺奜張棟偺慻傒崬傒
//
// Revision 1.5  2001/07/01 21:30:33  fujiwara
// 儊儌儕儕乕僋僠僃僢僋尒捈偟
//
// Revision 1.4  2001/07/01 01:03:44  fujiwara
// const 偺尒捈偟
// 攝抲僄僨傿僞偼搑拞宱夁
//
// Revision 1.3  2001/05/17 12:34:10  fujiwara
// 抧忋揋僒儞僾儖嶌惉
//
// Revision 1.2  2001/05/12 00:50:33  fujiwara
// 俠倁俽傪摫擖偟丄儘僌昞帵傪捛壛
//
//@DESCRIPTION_END -----------------------------------------------------------
//@AUTHOR=S.F.
// Copyright (C) 2000 Satoshi Fujiwara. All Rights Reserved.
///////////////////////////////////////////////////////////////////////////////
#pragma warning( disable : 4786 )	//STL偺寈崘奜偟

// 儊儌儕乕儕乕僋専弌梡
#include "sfdebug.h"

#include <string>
#include <vector>
#include <memory>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <map>
#include "stdio.h"
#include "math.h"

#include "exception.h"
#include "singleton.h"
#include "system.h"
#include "console.h"
#include "input.h"
#include "sound.h"

#include "Obj.h"
#include "Obj2D.h"
#include "Obj3D.h"
#include "Obj3DL.h"
#include "ObjRectangle.h"
#include "ObjQuadrangle.h"

#include "Background.h"
#include "Scene.h"
#include "main.h"

#include "character.h"
#include "Hit.h"
#include "MyShip.h"
#include "Game.h"
#include "Enemys.h"
#include "Armys.h"
#include "DispositionControl.h"
#include "Effects.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include "Explosion.h"

using namespace sf::application;
using namespace sf::application::effect;

sf::system::console::sprite::PSprite Explosion::mspSprite[MAX_EXPLOSION];
int Explosion::msSoundID = 0;

const sf::system::console::sprite::Info Explosion::msSpriteInfo[MAX_EXPLOSION] = 
{
	{"media\\explosion.png",0.0f,0.0f,64.0f,64.0f,0xff000000,console::sprite::SPRITE2D},
	{"media\\explosion2.png",0.0f,0.0f,64.0f,64.0f,0xff000000,console::sprite::SPRITE2D},
};



// 僐儞僗僩儔僋僞 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
Explosion::Explosion()
{

}// Explosion()

// 僨僗僩儔僋僞 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
Explosion::~Explosion()
{
	Effects::instance()->clear(index());
}// ~Explosion()


// 弶婜壔 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void Explosion::initialize()
{
	// 摉傝敾掕 
/*
	mHitRect.offsetTop(-24.0f);
	mHitRect.offsetBottom(24.0f);
	mHitRect.offsetLeft(-24.0f);
	mHitRect.offsetRight(24.0f);
*/
	mHitRect.isChecking(false);
	mHitRect.characterPtr(this);
	mScaling = 1.0f;

	mObj.scalingX(mScaling);
	mObj.scalingY(mScaling);

/*	mRadian = (float)atan2((double)(game()->player()->y() - y()),(double)(game()->player()->x() - x()));
	
	
	mSpeed = 6.0f;
*/
	mDx = cosf(direction()) * speed();
	mDy = sinf(direction()) * speed();
	
	mObj.index(0);
	mObj.sprite(mspSprite[rand() & 0x1].get());
	
	mObj.z(z());
	mObj.x(x());
	mObj.y(y());
	mObj.visibility(true);
	mObj.color(0xF0ffffff);
	mObj.drawMode(sf::system::console::DRAW_ADD);
	mObj.angle(direction());
	mObj.reverseX(rand() & 0x1?true:false);
	mObj.reverseY(rand() & 0x1?true:false);

	mbHit = false;
//	mDirCount = 24;
//	mDirSpeed = (rand() & 1) ? -0.01 : 0.01;
	sf::system::instance()->sound()->play(msSoundID,1,false,false);
}// initialize()

// 僥僋僗僠儍偺儘乕僪 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void Explosion::load(void){
	using namespace sf::system::console::sprite;
	PSprite *ptemp;
	int i;

	if(!mspSprite[0].get()){
		for(i = 0;i < MAX_EXPLOSION;i++){
			ptemp = new PSprite(sf::system::instance()->console()->createSprite(&msSpriteInfo[i])); 
			mspSprite[i] = *ptemp;
			delete ptemp;
		}
	}

	// 僒僂儞僪僨乕僞偺儘乕僪 
	msSoundID = sf::system::instance()->sound()->load("explos.wav");
}// load()

// 揋偺摦嶌 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void Explosion::move()
{
	mCount++;	
	y(y() + mDy);
	x(x() + mDx);
	mObj.x(x());
	mObj.y(y());
	mObj.index(mObj.index() + (mCount & 1));
	
	if(mObj.index() > 15){
		delete this;
		return;
	}
}//move()

void Explosion::hit(Character * const pDest)
{
//	mHitRect.isChecking(false);
//	mbHit = true;
};

// 揋偺惗惉 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
sf::application::Character * const Explosion::create(float x,float y ,float z,sf::application::scene::Game * const pGame,Character *pCharacter,int index)
{
	Explosion * ptemp = new Explosion;
	ptemp->x(x);
	ptemp->y(y);
	ptemp->z(z);
	ptemp->index(index);
	ptemp->game(pGame);
	ptemp->speed(pCharacter->speed());
	ptemp->direction(pCharacter->direction());
	ptemp->initialize();
	return ptemp;
;}// create

