summaryrefslogtreecommitdiff
path: root/src/entities/actors
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/actors')
-rw-r--r--src/entities/actors/snake/Snake.tscn16
-rw-r--r--src/entities/actors/snake/body_segment/BodySegment.tscn31
-rw-r--r--src/entities/actors/snake/body_segment/body_segment.gd27
-rw-r--r--src/entities/actors/snake/head/Head.tscn5
-rw-r--r--src/entities/actors/snake/head/head.gd21
-rw-r--r--src/entities/actors/snake/snake.gd14
-rw-r--r--src/entities/actors/snake/sprites/1x1.png (renamed from src/entities/actors/snake/body_segment/1x1.png)bin82 -> 82 bytes
-rw-r--r--src/entities/actors/snake/sprites/1x1.png.import (renamed from src/entities/actors/snake/body_segment/1x1.png.import)6
-rw-r--r--src/entities/actors/snake/sprites/head.pngbin0 -> 188 bytes
-rw-r--r--src/entities/actors/snake/sprites/head.png.import35
-rw-r--r--src/entities/actors/snake/sprites/segment.pngbin0 -> 168 bytes
-rw-r--r--src/entities/actors/snake/sprites/segment.png.import35
-rw-r--r--src/entities/actors/snake/sprites/tail.pngbin0 -> 174 bytes
-rw-r--r--src/entities/actors/snake/sprites/tail.png.import35
14 files changed, 192 insertions, 33 deletions
diff --git a/src/entities/actors/snake/Snake.tscn b/src/entities/actors/snake/Snake.tscn
index 98d106c..5548f40 100644
--- a/src/entities/actors/snake/Snake.tscn
+++ b/src/entities/actors/snake/Snake.tscn
@@ -15,6 +15,22 @@ BODY_SEGMENT_NP = ExtResource( 2 )
[node name="Head" parent="." instance=ExtResource( 1 )]
+[node name="BodySegment" parent="." instance=ExtResource( 2 )]
+position = Vector2( 0, 16 )
+PREV_SEGMENT_NP = NodePath("../Head")
+
+[node name="BodySegment2" parent="." instance=ExtResource( 2 )]
+position = Vector2( 0, 32 )
+PREV_SEGMENT_NP = NodePath("../BodySegment")
+
+[node name="BodySegment3" parent="." instance=ExtResource( 2 )]
+position = Vector2( 0, 48 )
+PREV_SEGMENT_NP = NodePath("../BodySegment2")
+
+[node name="BodySegment4" parent="." instance=ExtResource( 2 )]
+position = Vector2( 0, 64 )
+PREV_SEGMENT_NP = NodePath("../BodySegment3")
+
[node name="Path" type="Path2D" parent="."]
curve = SubResource( 1 )
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
diff --git a/src/entities/actors/snake/head/Head.tscn b/src/entities/actors/snake/head/Head.tscn
index 790e2f0..a77cbef 100644
--- a/src/entities/actors/snake/head/Head.tscn
+++ b/src/entities/actors/snake/head/Head.tscn
@@ -1,6 +1,6 @@
[gd_scene load_steps=3 format=2]
-[ext_resource path="res://icons/game.png" type="Texture" id=1]
+[ext_resource path="res://entities/actors/snake/sprites/head.png" type="Texture" id=1]
[ext_resource path="res://entities/actors/snake/head/head.gd" type="Script" id=2]
[node name="HeadPoint" type="Node2D"]
@@ -8,3 +8,6 @@ script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
+
+[node name="NextPivot" type="Node2D" parent="."]
+position = Vector2( 0, 8 )
diff --git a/src/entities/actors/snake/head/head.gd b/src/entities/actors/snake/head/head.gd
index 222d091..96707b7 100644
--- a/src/entities/actors/snake/head/head.gd
+++ b/src/entities/actors/snake/head/head.gd
@@ -1,13 +1,10 @@
extends Node2D
-# export(float, 1.0, 1000.0, 1.0) var SPEED: float = 100.0
-# export(float, 1.0, 1000.0, 1.0) var ROT_SPEED: float = 200.0
-# export(float, 0.01, 1.0, 0.01) var POSITION_UPDATE_INTERVAL: float = 0.01
-var speed: float
-var rot_speed: float
-var position_update_interval: float
-
-var direction: Vector2 = Vector2.UP
+var speed: float = Global.SNAKE_SPEED
+var rot_speed: float = Global.SNAKE_ROT_SPEED
+var position_update_interval: float = Global.SNAKE_POSITION_UPDATE_INTERVAL
+
+var _direction: Vector2 = Vector2.UP
var _time_elapsed: float = 0.0
@@ -17,14 +14,14 @@ func _ready():
func _process(delta: float) -> void:
if Input.is_action_pressed("move_left"):
- # direction = direction.rotated(deg2rad(-ROT_SPEED))
+ # _direction = _direction.rotated(deg2rad(-ROT_SPEED))
rotate(deg2rad(-rot_speed * delta))
if Input.is_action_pressed("move_right"):
- # direction = direction.rotated(deg2rad(ROT_SPEED))
+ # _direction = _direction.rotated(deg2rad(ROT_SPEED))
rotate(deg2rad(rot_speed * delta))
- move_local_x(direction.x * speed * delta)
- move_local_y(direction.y * speed * delta)
+ move_local_x(_direction.x * speed * delta)
+ move_local_y(_direction.y * speed * delta)
_handle_time_elapsed(delta)
diff --git a/src/entities/actors/snake/snake.gd b/src/entities/actors/snake/snake.gd
index 7da829c..fb817da 100644
--- a/src/entities/actors/snake/snake.gd
+++ b/src/entities/actors/snake/snake.gd
@@ -1,9 +1,6 @@
class_name Snake
extends Node2D
-export(float, 1.0, 1000.0, 1.0) var SPEED: float = 100.0
-export(float, 1.0, 1000.0, 1.0) var ROT_SPEED: float = 200.0
-export(float, 0.01, 1.0, 0.01) var POSITION_UPDATE_INTERVAL: float = 0.01
export(PackedScene) var BODY_SEGMENT_NP: PackedScene
onready var head: Node2D = $Head
@@ -11,18 +8,16 @@ onready var path: Path2D = $Path
onready var path_follow: PathFollow2D = $Path/PathFollow
onready var curve: Curve2D = Curve2D.new()
+var speed: float = Global.SNAKE_SPEED
+
func _ready():
Event.connect("new_curve_point", self, "_on_Head_new_curve_point")
path.curve = curve
- head.speed = SPEED
- head.rot_speed = ROT_SPEED
- head.position_update_interval = POSITION_UPDATE_INTERVAL
- set_process(false)
func _process(delta: float) -> void:
- path_follow.set_offset(path_follow.get_offset() + SPEED * delta)
+ path_follow.offset = path_follow.offset + speed * delta
func _draw() -> void:
@@ -32,9 +27,6 @@ func _draw() -> void:
func add_point_to_curve(coordinates: Vector2) -> void:
path.curve.add_point(coordinates)
- # need at least 2 points to enable processing (sprite move)
- if not is_processing() and path.curve.get_baked_points().size() >= 2:
- set_process(true)
# update call is to draw curve
update()
diff --git a/src/entities/actors/snake/body_segment/1x1.png b/src/entities/actors/snake/sprites/1x1.png
index 89d23b0..89d23b0 100644
--- a/src/entities/actors/snake/body_segment/1x1.png
+++ b/src/entities/actors/snake/sprites/1x1.png
Binary files differ
diff --git a/src/entities/actors/snake/body_segment/1x1.png.import b/src/entities/actors/snake/sprites/1x1.png.import
index ec15366..f3df488 100644
--- a/src/entities/actors/snake/body_segment/1x1.png.import
+++ b/src/entities/actors/snake/sprites/1x1.png.import
@@ -2,15 +2,15 @@
importer="texture"
type="StreamTexture"
-path="res://.import/1x1.png-6e89afd7f217fca93b741eefef4d6779.stex"
+path="res://.import/1x1.png-a365c2cbbf23daa7097bc2296bfd3da2.stex"
metadata={
"vram_texture": false
}
[deps]
-source_file="res://entities/actors/snake/body_segment/1x1.png"
-dest_files=[ "res://.import/1x1.png-6e89afd7f217fca93b741eefef4d6779.stex" ]
+source_file="res://entities/actors/snake/sprites/1x1.png"
+dest_files=[ "res://.import/1x1.png-a365c2cbbf23daa7097bc2296bfd3da2.stex" ]
[params]
diff --git a/src/entities/actors/snake/sprites/head.png b/src/entities/actors/snake/sprites/head.png
new file mode 100644
index 0000000..525de45
--- /dev/null
+++ b/src/entities/actors/snake/sprites/head.png
Binary files differ
diff --git a/src/entities/actors/snake/sprites/head.png.import b/src/entities/actors/snake/sprites/head.png.import
new file mode 100644
index 0000000..41a68eb
--- /dev/null
+++ b/src/entities/actors/snake/sprites/head.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/head.png-6a71dfa58e2c838244fb865b81cd114a.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://entities/actors/snake/sprites/head.png"
+dest_files=[ "res://.import/head.png-6a71dfa58e2c838244fb865b81cd114a.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/sprites/segment.png b/src/entities/actors/snake/sprites/segment.png
new file mode 100644
index 0000000..ebef3b4
--- /dev/null
+++ b/src/entities/actors/snake/sprites/segment.png
Binary files differ
diff --git a/src/entities/actors/snake/sprites/segment.png.import b/src/entities/actors/snake/sprites/segment.png.import
new file mode 100644
index 0000000..fb8abf6
--- /dev/null
+++ b/src/entities/actors/snake/sprites/segment.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/segment.png-63caac6c6161fc5c022cf02c07309ac1.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://entities/actors/snake/sprites/segment.png"
+dest_files=[ "res://.import/segment.png-63caac6c6161fc5c022cf02c07309ac1.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/sprites/tail.png b/src/entities/actors/snake/sprites/tail.png
new file mode 100644
index 0000000..ff78e1b
--- /dev/null
+++ b/src/entities/actors/snake/sprites/tail.png
Binary files differ
diff --git a/src/entities/actors/snake/sprites/tail.png.import b/src/entities/actors/snake/sprites/tail.png.import
new file mode 100644
index 0000000..614848e
--- /dev/null
+++ b/src/entities/actors/snake/sprites/tail.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/tail.png-a5618126bef18046eeb4da10da3411cb.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://entities/actors/snake/sprites/tail.png"
+dest_files=[ "res://.import/tail.png-a5618126bef18046eeb4da10da3411cb.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