summaryrefslogtreecommitdiffstats
path: root/scripts/PlayerCharacter.gd
blob: 06602a4d0fd230e002b27fa0d1664222bb9dec74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)