Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scenes/game/bullet_3.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ animations = [{
radius = 49.0

[node name="Bullet_3" type="Area2D"]
collision_mask = 2
collision_mask = 3
script = ExtResource("1_8iyde")

[node name="MineSprite" type="Sprite2D" parent="."]
Expand Down
20 changes: 17 additions & 3 deletions scripts/game/bullet_3.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class_name Bullet3 extends Area2D
@onready var explosion_sound: AudioStreamPlayer2D = $AudioStreamPlayer2D

var lifetime_seconds: float = 3.0
var insta_kill_amount: float = 99999.0
var can_hit_player: bool = false
var damage : float = 0.0


## Inicializa o timer e configura a mina para começar ativa e monitorando colisões.
Expand All @@ -20,13 +21,26 @@ func _ready() -> void:
explosion_animation.hide()
if not vanish_timer.timeout.is_connected(_on_vanish_timer_timeout):
vanish_timer.timeout.connect(_on_vanish_timer_timeout)
await get_tree().create_timer(0.2).timeout
can_hit_player = true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iBerserker89 pq essa variavel é declarada como false para depois mudar para true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func damage_player(body: Node) -> void:
	if body is Player:
		if not can_hit_player:
			return
		damage = body.acceleration / 30.0
		if damage <= 10.0:
			damage = 10.0
		body.health -= damage
		explode()

A variável vira true após o timer de 0.2s no _ready (logo após a mina ser instanciada), pra que o player não tome dano no momento em que instancia a mina no mapa.



## Detecta colisão com um corpo e aplica dano.
func _on_body_entered(body: Node) -> void:
if body is Player:
if not can_hit_player:
return
damage = body.acceleration / 30.0
if damage <= 10.0:
damage = 10.0
body.health -= damage
if body.has_method("take_damage"):
body.take_damage(insta_kill_amount, 1.0)
_explode()
damage = body.velocity.length() / 7.0
if damage <= 10.0:
damage = 10.0
body.take_damage(damage, 1.0)
print("ASTEROID damaged: ", snapped(damage, 0.01))
_explode()


## Executa a animação e o som da explosão e desativa colisões.
Expand Down