5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

型判別

Posted at
Player.cpp

# include "Collision.h"

# include "Character.h"
	#include "Player.h"
	#include "Enemy0.h"
	#include "Enemy1.h"


void	Player::CharacterHitcheck( Character* character )
{

	if( typeid( *character ) == typeid( Enemy0 ) ){		//	Enemy0だったら
		if( this->collision.Box( character ) ){			//	四角の当たり判定
			this->hp -= 5;
		}
	}else if( typeid( *character ) == typeid( Enemy1 ) ){	//	Enemy1だったら
		if( this->collision.Circle( character ) ){			//	円形の当たり判定
			this->hp -= 10;
		}
	}

}

・「Enemy0」と「Enemy1」は「Character」の派生クラスであることが前提です。
・Playerには当たり判定用クラスを持たせています。Collisionクラス内で具体的な処理を記述しています。

「このオブジェクトは他と違う処理をさせたい」時に使うと便利かもしれないです。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?