summaryrefslogtreecommitdiff
path: root/src/entities/actors/snake/body_segment
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/actors/snake/body_segment')
-rw-r--r--src/entities/actors/snake/body_segment/1x1.pngbin82 -> 0 bytes
-rw-r--r--src/entities/actors/snake/body_segment/1x1.png.import35
-rw-r--r--src/entities/actors/snake/body_segment/BodySegment.tscn31
-rw-r--r--src/entities/actors/snake/body_segment/body_segment.gd27
4 files changed, 52 insertions, 41 deletions
diff --git a/src/entities/actors/snake/body_segment/1x1.png b/src/entities/actors/snake/body_segment/1x1.png
deleted file mode 100644
index 89d23b0..0000000
--- a/src/entities/actors/snake/body_segment/1x1.png
+++ /dev/null
Binary files differ
diff --git a/src/entities/actors/snake/body_segment/1x1.png.import b/src/entities/actors/snake/body_segment/1x1.png.import
deleted file mode 100644
index ec15366..0000000
--- a/src/entities/actors/snake/body_segment/1x1.png.import
+++ /dev/null
@@ -1,35 +0,0 @@
-[remap]
-
-importer="texture"
-type="StreamTexture"
-path="res://.import/1x1.png-6e89afd7f217fca93b741eefef4d6779.stex"
-metadata={
-"vram_texture": false
-}
-
-[deps]
-
-source_file="res://entities/actors/snake/body_segment/1x1.png"
-dest_files=[ "res://.import/1x1.png-6e89afd7f217fca93b741eefef4d6779.stex" ]
-
-[params]
-
-compress/mode=0
-compress/lossy_quality=0.7
-compress/hdr_mode=0
-compress/bptc_ldr=0
-compress/normal_map=0
-flags/repeat=0
-flags/filter=false
-flags/mipmaps=false
-flags/anisotropic=false
-flags/srgb=2
-process/fix_alpha_border=false
-process/premult_alpha=false
-process/HDR_as_SRGB=false
-process/invert_color=false
-process/normal_map_invert_y=false
-stream=false
-size_limit=0
-detect_3d=false
-svg/scale=1.0
diff --git a/src/entities/actors/snake/body_segment/BodySegment.tscn b/src/entities/actors/snake/body_segment/BodySegment.tscn
index 065a42d..4bf02b0 100644
--- a/src/entities/actors/snake/body_segment/BodySegment.tscn
+++ b/src/entities/actors/snake/body_segment/BodySegment.tscn
@@ -1,9 +1,28 @@
-[gd_scene load_steps=2 format=2]
+[gd_scene load_steps=3 format=2]
-[ext_resource path="res://entities/actors/snake/body_segment/1x1.png" type="Texture" id=1]
+[ext_resource path="res://entities/actors/snake/sprites/segment.png" type="Texture" id=1]
+[ext_resource path="res://entities/actors/snake/body_segment/body_segment.gd" type="Script" id=2]
-[node name="BodySegment" type="Sprite"]
-modulate = Color( 0, 1, 0, 1 )
-position = Vector2( 0, 16 )
-scale = Vector2( 32, 32 )
+[node name="BodySegment" type="Node2D"]
+script = ExtResource( 2 )
+
+[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
+
+[node name="DirectionLine" type="Line2D" parent="."]
+visible = false
+points = PoolVector2Array( 0, 0, 0, -32 )
+width = 2.0
+default_color = Color( 1, 0, 0, 1 )
+
+[node name="DirectionToPreviousLine" type="Line2D" parent="."]
+visible = false
+points = PoolVector2Array( 0, 0, 0, -32 )
+width = 2.0
+default_color = Color( 0, 0, 1, 1 )
+
+[node name="PrevPivot" type="Node2D" parent="."]
+position = Vector2( 0, -8 )
+
+[node name="NextPivot" type="Node2D" parent="."]
+position = Vector2( 0, 8 )
diff --git a/src/entities/actors/snake/body_segment/body_segment.gd b/src/entities/actors/snake/body_segment/body_segment.gd
new file mode 100644
index 0000000..eabede3
--- /dev/null
+++ b/src/entities/actors/snake/body_segment/body_segment.gd
@@ -0,0 +1,27 @@
+extends Node2D
+
+export(NodePath) var PREV_SEGMENT_NP: NodePath
+
+onready var prev_segment: Node2D = get_node(PREV_SEGMENT_NP)
+onready var prev_segment_next_pivot: Node2D = prev_segment.get_node("NextPivot")
+onready var _prev_pivot: Node2D = $PrevPivot
+onready var _next_pivot: Node2D = $NextPivot
+
+var rot_speed: float = Global.SNAKE_SEGMENT_ROT_SPEED
+
+var prev_segment_next_pivot_to_center: Vector2
+var _center_to_prev_pivot: Vector2
+var _angle_between_segments: float
+
+
+func _process(delta: float) -> void:
+ prev_segment_next_pivot_to_center = prev_segment_next_pivot.global_position - prev_segment.global_position
+ _center_to_prev_pivot = _prev_pivot.global_position - global_position
+
+ _angle_between_segments = _center_to_prev_pivot.angle_to(prev_segment_next_pivot_to_center)
+ if _angle_between_segments > 0.0:
+ rotate(deg2rad(-rot_speed * delta))
+ else:
+ rotate(deg2rad(rot_speed * delta))
+
+ global_position = prev_segment_next_pivot.global_position - _center_to_prev_pivot