Leech Prototype
This commit is contained in:
parent
eefd58da42
commit
517eb56063
8 changed files with 122 additions and 2 deletions
|
|
@ -29,7 +29,7 @@ func _physics_process(delta: float) -> void:
|
|||
current_knockback = current_knockback/pow(1.3, 60*delta)
|
||||
|
||||
if(self.overlaps_body(player)):
|
||||
player.hurt(damage, self.position-player.position)
|
||||
player.hurt(damage, self.global_position-player.global_position)
|
||||
|
||||
func _on_death():
|
||||
self.queue_free()
|
||||
|
|
|
|||
56
enemies/leech.gd
Normal file
56
enemies/leech.gd
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
extends Node2D
|
||||
@export var broadth = 250
|
||||
@export var move_dir = 1
|
||||
@export var angular_speed = 0.25
|
||||
var angle = 0.0 if move_dir == 1 else PI
|
||||
|
||||
@onready var segments : Array[Node] = $Segments.get_children()
|
||||
@onready var segment_count = segments.size()
|
||||
var paused = false
|
||||
var pause_time = 0.1
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not paused:
|
||||
angle -= TAU * delta * angular_speed * move_dir
|
||||
if(angle > PI or angle < 0):
|
||||
paused = true
|
||||
await get_tree().create_timer(pause_time).timeout
|
||||
paused = false
|
||||
angle = fmod(angle + PI, PI)
|
||||
var y = position.length()
|
||||
var ratio = - move_dir * broadth / (2 * y)
|
||||
var rot_angle = - 2 * asin(ratio)
|
||||
position = position.rotated(rot_angle)
|
||||
|
||||
|
||||
for i in range(segment_count):
|
||||
var segment_pos_data = calculate_segment_location_and_rotation(i)
|
||||
segments[i].position = segment_pos_data.position
|
||||
segments[i].rotation = segment_pos_data.rotation
|
||||
|
||||
func calculate_segment_location_and_rotation (i) -> Dictionary:
|
||||
var aerial_end_location = Vector2.from_angle(-angle) * broadth
|
||||
var gravicenter = (aerial_end_location + Vector2(0, -broadth) + Vector2.ZERO) / 3
|
||||
var ax = gravicenter.x
|
||||
var ay = gravicenter.y
|
||||
var bx = aerial_end_location.x
|
||||
var by = aerial_end_location.y
|
||||
var cx = 0
|
||||
var cy = 0
|
||||
var d = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by))
|
||||
var ux = ((ax * ax + ay * ay) * (by - cy) + (bx * bx + by * by) * (cy - ay) + (cx * cx + cy * cy) * (ay - by)) / d
|
||||
var uy = ((ax * ax + ay * ay) * (cx - bx) + (bx * bx + by * by) * (ax - cx) + (cx * cx + cy * cy) * (bx - ax)) / d
|
||||
var center = Vector2(ux, uy)
|
||||
var radius = center.length()
|
||||
var switch_arc_dir = false
|
||||
if ux < 0:
|
||||
switch_arc_dir = !switch_arc_dir
|
||||
if center.angle() > 1:
|
||||
switch_arc_dir = !switch_arc_dir
|
||||
|
||||
var angle1 = - PI + center.angle()
|
||||
var angle2 = - PI + (center-aerial_end_location).angle()
|
||||
if(switch_arc_dir):
|
||||
angle1 += TAU
|
||||
return {"position": center + radius * Vector2.from_angle((i * angle1 + (segment_count - 1 - i) * angle2)/(segment_count - 1))
|
||||
, "rotation": (i * angle1 + (segment_count - 1 - i) * angle2)/ (segment_count - 1) + PI/2}
|
||||
1
enemies/leech.gd.uid
Normal file
1
enemies/leech.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b70f2ylbb3btt
|
||||
30
enemies/leech.tscn
Normal file
30
enemies/leech.tscn
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://b62xcg0dd3vct"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b70f2ylbb3btt" path="res://enemies/leech.gd" id="1_6u582"]
|
||||
[ext_resource type="PackedScene" uid="uid://cvoicwo2xnf7e" path="res://segment.tscn" id="2_oqch2"]
|
||||
[ext_resource type="PackedScene" uid="uid://chs0u61f45nau" path="res://utils/earth_aligner.tscn" id="3_0r7dp"]
|
||||
|
||||
[node name="Leech" type="Node2D"]
|
||||
script = ExtResource("1_6u582")
|
||||
|
||||
[node name="Segments" type="Node2D" parent="."]
|
||||
|
||||
[node name="Segment0" parent="Segments" instance=ExtResource("2_oqch2")]
|
||||
|
||||
[node name="Segment2" parent="Segments" instance=ExtResource("2_oqch2")]
|
||||
|
||||
[node name="Segment3" parent="Segments" instance=ExtResource("2_oqch2")]
|
||||
|
||||
[node name="Segment4" parent="Segments" instance=ExtResource("2_oqch2")]
|
||||
|
||||
[node name="Segment5" parent="Segments" instance=ExtResource("2_oqch2")]
|
||||
|
||||
[node name="Segment6" parent="Segments" instance=ExtResource("2_oqch2")]
|
||||
|
||||
[node name="Segment7" parent="Segments" instance=ExtResource("2_oqch2")]
|
||||
|
||||
[node name="Segment8" parent="Segments" instance=ExtResource("2_oqch2")]
|
||||
|
||||
[node name="Segment9" parent="Segments" instance=ExtResource("2_oqch2")]
|
||||
|
||||
[node name="EarthAligner" parent="." instance=ExtResource("3_0r7dp")]
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://cxo6bq26huau7"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://cxo6bq26huau7"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cmaovvr15b3qk" path="res://player/player.tscn" id="2_1bvp3"]
|
||||
[ext_resource type="Script" uid="uid://vgxh2xdevat7" path="res://world/earth.gd" id="2_lquwl"]
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://cjsrtswk4vgf2" path="res://healthbar/healthbar.tscn" id="6_7mycd"]
|
||||
[ext_resource type="PackedScene" uid="uid://dpdn2php3ydsv" path="res://death_screen/death_screen.tscn" id="7_5vw27"]
|
||||
[ext_resource type="Script" uid="uid://3k6r3jnko4hg" path="res://show_fps.gd" id="8_5vw27"]
|
||||
[ext_resource type="PackedScene" uid="uid://b62xcg0dd3vct" path="res://enemies/leech.tscn" id="9_kek77"]
|
||||
|
||||
[node name="main" type="Node2D"]
|
||||
|
||||
|
|
@ -57,6 +58,9 @@ offset_bottom = 23.0
|
|||
grow_horizontal = 0
|
||||
script = ExtResource("8_5vw27")
|
||||
|
||||
[node name="Leech" parent="." instance=ExtResource("9_kek77")]
|
||||
position = Vector2(0, -3000)
|
||||
|
||||
[connection signal="active_item_changed" from="Player" to="CanvasLayer/ItemUI" method="_on_player_active_item_changed"]
|
||||
[connection signal="health_changed" from="Player" to="CanvasLayer/Healthbar" method="_on_player_health_changed"]
|
||||
[connection signal="max_hp_changed" from="Player" to="CanvasLayer/Healthbar" method="_on_player_max_hp_changed"]
|
||||
|
|
|
|||
8
segment.gd
Normal file
8
segment.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
extends Area2D
|
||||
@onready var player = get_tree().get_root().get_node_or_null("main/Player")
|
||||
var damage = 1
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if (player != null and overlaps_body(player)):
|
||||
player.hurt(damage, self.global_position-player.global_position)
|
||||
|
||||
1
segment.gd.uid
Normal file
1
segment.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b3q5khoqnnicx
|
||||
20
segment.tscn
Normal file
20
segment.tscn
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://cvoicwo2xnf7e"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b3q5khoqnnicx" path="res://segment.gd" id="1_o43lr"]
|
||||
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_sa5vt"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_fgt1l"]
|
||||
|
||||
[node name="Segment" type="Area2D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 4
|
||||
script = ExtResource("1_o43lr")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
modulate = Color(0.309804, 0.113725, 0, 1)
|
||||
scale = Vector2(0.315, 0.16)
|
||||
texture = ExtResource("2_sa5vt")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
scale = Vector2(2, 1)
|
||||
shape = SubResource("RectangleShape2D_fgt1l")
|
||||
Loading…
Add table
Reference in a new issue