Beispiel #1
0
        public static void CollisionBallBar(ref ball gameBall, int characterX, int characterY)
        {
            if (gameBall.y == 22 && gameBall.x >= characterX && gameBall.x <= characterX + BAR_WIDTH)
            {
                gameBall.yDirection = (sbyte)-gameBall.yDirection;
                switch (gameBall.x - characterX)
                {
                case 0:
                    gameBall.xDirection = -1;
                    gameBall.xAngle     = -2;
                    break;

                case 1:
                    gameBall.xDirection = -1;
                    gameBall.xAngle     = -1;
                    break;

                case 2:
                    gameBall.xDirection = 0;
                    gameBall.xAngle     = 0;
                    break;

                case 3:
                    gameBall.xDirection = 1;
                    gameBall.xAngle     = 1;
                    break;

                case 4:
                    gameBall.xDirection = 1;
                    gameBall.xAngle     = 2;
                    break;
                }
            }
        }
Beispiel #2
0
 // Use this for initialization
 void Start()
 {
     isNotActive = false;
     ball        = FindObjectOfType <ball>();
     gamePad     = FindObjectOfType <GamePad>();
     tempIndex   = gamePad.index;
 }
Beispiel #3
0
        // Creating the Ball and it's movement
        private void Ball()
        {
            ball Ball = new ball();

            xball = Ball.MoveHorizontal(xball, ballright, ballleft, extrahorvelball);
            yball = Ball.MoveVertical(yball, ballup, balldown, extravervelball);
        }
    void CreateNewBall()
    {
        ball[] b = transform.GetComponentsInChildren <ball>();
        for (int i = 0; i < b.Length; i++)
        {
            DestroyImmediate(b[i].gameObject);
        }
        m_collider = GetComponent <BoxCollider>();
        m_Balls    = new List <ball>();
        float      space  = GameMgr.instance.CreateBallSpace;
        GameObject prefab = BallPoolMgr.instance.BallPrefab;

        for (int i = 0; i < XCount; i++)
        {
            for (int j = 0; j < YCount; j++)
            {
                for (int k = 0; k < HCount; k++)
                {
                    GameObject obj  = Instantiate(prefab, transform);
                    ball       ball = obj.GetComponent <ball>();
                    ball.rig.isKinematic = true;
                    m_Balls.Add(ball);

                    obj.transform.localPosition = new Vector3(j * space, k * space, i * space);
                }
            }
        }
    }
Beispiel #5
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "projectile")
        {
            ball ballSc = collision.gameObject.GetComponent <ball>();
            BallHitPos = collision.gameObject.transform.position;
            Debug.Log(BallHitPos);

            //HealthBallCollision(ballSc.damage);

            Destroy(collision.gameObject);
            if (ballSc.damage > 0)
            {
                if (gameSc.health > 0)
                {
                    cam.backgroundColor = new Color(0.6f, 0f, 0f);
                    StartCoroutine(sleep());
                    gameSc.health -= ballSc.damage;
                    Audio.Play();
                }
            }
            else
            {
                if (gameSc.health < 100)
                {
                    gameSc.health -= ballSc.damage;
                }
            }
        }
    }
Beispiel #6
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (GameManagerCopy.gameMode == Status.game && isDead != true)
     {
         if (other.gameObject.tag == "ball")
         {
             ball = other.gameObject;
             ball ballscript = ball.GetComponent <ball>();
             if (ballscript.shooting == false && ballscript.hasParent == false)
             {
                 catched(ballscript);
             }
             else if (ballscript.shooting && ballscript.parent != this.face)
             {
                 if (catching)
                 {
                     Vector2 drawBack = ballscript.rb2D.velocity;
                     rb2D.velocity = drawBack / 2;
                     catched(ballscript);
                 }
                 else
                 {
                     Vector2 drawBack = ballscript.rb2D.velocity;
                     rb2D.velocity = drawBack;
                     death();
                     ballscript.rb2D.velocity = drawBack / 3;
                     GameManagerCopy.checkEndturn(this);
                     transform.rotation = Quaternion.Euler(0, 0, 0);
                 }
             }
         }
     }
 }
        public BasketballScene()
        {
            reset = false;

            Song bgm = Cloud.content.Load <Song>("Thats a Wrap");

            MediaPlayer.Play(bgm);
            MediaPlayer.IsRepeating = true;

            sw.Start();

            renderables        = new RenderableCollection();
            Physics.collisions = new CollisionHandler(renderables);

            toAdd    = new List <Renderable>();
            toRemove = new List <Renderable>();

            Ball = new ball(new Vector2(120, 150), this);
            renderables.Add(Ball);

            TextureStatic.Load("hoopA", @"Art");
            TextureStatic.Load("hoopB", @"Art");
            TextureStatic.Load("courtBG", @"Art");
            TextureStatic.Load("net", @"Art");
            TextureStatic.Load("net2", @"Art");
            //courtbg = new Background("court", @"Art\Backgrounds", new Vector2(-360, 110), new Vector2(-10, 0), 0.11f, true, this);
            //renderables.Add(courtbg);

            //tentacle tn = new tentacle(new Vector2(0, 0), this);
            //renderables.Add(tn);
        }
