[UE5] ๐Ÿš€ Project Galaga (4)

Singery00ยท2024๋…„ 5์›” 21์ผ
0

Project Galaga

๋ชฉ๋ก ๋ณด๊ธฐ
4/15
post-thumbnail

๊ฐœ์š”

๐Ÿš€ Project Galaga ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

Unreal C++๊ณผ ๊ฒŒ์ž„์ˆ˜ํ•™์„ ์ ‘๋ชฉํ•ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

2024.05.04 ~ 2024.05.21์˜ ๊ฐœ๋ฐœ ๊ธฐ๊ฐ„์œผ๋กœ, ์ด 17์ผ ๋™์•ˆ ๊ฐœ๋ฐœ์„ ์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๊ฑฐ์ฐฝํ•˜๊ฒŒ ์‹œ์ž‘ํ•œ ํ”„๋กœ์ ํŠธ๋ณด๋‹จ ์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์šด ๊ฒƒ๋“ค์„ ์ข…ํ•ฉ์ ์œผ๋กœ ์‚ฌ์šฉํ•ด์„œ ๊ฒฐ๊ณผ๋ฌผ์„ ๋งŒ๋“ค์–ด ๋‚ด๋ณด๊ฒ ๋‹ค๋Š” ๋งˆ์Œ์œผ๋กœ ์™„์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.

ํ•ด๋‹น ์‹œ๋ฆฌ์ฆˆ์—๋Š” ๊ฐœ๋ฐœ ์ผ์ง€๋ฅผ ์ •๋ฆฌํ•˜๋ฉฐ, ๊ฐœ๋ฐœ ๋‚ด์šฉ์— ๋Œ€ํ•œ ์„ค๋ช…๊ณผ ์ด์Šˆ๋ฅผ ์ •๋ฆฌํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

๐Ÿš€ Project Galaga Github Repository


๋ณธ๋ก 


์  ์ œ์ž‘

์ด๋ฒˆ์—๋Š” ์ ์— ๋Œ€ํ•ด์„œ ๊ตฌํ˜„ํ•œ ์‚ฌํ•ญ์ž…๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋‚ด์šฉ์ด ๊ฐ€์žฅ ๊ฐœ๋ฐœ์— ์žˆ์–ด์„œ ๊ฐ€์žฅ ํฐ ์š”์†Œ๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ ์˜ ์™ธํ˜•๊ณผ ์ถฉ๋Œ์€ ํ”Œ๋ ˆ์ด์–ด์™€๋Š” ๋ฐ˜๋Œ€๋กœ Overlap์œผ๋กœ ๊ตฌํ˜„ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

์ ์€ ๋ฒฝ ๋ฐ–์—์„œ ์ด๋™ํ•˜์—ฌ ๋“ค์–ด์™€์•ผํ•˜๊ณ , ํ”Œ๋ ˆ์ด์–ด์™€ ์ถฉ๋Œ ์‹œ Overlap Event๋ฅผ ๋ฐœ์ƒํ•˜์—ฌ ๋ฐ๋ฏธ์ง€๋ฅผ ์ฃผ์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.


์  ๊ตฌ์กฐ

์ ์€ ํฌ๊ฒŒ 3๊ฐ€์ง€์˜ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

  1. ์›€์ง์ž„ ํŒจํ„ด
UENUM(BlueprintType)
enum class EEnemyType : uint8
{
	Suiside,
	Patrol,
	Fixed,
	PassBy,
	Random,
	InOut,
};
  1. ๊ณต๊ฒฉ ํŒจํ„ด
UENUM(BlueprintType)
enum class EEnemyAttackType : uint8
{
	Suiside,
	Front,
	Target,
	Spread,
	Orbit,
	Laser,
	Wave,
	Angle,
};
  1. ํฌ์ปค์Šค
UENUM(BlueprintType)
enum class EEnemyFocus : uint8
{
	Player,
	TargetMP,
	Front,
	Back,
	Center,
	PlayerOnce,
};

๊ฐ ํŒจํ„ด๋“ค์€ Enum Class๋กœ ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์œ„ ์š”์†Œ์™€ ์ฒด๋ ฅ, ๊ณต๊ฒฉ์†๋„, ์ด๋™์†๋„ ๋“ฑ์˜ ์š”์†Œ๋ฅผ EnemyStat์˜ ์นดํ…Œ๊ณ ๋ฆฌ๋กœ ๋ฌถ์–ด ๊ฐ’์„ ๋„ฃ์–ด์ค„ ์ˆ˜ ์žˆ๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.


