Frontier-of-Hell/scripts/bullets/bullet.gd

45 lines
972 B
GDScript3
Raw Normal View History

2023-10-06 11:40:11 +02:00
extends Area2D
2023-10-16 19:12:44 +02:00
2023-10-06 11:40:11 +02:00
const right = Vector2.RIGHT
2023-10-20 19:59:00 +02:00
var speed: int = 0
var damage: int = 0
2023-10-16 19:12:44 +02:00
var dir = 0
2023-10-20 19:59:00 +02:00
var area_damage: bool = false
2023-10-20 20:52:37 +02:00
var slow_effect: bool = false
2023-10-16 19:12:44 +02:00
2023-12-05 16:29:34 +01:00
var enemies = []
var stop: bool = false
2023-10-18 06:10:07 +02:00
func _physics_process(_delta):
2023-12-05 16:29:34 +01:00
if stop:
return
2023-10-16 19:12:44 +02:00
var move_dir = Vector2(1,0).rotated(dir)
global_position += (move_dir * speed)
2023-10-06 11:40:11 +02:00
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
func _on_Bullet_body_entered(body):
if body.is_in_group("Enemy"):
2023-10-20 19:59:00 +02:00
if area_damage:
2023-12-05 16:29:34 +01:00
$Sprite2D.hide()
stop = true
$AnimatedSprite2D.visible = true
$AnimatedSprite2D.play("default")
for enemy in enemies:
2023-10-20 19:59:00 +02:00
enemy.hit(damage)
2023-12-05 16:29:34 +01:00
await get_tree().create_timer(1).timeout
2023-10-20 20:52:37 +02:00
elif slow_effect:
body.get_parent().hit(damage)
body.get_parent().slow()
2023-10-20 19:59:00 +02:00
else:
body.get_parent().hit(damage)
2023-10-06 11:40:11 +02:00
queue_free()
2023-12-05 16:29:34 +01:00
func _on_body_entered(body):
if body.is_in_group("Enemy"):
enemies.append(body.get_parent())
func _on_body_exited(body):
enemies.erase(body.get_parent())