Beispiel #8
0
 private void OnTriggerEnter(Collider col)
 {
     Debug.Log("ball in");
     if (col.gameObject.tag == "Ball")
     {
         GameObject gameObj = col.gameObject;
         ball       obj     = (ball)gameObj.GetComponent <ball>();
         Debug.Log("ball ID: " + obj.getId());
         if (obj != null)
         {
             Debug.Log("ball ID: " + obj.getId());
             if (obj.getId() != Id)
             {
                 Rigidbody item = gameObj.GetComponent <Rigidbody>();
                 item.GetComponent <Rigidbody>().isKinematic = false;
                 transform.DetachChildren();
                 Vector3 camDirct = transform.TransformDirection(0, 0, 0);
                 // Random ran_x = new UnityEngine.Random();
                 // Random ran_y = new Random();
                 // Random ran_z = new Random();
                 item.velocity = new Vector3(UnityEngine.Random.Range(-10, 10), UnityEngine.Random.Range(5, 10), UnityEngine.Random.Range(-10, 10));
             }
         }
     }
 }
Beispiel #9
0
    public void playing()
    {
        b = current.GetComponent <ball>();

        PlayerPrefs.SetInt("ball", b.number);
        SceneManager.LoadScene("main");
    }
Beispiel #10
0
    public void prev()
    {
        b = current.GetComponent <ball>();


        nextb.SetActive(true);
        if (b.number > 0)
        {
            if (b.number == 1)
            {
                prevs.SetActive(false);
            }
            //print (b.number);
            ball [b.number].SetActive(false);
            for (int i = 0; i < ball.Length; i++)
            {
                if (i == b.number - 1)
                {
                    ball actual = ball [i].GetComponent <ball> ();
                    ball [i].SetActive(true);

                    if (owned[i] == 1)
                    {
                        buy.SetActive(false);
                        play.SetActive(true);
                        price.text = "owned";
                        watchb.SetActive(false);
                    }
                    else
                    {
                        if (actual.ads)
                        {
                            watchb.SetActive(true);
                            buy.SetActive(false);
                            play.SetActive(false);
                            if (PlayerPrefs.GetInt("watch" + actual.number) == 0)
                            {
                                adst.text  = "X " + actual.numberAds;
                                price.text = "";
                            }
                            else
                            {
                                adst.text  = "X " + PlayerPrefs.GetInt("watch" + actual.number);
                                price.text = "";
                            }
                        }
                        else
                        {
                            watchb.SetActive(false);
                            buy.SetActive(true);
                            play.SetActive(false);
                            price.text = ball [i].GetComponent <ball> ().price.ToString();
                        }
                    }

                    current = ball [i];
                }
            }
        }
    }
Beispiel #11
0
    public void switchCharacter()
    {
        bool switched = false;
        int  counter  = 0;

        if (outOfThrows == false)
        {
            while (switched == false)
            {
                currentCharacter++;
                if (currentCharacter == 1)
                {
                    if (StBernard.getHoldAllowed() == true)
                    {
                        storeCharacter(StBernard);
                    }
                    if (Hugo.getStorage() == true)
                    {
                        centerCharacter(Hugo);
                        currentBall = Hugo;
                        switched    = true;
                    }
                }
                else if (currentCharacter == 2)
                {
                    if (Hugo.getHoldAllowed() == true)
                    {
                        storeCharacter(Hugo);
                    }
                    if (Chihuahua.getStorage() == true)
                    {
                        centerCharacter(Chihuahua);
                        currentBall = Chihuahua;
                        switched    = true;
                    }
                }
                else
                {
                    if (Chihuahua.getHoldAllowed() == true)
                    {
                        storeCharacter(Chihuahua);
                    }
                    if (StBernard.getStorage() == true)
                    {
                        centerCharacter(StBernard);
                        currentBall = StBernard;
                        switched    = true;
                    }
                    currentCharacter = 0;
                }
                counter++;

                if (counter > 3)
                {
                    switched    = true;
                    outOfThrows = true;
                }
            }
        }
    }
