public List <BallProperty> GetBallPropties(Mat frame) { //色でマスク Mat masked = GetColorMasked(frame); //輪郭膨張 masked = GetExpansion(masked); //水平線マスク masked = GetHorizonMasked(masked); //円でマスク //masked = GetCircleMasked(masked); //輪郭 Mat[] contours = GetContours(masked); var moList = new List <BallProperty>(); for (int i = 0; i < contours.Length; i++) { BallProperty m = new BallProperty(); m.index = i; m.contour = contours[i]; m.area = Cv2.ContourArea(contours[i]); moList.Add(m); } moList.Sort((a, b) => (int)(b.area - a.area)); return(moList); }
public float fireRate = 12.5f; //砲台發射頻率 public void Initialize() { BallProperty Base = CreateInstance <BallProperty>(); damage = Base.damage; reflect = Base.reflect; speed = Base.speed; fireRate = Base.fireRate; }
void FixedUpdate() { if (Input.GetKey ("left")) { var rb = gameObject.GetComponent<Rigidbody>(); rb.AddForce(-4, 0, 0); //rb.transform.Rotate(6.0f*rotationsPerMinute*Time.deltaTime,0.0f,0.0f); //Vector3 position = this.transform.position; //position.x = position.x - 0.1f; //this.transform.position = position; } if (Input.GetKey ("right")) { var rb = gameObject.GetComponent<Rigidbody>(); rb.AddForce(4, 0, 0); //rb.transform.Rotate(6.0f*rotationsPerMinute*Time.deltaTime,0.0f,0.0f); //Vector3 position = this.transform.position; //position.x = position.x + 0.1f; //this.transform.position = position; } if((Input.GetKeyDown ("space")||Input.GetButtonDown("Rubber_jump")) && canJump && property == BallProperty.Rubber) { //Debug.Log("space down"); canJump = false; var rb = gameObject.GetComponent<Rigidbody>(); rb.AddForce(new Vector3(0, thrust, 0)); GetComponent<Collider>().material.bounciness = 1.0f; keepBouncing = 4.0f; } if (keepBouncing > 0 && canJump) { canJump = false; var rb = gameObject.GetComponent<Rigidbody>(); // float b = keepBouncing; rb.AddForce(new Vector3(0, thrust / (6.0f - keepBouncing), 0)); keepBouncing -= 1.0f; //GetComponent<Collider>().material.bounciness = 1000.0f; } if (Input.GetKey ("1")) { GetComponent<Renderer>().material.mainTexture = null; gameObject.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); GetComponent<Rigidbody>().mass = 1.0f; property = BallProperty.Normal; } if (Input.GetKey ("2")) { GetComponent<Renderer>().material.mainTexture = rubberball; gameObject.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f); GetComponent<Rigidbody>().mass = 1.0f; property = BallProperty.Rubber; } if (Input.GetKey ("3")) { GetComponent<Renderer>().material.mainTexture = steelball; gameObject.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f); GetComponent<Rigidbody>().mass = 5.0f; property = BallProperty.Steel; } // if (Input.GetKey ("4")) { // GetComponent<Renderer>().material.mainTexture = bubbleball; // property = BallProperty.Bubble; // } }
// Update is called once per frame void Update() { transform.Rotate(6.0f*rotationsPerMinute*Time.deltaTime,0.0f,0.0f); var rb = gameObject.GetComponent<Rigidbody>(); rb.AddTorque (10.0f, 0.0f, 0.0f); if (property == BallProperty.Rubber) { RubberBarSlider.value -= Time.deltaTime * 0.01f; if(RubberBarSlider.value <= 0) { GetComponent<Renderer>().material.mainTexture = null; property = BallProperty.Normal; gameObject.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); } } if (property == BallProperty.Steel) { SteelBarSlider.value -= Time.deltaTime * 0.01f; if(SteelBarSlider.value <= 0) { GetComponent<Renderer>().material.mainTexture = null; property = BallProperty.Normal; gameObject.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); } } if (property == BallProperty.Bubble) { movingup = this.transform.position; movingup.y += 0.2f; if(movingup.y>2.0f) movingup.y = 2.0f; this.transform.position = movingup; } }
// Use this for initialization void Start() { GameObject g = GameObject.Find ("GameManager"); globalObj = g.GetComponent< GameManagerScript >(); GameObject a = GameObject.Find ("AudioManager"); AudioManager = a.GetComponent<AudioManagerScript>(); property = BallProperty.Normal; }