ZK01.cpp

[関数 | マクロ]

関数一覧

マクロ一覧


   1|//@STATE=作成中
   2|//@DESCRIPTION ---------------------------------------------------------------
   3|// ZK01.cpp: ZK01 クラスのインプリメンテーション
   4|//	履歴:
   5|// $Log: ZK01.cpp,v $
   6|// Revision 1.8  2001/07/01 21:30:34  fujiwara
   7|// メモリリークチェック見直し
   8|//
   9|// Revision 1.7  2001/07/01 01:03:45  fujiwara
  10|// const の見直し
  11|// 配置エディタは途中経過
  12|//
  13|// Revision 1.6  2001/06/03 09:22:32  fujiwara
  14|// 地上敵クラスおよび雑魚敵の微調整
  15|//
  16|// Revision 1.5  2001/05/29 01:12:10  fujiwara
  17|// 雑魚キャラ(飛行物)の作成。配置エディタのバグ修正
  18|//
  19|// Revision 1.4  2001/05/17 12:31:29  fujiwara
  20|// 地上敵サンプル作成
  21|//
  22|// Revision 1.3  2001/05/13 20:04:24  fujiwara
  23|// メモリーリークが発生したので取り除く。
  24|// 自弾のサウンドテスト
  25|//
  26|// Revision 1.2  2001/05/12 00:48:35  fujiwara
  27|// CVSを導入し、ログ表示を追加
  28|//
  29|//@DESCRIPTION_END -----------------------------------------------------------
  30|//@AUTHOR=S.F.
  31|// Copyright (C) 2000 Satoshi Fujiwara. All Rights Reserved.
  32|///////////////////////////////////////////////////////////////////////////////
  33|#pragma warning( disable : 4786 )	//STLの警告外し
  34|
  35|// メモリーリーク検出用
  36|#include "sfdebug.h"
  37|
  38|#include <string>
  39|#include <vector>
  40|#include <memory>
  41|#include <stack>
  42|#include <list>
  43|#include <iostream>
  44|#include <fstream>
  45|#include <map>
  46|
  47|#include "stdio.h"
  48|#include "math.h"
  49|
  50|#include "singleton.h"
  51|#include "system.h"
  52|#include "console.h"
  53|#include "input.h"
  54|#include "sound.h"
  55|
  56|#include "Obj.h"
  57|#include "Obj2D.h"
  58|#include "Obj3D.h"
  59|#include "Obj3DL.h"
  60|#include "ObjRectangle.h"
  61|#include "ObjQuadrangle.h"
  62|
  63|#include "Background.h"
  64|#include "Scene.h"
  65|#include "main.h"
  66|
  67|#include "character.h"
  68|#include "Hit.h"
  69|#include "MyShip.h"
  70|#include "Game.h"
  71|#include "Enemys.h"
  72|#include "Armys.h"
  73|#include "AbstractEnemy.h"
  74|#include "EnemyBullets.h"
  75|#include "DispositionControl.h"
  76|#include "Effects.h"
  77|#include "Explosion.h"
  78|
  79|#ifdef _DEBUG
  80|#define new DEBUG_NEW
  81|#endif
  82|
  83|#include "ZK01.h"
  84|#include "EB01.h"
  85|
  86|using namespace sf::application;
  87|using namespace sf::application::enemy;
  88|
  89|sf::system::console::sprite::PSprite ZK01::mspSprite;
  90|
  91|int ZK01::mBalletTimer = 0;
  92|int ZK01::mBalletTimerInit = 0;
  93|
  94|const sf::system::console::sprite::Info ZK01::msSpriteInfo = 
  95|{
  96|	"media\\zk01.png",0.0f,0.0f,64.0f,64.0f,0xff000000,console::sprite::SPRITE2D
  97|};
  98|
  99|const int ZK01::SCORE = 20;
 100|
 101|// コンストラクタ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−
 102|ZK01::ZK01()
 103|{
 104|}// ZK01()
 105|
 106|// デストラクタ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
 107|ZK01::~ZK01()
 108|{
 109|	Enemys::instance()->clear(index());
 110|}// ~ZK01()
 111|
 112|
 113|// 初期化 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
 114|const bool ZK01::initialize()
 115|{
 116|	// 当り判定 
 117|	mHitRect.offsetTop(-24.0f);
 118|	mHitRect.offsetBottom(24.0f);
 119|	mHitRect.offsetLeft(-24.0f);
 120|	mHitRect.offsetRight(24.0f);
 121|
 122|	mHitRect.isChecking(true);
 123|	mHitRect.characterPtr(this);
 124|	direction((float)atan2((double)(game()->player()->y() - y()),(double)(game()->player()->x() - x())));
 125|	
 126| 	mDeltaTime = sf::system::Factory::getInstance()->deltaTime();
 127|	mDeltaTimeRev = 1.0f / mDeltaTime;
 128|	speed(3.0f * mDeltaTime);
 129|
 130|	mDx = cosf(direction()) * speed();
 131|	mDy = sinf(direction()) * speed();
 132|	
 133|	// Body 部分 
 134|	mObj.index(0);
 135|
 136|	if(!mspSprite.get())
 137|		load();
 138|
 139|	mObj.sprite(mspSprite.get());
 140|	
 141|	mObj.z(z() + (float)index() * 0.0001f );
 142|	mObj.x(x());
 143|	mObj.y(y());
 144|	mObj.visibility(true);
 145|	mObj.color(0xffffffff);
 146|	mObj.drawMode(sf::system::console::DRAW_TRANS);
 147|	mObj.angle(direction());
 148|
 149|	// Light部分
 150|	mObjLight.z(z() + (float)index() * 0.0001f + 0.00001f);
 151|	mObjLight.x(x());
 152|	mObjLight.y(y());
 153|
 154|	initLight();
 155|	
 156|	mbHit = false;
 157|	mDirCount = 18.0f * mDeltaTime;
 158|	mDirSpeed = (rand() & 1) ? -0.02f * mDeltaTime : 0.02f * mDeltaTime;
 159|	
 160|	mState = MOVE;
 161|	
 162|	mShootTimer = (int)((20.0f + (float)(rand() & 0x7)) * mDeltaTimeRev);
 163|	mbShoot = false;
 164|	mAccel = 0.2f * mDeltaTime;
 165|
 166|	if(!mBalletTimerInit)
 167|	{
 168|		mBalletTimer = mBalletTimerInit = (3.0f - game()->currentDifficulty()) * mDeltaTimeRev;
 169|		mbShoot = false;
 170|	} else {
 171|		mBalletTimer--;
 172|		if(!mBalletTimer){
 173|			mBalletTimer = mBalletTimerInit;
 174|			mBalletTimerInit = (3.0f - game()->currentDifficulty()) * mDeltaTimeRev;
 175|			mbShoot = false;
 176|		} else {
 177|			mbShoot = true;
 178|		}
 179|	}
 180|
 181|	return true;
 182|}// initialize()
 183|
 184|// テクスチャのロード −−−−−−−−−−−−−−−−−−−−−−−−−−−
 185|const bool ZK01::load(void){
 186|	using namespace sf::system::console::sprite;
 187|	if(!mspSprite.get()){
 188|		sf::system::console::sprite::PSprite ptemp(sf::system::Factory::getInstance()->console()->createSprite(&msSpriteInfo)); 
 189|		if(ptemp.get() == NULL)
 190|			return false;
 191|		mspSprite = ptemp;
 192|	}
 193|
 194|	if(!Bullets::instance()->load(Bullets::EB01))
 195|		return false;
 196|	
 197|	if(!AbstractEnemy::loadLight())
 198|		return false;
 199|
 200|	return true;
 201|}// load()
 202|
 203|// テクスチャのアンロード −−−−−−−−−−−−−−−−−−−−−−−−−
 204|void ZK01::unload(void){
 205|	using namespace sf::system::console::sprite;
 206|	PSprite ptmp(NULL);
 207|	mspSprite = ptmp;
 208|}// unload()
 209|
 210|// 敵の動作 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
 211|void ZK01::move()
 212|{
 213|	using namespace sf::application;
 214|	float tx,ty;
 215|
 216|	y(y() + mDy);
 217|	x(x() + mDx);
 218|
 219|	switch(mState){
 220|	case MOVE:
 221|		// 動きのメイン
 222|		if(!--mDirCount){
 223|			mDirCount = (int)(2.0f * mDeltaTimeRev);
 224|			direction(direction() + mDirSpeed);
 225|			speed(speed() + mAccel);
 226|			mDx = cosf(direction()) * speed();
 227|			mDy = sinf(direction()) * speed();
 228|		}
 229|
 230|		// 座標位置、角度の設定		
 231|		mObj.x(x());
 232|		mObj.y(y());
 233|		mObj.angle(direction());
 234|
 235|		mObjLight.x(x());
 236|		mObjLight.y(y());
 237|		moveLight();
 238|		
 239|		// 弾発射 
 240|		if(!mbShoot){
 241|			if(!(mShootTimer--) ){
 242|				tx = x() + 20.0f * cosf(direction());
 243|				ty = y() + 20.0f * sinf(direction());
 244|				EB01 *peb = (EB01 *)Bullets::instance()->create(Bullets::EB01,tx,ty,z() + 0.01f,game());
 245|				peb->direction(Util::calcDirection(x(),y(),game()->player()->x(),game()->player()->y()));
 246|				mbShoot = true;
 247|			}
 248|		}
 249|		
 250|		// 弾にあたったかどうかの判定
 251|		if(mbHit)
 252|		{
 253|			die();
 254|			return;
 255|		}
 256|		break;// case MOVE:
 257|
 258|	case DEAD:
 259|		if(!--mDirCount){
 260|			delete this;
 261|			return;
 262|		}
 263|		mObj.x(x());
 264|		mObj.y(y());
 265|		break;
 266|	}
 267|
 268|	// 画面消去判定
 269|	if(Util::checkArea(x(),y(),64.0f,64.0f))
 270|		delete this;
 271|}//move()
 272|
 273|
 274|
 275|// 弾にあたったときの処理 −−−−−−−−−−−−−−−−−−−−−−−−−
 276|void ZK01::hit(Character * const pDest)
 277|{
 278|	mHitRect.isChecking(false);
 279|	mbHit = true;
 280|
 281|};
 282|
 283|// 敵の生成 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
 284|sf::application::Character * const ZK01::create(float x,float y ,float z,sf::application::scene::Game * const pGame,int index)
 285|{
 286|	ZK01 * ptemp = new ZK01;
 287|	ptemp->x(x);
 288|	ptemp->y(y);
 289|	ptemp->z(z);
 290|	ptemp->index(index);
 291|	ptemp->game(pGame);
 292|	ptemp->initialize();
 293|	return ptemp;
 294|;}// create
 295|
 296|// 死んだときの処理  −−−−−−−−−−−−−−−−−−−−−−−−−−−
 297|void ZK01::die(void)
 298|{
 299|	effect::Explosion *pExp = (effect::Explosion*)effect::Effects::instance()->create(effect::Effects::EXPLOSION,x(),y(),0.1f,game(),this);
 300|	if(pExp){
 301|		pExp->scaling(1.5f);
 302|	}
 303|	mDirCount = 2;
 304|	mState = DEAD;
 305|	game()->score(game()->score() + SCORE);
 306|
 307|};// die()
 308|
 309|//  全爆発イベント −−−−−−−−−−−−−−−−−−−−−−−−−−−−
 310|void ZK01::allBomb(void)
 311|{
 312|	die();
 313|}// allBomb()