FSM

์ ์€ ์œ ํ•œ ์ƒํƒœ ๊ธฐ๊ณ„๋ฅผ ๊ฐ€์ ธ ์„ค์ •๋œ Stat์— ๋”ฐ๋ผ์„œ ํŒจํ„ด์ด ์ง„ํ–‰๋˜๋„๋ก ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

Enemy FSM์„ ์•กํ„ฐ ์ปดํฌ๋„ŒํŠธ๋กœ ์ œ์ž‘ํ•˜์—ฌ ๊ฐ ์ƒํƒœ๋งˆ๋‹ค Switch๋ฅผ ํ†ตํ•ด ํŒจํ„ด ํ•จ์ˆ˜๊ฐ€ ๋™์ž‘ํ•˜๋„๋ก ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

AEnemyBase::AEnemyBase()
{
	fsm = CreateDefaultSubobject<UEnemyFSM>(TEXT("FSM"));
}

์–ด๋–ค ์ƒํƒœ์ธ์ง€์— ๋”ฐ๋ผ ๊ฐ State ์‹คํ–‰ํ•จ์ˆ˜๋กœ ๋„˜์–ด ๊ฐ€๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

void UEnemyFSM::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

		switch (mState)
		{
		case EEnemyState::IDLE:
			IdleState();
			break;
		case EEnemyState::MOVE:
			MoveState();
			break;
		case EEnemyState::ATTACK:
			AttackState();
			break;
		case EEnemyState::DIE:
			DieState();
			break;
		default:
			break;
		}
	}
}

์–ด๋–ค ์›€์ง์ž„ ํŒจํ„ด์„ ๊ฐ€์กŒ๋Š”์ง€์— ๋”ฐ๋ผ ๊ฐ ์›€์ง์ž„ ํŒจํ„ด ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

void UEnemyFSM::MoveState()
{

	switch (me->GetMType())
	{
	case EEnemyType::Suiside:
		SuisideMove();
		break;
	case EEnemyType::Patrol:
		PatrolMove();
		break;
	case EEnemyType::Fixed:
		FixedMove();
		break;
	case EEnemyType::PassBy:
		PassByMove();
		break;
	case EEnemyType::Random:
		RandomMove();
		break;
	case EEnemyType::InOut:
		InOutMove();
		break;
	default:
		break;
	}

	if (currentTime >= me->GetEnemyAttackSpeed())
	{
		SetAttackState();
	}
}

์–ด๋–ค ๊ณต๊ฒฉ ํŒจํ„ด์„ ๊ฐ€์กŒ๋Š”์ง€์— ๋”ฐ๋ผ ๊ฐ ๊ณต๊ฒฉ ํŒจํ„ด ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

void UEnemyFSM::AttackState()
{
	me->FireSound();
	switch (me->GetMAttackType())
	{
	case EEnemyAttackType::Suiside:
		SetMoveState();
		break;
	case EEnemyAttackType::Front:
		FrontAttack();
		break;
	case EEnemyAttackType::Target:
		TargetAttack();
		break;
	case EEnemyAttackType::Spread:
		SpreadAttack();
		break;
	case EEnemyAttackType::Orbit:
		OrbitAttack();
		break;
	case EEnemyAttackType::Laser:
		me->laserEffect();
		me->GetWorldTimerManager().SetTimer(LaserTimer, this, &UEnemyFSM::LaserAttack, 2.0f, false);
		break;
	case EEnemyAttackType::Wave:
		WaveAttack();
		break;
	case EEnemyAttackType::Angle:
		AngleAttack();
	default:
		break;
	}

	SetMoveState();
	currentTime = 0.0f;
}

๋งˆ๋ฌด๋ฆฌ

์—ฌ๊ธฐ๊นŒ์ง€ ์  ๊ตฌํ˜„์— ๋Œ€ํ•œ ๊ฐœ์š”์ž…๋‹ˆ๋‹ค.
์›€์ง์ž„ ํŒจํ„ด, ๊ณต๊ฒฉ ํŒจํ„ด, ํฌ์ปค์Šค์— ๋Œ€ํ•ด์„œ ๋”ฐ๋กœ ํฌ์ŠคํŒ…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

profile
๊ฒŒ์ž„ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋˜์–ด๋ณด์ž

0๊ฐœ์˜ ๋Œ“๊ธ€