Ze pew
This commit is contained in:
@@ -2,29 +2,42 @@ extends Area2D
|
||||
|
||||
@export var DAMAGE = 10;
|
||||
@export var SPEED = 700;
|
||||
@export var LIFETIME = 1;
|
||||
|
||||
@onready var life_timer = $LifeTimer;
|
||||
@export var LIFETIME = 1.0;
|
||||
@export var HANG_TIME = 0.0;
|
||||
@export var FRICTION = 0.0;
|
||||
|
||||
var is_hanging = false;
|
||||
var velocity = Vector2.ZERO;
|
||||
var time = 0.0;
|
||||
|
||||
func _process(delta):
|
||||
|
||||
if is_hanging :
|
||||
velocity = velocity * FRICTION;
|
||||
if velocity != Vector2.ZERO:
|
||||
transform.origin += velocity * delta;
|
||||
|
||||
time += delta;
|
||||
|
||||
if time >= LIFETIME:
|
||||
end_of_life();
|
||||
if time >= LIFETIME + HANG_TIME:
|
||||
explode();
|
||||
|
||||
func launch(direction, based_velocity):
|
||||
life_timer.start(LIFETIME);
|
||||
velocity = based_velocity + direction * SPEED;
|
||||
|
||||
func _on_life_timer_timeout():
|
||||
queue_free();
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body.name != "Player":
|
||||
if body.is_in_group("enemies"):
|
||||
body.take_damage(DAMAGE);
|
||||
explode();
|
||||
|
||||
func end_of_life():
|
||||
is_hanging = true;
|
||||
|
||||
func explode():
|
||||
#animation and stuff
|
||||
queue_free();
|
||||
|
||||
|
||||
|
||||
|
@@ -4,6 +4,7 @@
|
||||
[ext_resource type="Texture2D" uid="uid://gqotbni355f" path="res://Sprites/placeholder_projectile.png" id="1_o7jy1"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_pp7ve"]
|
||||
size = Vector2(4, 4)
|
||||
|
||||
[node name="basic_projectile" type="Area2D"]
|
||||
script = ExtResource("1_l2kyf")
|
||||
@@ -15,7 +16,4 @@ texture = ExtResource("1_o7jy1")
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_pp7ve")
|
||||
|
||||
[node name="LifeTimer" type="Timer" parent="."]
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
[connection signal="timeout" from="LifeTimer" to="." method="_on_life_timer_timeout"]
|
||||
|
13
Projectiles/sand.tscn
Normal file
13
Projectiles/sand.tscn
Normal file
@@ -0,0 +1,13 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bedh0enwukdbf"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cpo8qy3y0fuui" path="res://Projectiles/basic_projectile.tscn" id="1_mqpki"]
|
||||
|
||||
[node name="basic_projectile" instance=ExtResource("1_mqpki")]
|
||||
DAMAGE = 1
|
||||
SPEED = 1000
|
||||
LIFETIME = 0.1
|
||||
HANG_TIME = 0.3
|
||||
FRICTION = 0.92
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
scale = Vector2(2.43502, 2.43502)
|
Reference in New Issue
Block a user