2023-01-14 22:51:05 -05:00
|
|
|
extends Area2D
|
|
|
|
|
2023-01-15 00:18:38 -05:00
|
|
|
@export var DAMAGE = 10;
|
|
|
|
@export var SPEED = 700;
|
2023-01-15 11:17:51 -05:00
|
|
|
@export var LIFETIME = 1.0;
|
|
|
|
@export var HANG_TIME = 0.0;
|
|
|
|
@export var FRICTION = 0.0;
|
2023-01-15 12:27:19 -05:00
|
|
|
@export var SIZE_MOD = 0.0;
|
2023-01-14 22:51:05 -05:00
|
|
|
|
2023-01-15 12:27:19 -05:00
|
|
|
@onready var sprite = $Sprite2D;
|
|
|
|
|
|
|
|
var rng = RandomNumberGenerator.new();
|
2023-01-15 11:17:51 -05:00
|
|
|
var is_hanging = false;
|
2023-01-14 22:51:05 -05:00
|
|
|
var velocity = Vector2.ZERO;
|
2023-01-15 11:17:51 -05:00
|
|
|
var time = 0.0;
|
2023-01-14 22:51:05 -05:00
|
|
|
|
2023-01-15 12:27:19 -05:00
|
|
|
func _ready():
|
|
|
|
var size_mod = rng.randf() * SIZE_MOD;
|
|
|
|
sprite.scale.x -= size_mod;
|
|
|
|
sprite.scale.y -= size_mod;
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-14 22:51:05 -05:00
|
|
|
func _process(delta):
|
2023-01-15 11:17:51 -05:00
|
|
|
|
|
|
|
if is_hanging :
|
|
|
|
velocity = velocity * FRICTION;
|
2023-01-14 22:51:05 -05:00
|
|
|
if velocity != Vector2.ZERO:
|
|
|
|
transform.origin += velocity * delta;
|
2023-01-15 11:17:51 -05:00
|
|
|
|
|
|
|
time += delta;
|
|
|
|
|
|
|
|
if time >= LIFETIME:
|
|
|
|
end_of_life();
|
|
|
|
if time >= LIFETIME + HANG_TIME:
|
|
|
|
explode();
|
2023-01-14 22:51:05 -05:00
|
|
|
|
2023-01-15 00:18:38 -05:00
|
|
|
func launch(direction, based_velocity):
|
|
|
|
velocity = based_velocity + direction * SPEED;
|
2023-01-14 22:51:05 -05:00
|
|
|
|
2023-01-14 23:05:08 -05:00
|
|
|
func _on_body_entered(body):
|
2023-01-15 00:18:38 -05:00
|
|
|
if body.name != "Player":
|
|
|
|
if body.is_in_group("enemies"):
|
|
|
|
body.take_damage(DAMAGE);
|
|
|
|
explode();
|
|
|
|
|
2023-01-15 11:17:51 -05:00
|
|
|
func end_of_life():
|
|
|
|
is_hanging = true;
|
|
|
|
|
2023-01-15 00:18:38 -05:00
|
|
|
func explode():
|
2023-01-15 12:27:19 -05:00
|
|
|
velocity = Vector2.ZERO;
|
|
|
|
sprite.play("explosion");
|
2023-01-15 11:17:51 -05:00
|
|
|
|
2023-01-15 12:27:19 -05:00
|
|
|
func _on_sprite_2d_animation_finished():
|
|
|
|
queue_free();
|