<commit_before>﻿using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public class CrowBehaviour : MonoBehaviour {

	private bool selected;
	private bool moving;
	public Animator animation;
	private Vector2 target;
	private float maxSpeed;
	public int obedience;
	public bool facingLeft;

	// Use this for initialization
	void Start () {
		maxSpeed = 3;
		moving = false;
	}
	
	// Update is called once per frame
	void Update () {

		// Select bird on Left Click
		if (Input.GetMouseButtonDown(0)) {
			Debug.Log("Pressed left click, casting ray.");
			CastSelectRay();
		}
		
		// Move bird if selected
		if (Input.GetMouseButtonDown (1) && selected) {
			CastMoveRay();
		}

		// See if object colliding with dark matter
		checkDarkCollide ();

		//Get direction that bird is moving
		float move = transform.position.x - target.x;
		
		// Move bird towards target
		if ((Vector2)transform.position != target) {
			float step = getCurrentSpeed () * Time.deltaTime;
			transform.position = Vector2.MoveTowards (transform.position, target, step);
			moving = true;
		} else {
			moving = false;
		}

		//Face the bird right
		if (move < 0) {
			facingLeft = false;
			transform.localRotation = Quaternion.Euler (0, 180, 0);
		}

		//Face the bird left
		if (move > 0){
			facingLeft = true;
			transform.localRotation = Quaternion.Euler (0, 0, 0);
		}
		
		// Wobble
		if (!moving && !selected) {
			target = getRandomPoint((Vector2)transform.position, obedienceToDistance());
		}
	}

	void CastSelectRay() {
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity);
		if (hit.collider == this.GetComponent<BoxCollider2D>()) {
			Debug.Log("Bird Selected");
			animation.speed = 0;
			selected = true;
			moving = false;
		} else {
			animation.speed = 1;
			selected = false;
			moving = true;
		}
	}

	void checkDarkCollide() {
		CircleCollider2D collider = this.GetComponent<CircleCollider2D> ();
		Shadow shadow = GameObject.Find ("Shadow").GetComponent<Shadow> ();
		List<Point> points = shadow.getPoints();
		for (int i = 0; i < points.Count; i++) {
			Point p = points[i];
			double end = p.getRad () * 100;

			double top;
			double bottom;
			bool check;

		}
	}

	void CastMoveRay(){
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		target = getRandomPoint(ray.origin, obedienceToDistance());
		animation.speed = 1;
		moving = true;
		Debug.Log ("Crow selected now moving to " + target);
	}

	float getCurrentSpeed(){
		if (moving) {
			if (obedience < maxSpeed) {
				return obedience + 1;
			} else {
				return maxSpeed;
			}
		} else {
			return 0;
		}
	}

	int obedienceToDistance(){<commit_msg>Really broken :( but getting organised<commit_after>﻿using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public class CrowBehaviour : MonoBehaviour {

	private bool selected;
	private bool moving;
	public Animator animation;
	private Vector2 target;
	private float maxSpeed;
	public int obedience;
	public bool facingLeft;

	// Use this for initialization
	void Start () {
		maxSpeed = 3;
		moving = false;
	}
	
	// Update is called once per frame
	void Update () {

		// Select bird on Left Click
		if (Input.GetMouseButtonDown(0)) {
			CastSelectRay();
		}
		
		// Move bird if selected
		if (Input.GetMouseButtonDown (1) && selected) {
			CastMoveRay();
		}

		// See if object colliding with dark matter
		//checkDarkCollide ();

		// Move bird towards target
		if ((Vector2)transform.position != target && moving) {
			moveBird();
		}

		adjustDirection ();

		// Wobble
		/*if (!moving && !selected) {
			target = getRandomPoint((Vector2)transform.position, obedienceToDistance());
			moving = true;
		}*/
	}

	void adjustDirection(){
		//Get direction that bird is moving
		float move = transform.position.x - target.x;
		
		//Face the bird right
		if (move < 0) {
			facingLeft = false;
			transform.localRotation = Quaternion.Euler (0, 180, 0);
		}
		
		//Face the bird left
		if (move > 0) {
			facingLeft = true;
			transform.localRotation = Quaternion.Euler (0, 0, 0);
		}
	}

	void moveBird (){
		float step = getCurrentSpeed () * Time.deltaTime;
		transform.position = Vector2.MoveTowards (transform.position, target, step);
	}

	void CastSelectRay() {
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity);
		if (hit.collider == this.GetComponent<BoxCollider2D>()) {
			//Debug.Log("Bird Selected");
			animation.speed = 0;
			selected = true;
			moving = false;
		} else {
			animation.speed = 1;
			selected = false;
			moving = true;
		}
	}

	void checkDarkCollide() {
		CircleCollider2D collider = this.GetComponent<CircleCollider2D> ();
		Shadow shadow = GameObject.Find ("Shadow").GetComponent<Shadow> ();
		List<Point> points = shadow.getPoints();
		for (int i = 0; i < points.Count; i++) {
			Point p = points[i];
			double end = p.getRad () * 100;

			double top;
			double bottom;
			bool check;

		}
	}

	void CastMoveRay(){
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		target = getRandomPoint(ray.origin, obedienceToDistance());
		animation.speed = 1;
		moving = true;
		//Debug.Log ("Crow selected now moving to " + target);
	}

	float getCurrentSpeed(){
		if (moving) {
			if (obedience < maxSpeed) {
				return obedience + 1;
			} else {
				return maxSpeed;
			}
		} else {
			return 0;
		}
	}

	int obedienceToDistance(){
{'fraction_non_alphanumeric': 0.12263981298327639, 'fraction_numerical': 0.01114907390757058, 'mean_word_length': 3.3487099296325256, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2189932', 'n_tokens_mistral': 2108, 'n_tokens_neox': 1767, 'n_words': 492}