extends KinematicBody2D

var motion = Vector2()
var speed = 150
var up = Vector2(0, -1)
var grav = 20
var jumpy = -350
var smacking = false
onready var raycast = $RayCast2D
	
func _physics_process(delta):
	motion.y += grav
	
	if Input.is_action_pressed("ui_right"):
		motion.x = speed
		$PlayerSprite.flip_h = false
		$RayCast2D.global_rotation_degrees = 0
		$PlayerSprite.play("Run")
	elif Input.is_action_pressed("ui_left"):
		motion.x = -speed
		$PlayerSprite.flip_h = true
		$RayCast2D.global_rotation_degrees = 180
		$PlayerSprite.play("Run")
	else:
		motion.x = 0
		$PlayerSprite.play("Idle")
	if is_on_floor():
		if Input.is_action_just_pressed("jump"):
			motion.y = jumpy
			$AudioStreamPlayer.play()
	if Input.is_action_just_pressed("smack"):
		$PlayerSprite.play("Smack")
		$AudioStreamPlayer2.play()
	if raycast.is_colliding():
		var coll = raycast.get_collider()
		Glob.hit = coll.name
	
	if Glob.ready == true:
		$AudioStreamPlayer3.play()
	
		



	motion = move_and_slide(motion, up)
	