Beispiel #12
0
    public void shoot()
    {
        hasBall = false;
        ball    ballscript = ball.GetComponent <ball>();
        Vector3 forward    = input;

        if (forward.y > 0)
        {
            forward.y = 1;
        }
        else if (forward.y < 0)
        {
            forward.y = -1;
        }
        if (transform.rotation.y == -1)
        {
            forward.x = 1;
        }
        else if (transform.rotation.y == 0)
        {
            forward.x = -1;
        }
        if (forward.x > 0)
        {
            forward.x = 1;
        }
        else if (forward.x < 0)
        {
            forward.x = -1;
        }

        ballscript.shoot(force, forward);
    }
Beispiel #13
0
    // Use this for initialization
    void Start()
    {
        hpfield = GetComponent <Text>();
        GameObject ballGo = GameObject.Find("ball");

        ballScript   = (ball)ballGo.GetComponent(typeof(ball));
        hpfield.text = "HP: " + ballScript.getHp();
    }
Beispiel #14
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Ball")
     {
         ball ball = collision.GetComponent <ball>();
         BallsManager.Instance.Balls.Remove(ball);
         ball.Die();
     }
 }
Beispiel #15
0
    public void createBall()
    {
        GameObject ball = Instantiate(ball_pref, new Vector3(0, 0, 0), Quaternion.identity, ball_cont.transform);
        ball       bs   = ball.GetComponent <ball>();

        bs.canvas = this;

        current_ball = ball;
    }
Beispiel #16
0
 void catched(ball ballscript)
 {
     ballscript.sr.color      = teamColor;
     ballscript.catchable     = false;
     ballscript.rb2D.velocity = new Vector2(0, 0);
     ballscript.shooting      = false;
     hasBall              = true;
     ballscript.parent    = face;
     ballscript.hasParent = true;
 }
Beispiel #17
0
    // ボール作成。一定以上積もっちゃったらゲームオーバーにする
    public GameObject CreateBall()
    {
        GameObject ball = (GameObject)Instantiate(prefabBall);                 // 複製。Object型で生成されるのでGameObject型に変換

        ball.transform.position = new Vector3(Random.Range(minX, maxX), Y, 0); // 横の位置をランダムに変更
        ball color = ball.GetComponent <ball>();                               // ballスクリプト取って来る

        color.ChangeColor(Random.Range(1, colorPattern + 1));                  // ランダムに色変更
        count++;                                                               // 落とした個数増やす
        exist++;                                                               // 存在する数増やす
        return(ball);                                                          // 操作出来るようにオブジェクト返しておく
    }
Beispiel #18
0
    // Use this for initialization
    void Start()
    {
        currentCharacter = 0;

        center    = new Vector3(0, 0, 0);
        storage   = new Vector3(300, 300, 0);
        StBernard = Instantiate(StBernardPrefab, center, transform.rotation);
        Hugo      = Instantiate(HugoPrefab, center, transform.rotation);
        Chihuahua = Instantiate(ChihuahuaPrefab, center, transform.rotation);
        storeAllCharacters();
        switchCharacter();
    }
Beispiel #19
0
    private void InitBall()
    {
        Vector3 paddlePosition   = Paddle.Instance.gameObject.transform.position;
        Vector3 startingPosition = new Vector3(paddlePosition.x + .78f, paddlePosition.y + .7f, 0);

        initiaBall   = Instantiate(ballPrefab, startingPosition, Quaternion.identity);
        initiaBallRb = initiaBall.GetComponent <Rigidbody2D>();

        this.Balls = new List <ball>
        {
            initiaBall
        };
    }
Beispiel #20
0
 void init()
 {
     Random rnd = new Random();
     bool flag;
     int k,i;
     for (i = 0; i < nb; i++)
     {
         ba[i] = new ball();
         ba[i].FormHeight = this.Height;
         ba[i].FormWidth = this.Width;
         ba[i].Bkcolor = this.BackColor;
         ba[i].graph = gr;
         ba[i].r = rnd.Next(10) + 10;
         do
         {
             flag = false;
             ba[i].x = rnd.NextDouble() * (this.Width - 2 * ba[i].r - 15) + ba[i].r;
             ba[i].y = rnd.NextDouble() * (this.Height - 80 - 2 * ba[i].r) + ba[i].r;
             k = 0;
             while (k < i)
             {
                 if (ba[i].x == ba[k].x && ba[i].y == ba[k].y)
                     flag = true;
                 k++;
             }
         } while (flag);
         ba[i].vx = rnd.NextDouble() * 4000 - 2000;
         ba[i].vy = rnd.NextDouble() * 4000 - 2000;
         av += Math.Sqrt(ba[i].vx * ba[i].vx + ba[i].vy * ba[i].vy);
         do
         {
             ba[i].color = Color.FromArgb(255, rnd.Next(256), rnd.Next(256), rnd.Next(256));
         } while (ba[i].color == this.BackColor);
     }
     av /= nb;
 }
