Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 additions & 0 deletions scripts/game/bullet_3.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class_name Bullet3 extends Area2D

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


## Inicializa o timer e configura a mina para começar ativa e monitorando colisões.
Expand All @@ -20,10 +21,20 @@ 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.has_method("is_player"):
if not can_hit_player:
return
var damage = body.acceleration / 30.0
if damage <= 10.0:
damage = 10.0
body.health -= damage
_explode()
if body.has_method("take_damage"):
body.take_damage(insta_kill_amount, 1.0)
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 pelo que eu entendi a mina continua dando insta kill nos asteroids, acho que o melhor é ter uma função para calcular o dano e essa função ser utilizada tanto para o player qt para o inimigo

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.

Resolvido

_explode()
Expand Down