-
Notifications
You must be signed in to change notification settings - Fork 0
A mina pode causar dano no player #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
27dff96
60a04c7
9ffdf12
180cd99
6f12511
cfb633e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
|
@@ -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 | ||
|
|
||
|
|
||
| ## Detecta colisão com um corpo e aplica dano. | ||
| func _on_body_entered(body: Node) -> void: | ||
| damage_enemy(body) | ||
| damage_player(body) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolvido |
||
|
|
||
|
|
||
| ## 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: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iBerserker89 essa função é chamada fora desse script?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
|
@@ -47,4 +76,4 @@ func _on_explosion_finished() -> void: | |
|
|
||
|
|
||
| func _on_vanish_timer_timeout() -> void: | ||
| _explode() | ||
| explode() | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.