Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
39 changes: 34 additions & 5 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,17 +21,45 @@ 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:
damage_enemy(body)
damage_player(body)
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 precisamos ter duas funções distintas? não da para unificar em apenas uma única função?

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

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"):
		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()`



## Aplica dano ao Player somente se a mina estiver autorizada a atingi-lo.
## O dano é calculado com base na aceleração atual do Player,
## Após aplicar o dano, a mina explode.
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()


## Aplica dano a inimigos que implementam `take_damage`.
## O dano é calculado a partir da velocidade do corpo,
## Explode a mina após o impacto.
func damage_enemy(body: Node) -> void:
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.
func _explode() -> void:
func explode() -> void:
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 essa função é chamada fora desse script?

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.

Não, não é chamada fora do código. Resolvido

collision_shape.set_deferred("disabled", true)
set_deferred("monitoring", false)
vanish_timer.stop()
Expand All @@ -47,4 +76,4 @@ func _on_explosion_finished() -> void:


func _on_vanish_timer_timeout() -> void:
_explode()
explode()