인스턴스 건강 표시 그리기 (Draw Instance Health)
이 문서에서는 게임 제작에서 인스턴스의 건강(health)을 시각적으로 표현하기 위한 방법에 대해 설명합니다. 이 기능을 사용하면 "health" 액션을 통해 인스턴스에 새로운 범위 변수를 추가할 수 있으며, 건강 상태를 알려주는 색깔의 바를 그릴 수 있습니다. 이 건강 바는 0에서 100까지의 퍼센트 값을 표시합니다.
건강 바를 그릴 때 설정할 수 있는 여러 가지 옵션이 있습니다. 방향(왼쪽에서 오른쪽, 위에서 아래 등), 위치(룸 내에서의 위치 또는 액션 호출 인스턴스에 상대적인 위치), 그리고 각 모서리에서 혼합할 색상(예: 빨간색에서 초록색) 등을 설정할 수 있습니다.
액션 문법
health_draw(x, y, width, height, background_color, outline_color, min_color, max_color);
매개변수 설명
| 매개변수 | 설명 |
|---|---|
| Direction | 건강 바 내용 그리기 방향 |
| Left | 건강 바의 왼쪽 위치 |
| Top | 건강 바의 상단 위치 |
| Right | 건강 바의 오른쪽 위치 |
| Bottom | 건강 바의 하단 위치 |
| Background | 건강 바의 배경 색상 |
| Outline | 건강 바의 외곽선 색상 |
| Min Colour | 최소값에서 혼합할 색상 |
| Max Colour | 최대값에서 혼합할 색상 |
예제
아래의 코드는 화면 좌측 상단에 건강 바를 그리는 예제입니다.
// 건강 바 그리기 예제
var health = 80; // 건강 상태 (0~100)
var max_health = 100; // 최대 건강 상태
// 건강 바 색상 설정
var background_color = c_black;
var outline_color = c_white;
var min_color = c_red;
var max_color = c_green;
// 건강 바 그리기
health_draw(10, 10, 100, 20, background_color, outline_color, min_color, max_color);
이 코드는 좌측 상단에 100의 폭을 가진 건강 바를 그리며, 현재 건강이 80%인 경우 색상이 빨강에서 초록으로 변화합니다.
다양한 활용 및 응용 예제
1. 플레이어 건강 바
// 플레이어의 건강바
if (instance_exists(player)) {
health = player.health; // 플레이어 건강 상태
max_health = player.max_health; // 최대 플레이어 건강 상태
health_draw(10, 10, 200 * (health / max_health), 20, c_black, c_white, c_red, c_green);
}
2. 적 캐릭터의 건강 바
// 적 캐릭터 건강바
if (instance_exists(enemy)) {
health = enemy.health;
max_health = enemy.max_health;
health_draw(enemy.x - 30, enemy.y - 20, 200 * (health / max_health), 10, c_black, c_white, c_red, c_green);
}
3. 팀원 건강 바
// 팀원 건강바 그리기
var team_members = [player1, player2, player3];
var offset = 10;
for (var i = 0; i < array_length(team_members); i++) {
var member = team_members[i];
if (instance_exists(member)) {
health = member.health;
max_health = member.max_health;
health_draw(10, offset + (i * 30), 200 * (health / max_health), 20, c_black, c_white, c_red, c_green);
}
}
이러한 방법들을 통해 게임 내에서 다양한 인스턴스의 건강 상태를 시각적으로 효과적으로 표현할 수 있습니다.