Beispiel #21
0
 public hole(float x, float z, float radius, ball targetBall)
 {
     this.x = x;
     this.z = z;
     this.radius = radius;
     this.targetBall = targetBall;
 }
Beispiel #22
0
 public void addNewBall()
 {
     double ballSpeed = 6;//the balls standard spawning speed
     ContentControl tempBall = new ContentControl();//temporary ball ContentControl
     tempBall.Template = Resources["ballTemplate"] as ControlTemplate;//set a template for it
     playArea.Children.Add(tempBall);//add it to the screen
     Canvas.SetBottom(tempBall, (playArea.ActualHeight / 2));//set where it should start (y)
     Canvas.SetLeft(tempBall, (playArea.ActualWidth / 2) - 7.5);//set where it should start(x)
     //Random r = new Random();//a random value to determine what direction the ball should move & what speed it should move with
     double xspeedTemp = rand.NextDouble()*ballSpeed;//find a random speed
     int tempYDirection = rand.Next(1,3);//find a random y direction based on r
     if(tempYDirection.Equals(2)){
         tempYDirection = -1;
     }
     int tempXDirection = rand.Next(1,3);//find a random X direction based on r
     if(tempXDirection.Equals(2)){
         tempXDirection = -1;
     }
     ball tempBallClass = new ball(tempBall,xspeedTemp,(6-xspeedTemp),tempXDirection,tempYDirection,ballSpeed);//create a temporary instance of the class
     ballList.Add(tempBallClass);//add the object to the ballList
 }
    // Use this for initialization
    void Start()
    {
        //  this.transform.rotation = Quaternion.Euler(0, 90, 0);
        ball_contact_collider = ball_contact_collider_pbj.GetComponent<BoxCollider>();
        dust_particle = dust_particle_obj.GetComponent<ParticleSystem>();

        dust_particle.Stop();
          //  spawn_pos = physics_container.transform.position;
        this.name = player_id.ToString();
        rd = physics_container.GetComponent<Rigidbody>();
        my_collider = physics_container.GetComponent<BoxCollider>();
        animator = this.GetComponent<Animator>();
        ball_instance = GameObject.Find("ball").GetComponent<ball>();
        punsh_collider = punsh_collider_holder.GetComponent<BoxCollider>();
        punsh_collider.enabled = false;
        switch (player_id)
        {
          case vars.player_id.player_1: pid = 0; break;
          case vars.player_id.player_2: pid = 1; break;
          case vars.player_id.player_3: pid = 2; break;
          case vars.player_id.player_4: pid = 3; break;
          default:
        break;
        }
        if (pid >= 0)
        {
          inputDevice = (InputManager.Devices.Count > pid) ? InputManager.Devices[pid] : null;
        }
        if (inputDevice != null)
        {
          is_playing = true;
        }
        else
        {

        }
        set_pause_pos();
        animator.SetFloat("punsh_speed", punsh_speed);
        animator.SetBool("dance_1", false);
         //   set_pause_pos();
        rotate_front();
    }
Beispiel #24
0
 public void addBall(ball pocketedBall)
 {
     m_pocketedBalls.Add(pocketedBall);
 }
Beispiel #25
0
 // Use this for initialization
 void Start()
 {
     ball = GameObject.FindObjectOfType<ball>();
     paddlePos = new Vector3 (8f, this.transform.position.y, 0f);
 }
    // Use this for initialization
    void Start()
    {
        ball_instance = GameObject.Find("ball").GetComponent<ball>(); ;
        punsh_collider = punsh_obj.GetComponent<BoxCollider>();
        punsh_start_position = punsh_obj.transform.localPosition;
        punsh_collider.enabled = false;
        instatiate_points();
        rd = this.GetComponent<Rigidbody>();
        is_playing = false;
        this.name = player_id.ToString();
        spawn_pos = this.transform.position; //save the spawn pos
        set_pause_pos();
        spawn_particle_system_holder.GetComponent<ParticleSystem>().playbackSpeed = spawn_particle_system_speed;
        spawn_particle_system_holder.GetComponent<ParticleSystem>().loop = false;
        spawn_particle_system_holder.GetComponent<ParticleSystem>().Stop();

        switch (player_id)
        {
            case vars.player_id.player_1: pid = 0; break;
            case vars.player_id.player_2: pid = 1; break;
            case vars.player_id.player_3: pid = 2; break;
            case vars.player_id.player_4: pid = 3; break;
            default:
                break;
        }
        if (pid >= 0)
        {
            inputDevice = (InputManager.Devices.Count > pid) ? InputManager.Devices[pid] : null;
        }
        if (inputDevice != null)
        {
            is_playing = true;
        }
    }