summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2020-07-29 22:47:18 +0300
committerJan Tuomi <jan.tuomi@valuemotive.com>2020-07-29 22:47:18 +0300
commited61419eda9d0154a78c04999a7c8a779244ef29 (patch)
treed8253396e9c305835880a39e8730ebd575050610 /scripts
Initial commit
Diffstat (limited to 'scripts')
-rw-r--r--scripts/PlayerCharacter.gd33
-rw-r--r--scripts/Scene1.gd21
2 files changed, 54 insertions, 0 deletions
diff --git a/scripts/PlayerCharacter.gd b/scripts/PlayerCharacter.gd
new file mode 100644
index 0000000..06602a4
--- /dev/null
+++ b/scripts/PlayerCharacter.gd
@@ -0,0 +1,33 @@
+extends KinematicBody2D
+
+export (int) var speed = 8
+export (float) var walk_wobble_coeff = 5
+var velocity = Vector2()
+
+func get_input():
+ velocity = Vector2()
+ if Input.is_action_pressed('ui_right'):
+ velocity.x += 1
+ if Input.is_action_pressed('ui_left'):
+ velocity.x -= 1
+ if Input.is_action_pressed('ui_down'):
+ velocity.y += 1
+ if Input.is_action_pressed('ui_up'):
+ velocity.y -= 1
+ velocity = velocity.normalized() * speed
+
+func _process(_delta):
+ var is_moving = velocity.length_squared() > .0
+ if is_moving:
+ var time = OS.get_system_time_msecs() / 1000.0
+ var rot = 0.2 * sin(walk_wobble_coeff * time)
+ $Sprite.set_rotation(rot)
+ else:
+ $Sprite.set_rotation(0)
+
+ #$Sprite.z_index = self.position[1]
+ #print($Sprite.z_index)
+
+func _physics_process(_delta):
+ get_input()
+ velocity = move_and_slide(velocity)
diff --git a/scripts/Scene1.gd b/scripts/Scene1.gd
new file mode 100644
index 0000000..ce8376c
--- /dev/null
+++ b/scripts/Scene1.gd
@@ -0,0 +1,21 @@
+extends Node2D
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ pass # Replace with function body.
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(_delta):
+ pass
+
+func _unhandled_input(event):
+ if event is InputEventKey:
+ if event.pressed and event.scancode == KEY_ESCAPE:
+ get_tree().quit()