Mortar first act
This commit is contained in:
@ -5,6 +5,19 @@ var speed
|
||||
var hitpoint
|
||||
var distancetaken = 0
|
||||
|
||||
#For the mortar, to create a nice bezier curve!
|
||||
var starterpos = 0
|
||||
var targetpos = 0
|
||||
var midpoint = 0
|
||||
var t = 0.0
|
||||
var duration = 0.5
|
||||
|
||||
func _ready() -> void:
|
||||
starterpos = global_position
|
||||
targetpos = target.global_position
|
||||
midpoint = (targetpos + starterpos) / 2
|
||||
midpoint.y -= 200 #height of the curve!
|
||||
|
||||
func set_targe(_target : Node2D) -> void:
|
||||
target = _target
|
||||
|
||||
@ -14,8 +27,15 @@ func set_speed(_speed: int) -> void:
|
||||
func set_hitpoint(_hitpoint: int) -> void:
|
||||
hitpoint = _hitpoint
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if target and speed > 0:
|
||||
if name.contains("Rock"):
|
||||
t += delta / duration
|
||||
position = bezier(t)
|
||||
if t >= 1.0:
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hit")
|
||||
set_process(false)
|
||||
elif target and speed > 0:
|
||||
# Get the direction vector from the bullet to the target
|
||||
var direction = (target.get_parent().get_parent().get_position() - position).normalized()
|
||||
|
||||
@ -44,8 +64,17 @@ func target_reached() -> void:
|
||||
if name.contains("Magic"):
|
||||
if randf() < 0.5:
|
||||
target.get_parent().set_progress(max(target.get_parent().get_progress() - 60, 0))
|
||||
|
||||
|
||||
|
||||
|
||||
target.get_parent().enemy_hurt(hitpoint)
|
||||
queue_free()
|
||||
|
||||
|
||||
func bezier(t: float):
|
||||
var q0 = starterpos.lerp(midpoint, t)
|
||||
var q1 = midpoint.lerp(targetpos, t)
|
||||
return q0.lerp(q1, t)
|
||||
|
||||
|
||||
|
||||
func _on_animated_sprite_2d_animation_finished() -> void:
|
||||
queue_free()
|
||||
|
59
Game/Bullets/rock.tscn
Normal file
59
Game/Bullets/rock.tscn
Normal file
@ -0,0 +1,59 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://cwcgq1vk643ha"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dqvdgdobuo2rf" path="res://Game/Bullets/bullet.gd" id="1_yml18"]
|
||||
[ext_resource type="Texture2D" uid="uid://t8y1d33eiffp" path="res://Assets/Bullets/mortarbullet (1).png" id="2_yml18"]
|
||||
[ext_resource type="Texture2D" uid="uid://cinql8footbvf" path="res://Assets/Bullets/mortarbullet (2).png" id="3_tjven"]
|
||||
[ext_resource type="Texture2D" uid="uid://xm4gs3h00bk1" path="res://Assets/Bullets/mortarbullet (3).png" id="4_av0br"]
|
||||
[ext_resource type="Texture2D" uid="uid://crf32to6tlkux" path="res://Assets/Bullets/mortarbullet (4).png" id="5_c612l"]
|
||||
[ext_resource type="Texture2D" uid="uid://bbu8u4h7vpqwa" path="res://Assets/Bullets/mortarbullet (5).png" id="6_m5188"]
|
||||
[ext_resource type="Texture2D" uid="uid://uc2ib201l7kd" path="res://Assets/Bullets/mortarbullet (6).png" id="7_lr72h"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_yml18"]
|
||||
size = Vector2(18, 16)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_yml18"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_yml18")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 2.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("3_tjven")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("4_av0br")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("5_c612l")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("6_m5188")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("7_lr72h")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"hit",
|
||||
"speed": 8.0
|
||||
}]
|
||||
|
||||
[node name="Rock" type="Node2D"]
|
||||
script = ExtResource("1_yml18")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="."]
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
shape = SubResource("RectangleShape2D_yml18")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="CharacterBody2D"]
|
||||
scale = Vector2(0.4, 0.4)
|
||||
sprite_frames = SubResource("SpriteFrames_yml18")
|
||||
autoplay = "default"
|
||||
|
||||
[connection signal="animation_finished" from="CharacterBody2D/AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
|
Reference in New Issue
Block a user