summaryrefslogtreecommitdiff
path: root/src/entities/actors/snake/head
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-05-30 02:05:19 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-05-30 02:05:19 -0600
commit0aa26dc19da1c8907cd69d18b423c33f351d3f2f (patch)
tree1f66ccb21df5d7cd508e50be7b4fe97fe400c580 /src/entities/actors/snake/head
parent8165182a3ec840726eaa75678ea23f7ef8e6938e (diff)
working path2d with only the head, need to figure out the segments part
Diffstat (limited to 'src/entities/actors/snake/head')
-rw-r--r--src/entities/actors/snake/head/Head.tscn10
-rw-r--r--src/entities/actors/snake/head/head.gd37
2 files changed, 47 insertions, 0 deletions
diff --git a/src/entities/actors/snake/head/Head.tscn b/src/entities/actors/snake/head/Head.tscn
new file mode 100644
index 0000000..790e2f0
--- /dev/null
+++ b/src/entities/actors/snake/head/Head.tscn
@@ -0,0 +1,10 @@
+[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/head/head.gd" type="Script" id=2]
+
+[node name="HeadPoint" type="Node2D"]
+script = ExtResource( 2 )
+
+[node name="Sprite" type="Sprite" parent="."]
+texture = ExtResource( 1 )
diff --git a/src/entities/actors/snake/head/head.gd b/src/entities/actors/snake/head/head.gd
new file mode 100644
index 0000000..222d091
--- /dev/null
+++ b/src/entities/actors/snake/head/head.gd
@@ -0,0 +1,37 @@
+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 _time_elapsed: float = 0.0
+
+
+func _ready():
+ Event.emit_signal("new_curve_point", global_position)
+
+
+func _process(delta: float) -> void:
+ if Input.is_action_pressed("move_left"):
+ # direction = direction.rotated(deg2rad(-ROT_SPEED))
+ rotate(deg2rad(-rot_speed * delta))
+ if Input.is_action_pressed("move_right"):
+ # 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)
+
+ _handle_time_elapsed(delta)
+
+
+# using a timer is not recommended for < 0.01
+func _handle_time_elapsed(delta: float) -> void:
+ if _time_elapsed >= position_update_interval:
+ Event.emit_signal("new_curve_point", global_position)
+ _time_elapsed = 0.0
+ _time_elapsed += delta