extends Area2D


var color
var normal_speed
var max_speed
var move_direction


func _ready():
	var random
	var col
	
	normal_speed = Global.monster_normal
	max_speed = Global.monster_max
	
	$speed.start()
	$bot/anim.play("animation")
	$bot/spawn.play("spawn")
	
	randomize()
	random = randi() % 4 + 1
	col = randi() % 3 + 1
	
	if random == 1:
		move_direction = "up"
	if random == 2:
		move_direction = "down"
	if random == 3:
		move_direction = "left"
	if random == 4:
		move_direction = "right"
	
	if col == 1:
		color = "red"
		$bot/color/color.play("red")
	if col == 2:
		color = "blue"
		$bot/color/color.play("blue")
	if col == 3:
		color = "yellow"
		$bot/color/color.play("yellow")
	pass


# warning-ignore:unused_argument
func _physics_process(delta):
	move()
	
	if position.x > 1785:
		position.x = 135
	if position.x < 135:
		position.x = 1785

	if position.y < 220:
		position.y = 970
	if position.y > 970:
		position.y = 220
		
	if normal_speed > max_speed:
		$speed.stop()
	
	if Global.game_over == true:
		queue_free()
	pass


func move():
	if move_direction == "up":
		position -= Vector2(0, normal_speed)
	if move_direction == "down":
		position += Vector2(0, normal_speed)
	if move_direction == "left":
		position -= Vector2(normal_speed, 0)
	if move_direction == "right":
		position += Vector2(normal_speed, 0)
	pass


func _on_speed_timeout():
	normal_speed += 0.5
	pass


func _on_bot_area_entered(area):
	if area.has_method("character_move"):
		if Global.color == color:
			Global.score += 1
			Global.progress += 3
			queue_free()
			$"/root/main/menu/Sound".gear()
		else:
			Global.health -= 1
			Global.death = true
			queue_free()
			$"/root/main/menu/Sound".chip()
	pass
