Menu
CoddyTech

바위 쏘기

Coddy Godot 여정의 프로젝트 섹션에 포함된 레슨. 33개 중 15번째.

바위는 Area2D이고 총알은 물리 본체이므로, body_entered는 총알이 바위에 부딪혔을 때 바위에 알려 줍니다. 모든 총알은 bullets 그룹에 속합니다.

func _on_body_entered(body):
	if body.is_in_group("bullets"):
		body.queue_free()
		burst()
		queue_free()

총알도 제거하세요. 그렇지 않으면 총알이 계속 날아가 뒤에 있는 바위까지 부숩니다. burst()는 이미 rock.gd에 있습니다. 바위가 있던 자리에 먼지 구름을 일으킵니다. queue_free()보다 먼저 호출하세요.

challenge icon

챌린지

중급

rock.gd에서 _ready 안에 body_entered를 연결하세요. bullets 그룹에 속한 본체가 바위에 닿으면 총알을 제거하고, burst()를 호출한 다음 바위를 제거하세요.

직접 해보기

extends Area2D

var velocity = Vector2.ZERO

func _physics_process(delta):
	position += velocity * delta
	rotation += 0.5 * delta
	if position.x < -30:
		position.x += 700
	if position.x > 670:
		position.x -= 700
	if position.y < -30:
		position.y += 420
	if position.y > 390:
		position.y -= 420

# Bursts into dust where the rock is. Call it when the rock breaks.
func burst():
	var dust = CPUParticles2D.new()
	dust.position = position
	dust.one_shot = true
	dust.explosiveness = 1.0
	dust.amount = 20
	dust.lifetime = 0.7
	dust.spread = 180.0
	dust.gravity = Vector2.ZERO
	dust.initial_velocity_min = 30.0
	dust.initial_velocity_max = 120.0 * scale.x
	dust.scale_amount_min = 2.0
	dust.scale_amount_max = 5.0
	dust.color = Color(0.75, 0.82, 0.95)
	dust.finished.connect(dust.queue_free)
	get_parent().add_child(dust)
	dust.emitting = true
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

프로젝트의 모든 레슨

직접 연습해 보세요: Godot 플레이그라운드