spacegame/bullet/bullet.gd

24 lines
678 B
GDScript

extends RigidBody2D
class_name Bullet
var player : Player
@export var flash : PackedScene = preload("res://effects/flash.tscn")
var pref : int = 0
func _ready() -> void:
rotation = randf_range(0, 2*PI)
await get_tree().create_timer(0.05).timeout
apply_torque_impulse(randf_range(-100, 100))
func _integrate_forces(state) -> void:
pref += 1
if state.get_contact_count() > 0 && pref > 10:
pref = 0
var instance = flash.instantiate()
instance.global_position = state.get_contact_collider_position(0)
get_parent().add_child(instance)
func _on_body_entered(body: Node) -> void:
if body != Player and $animation.current_animation_position < 8:
$animation.seek(8)