コード例 #1
0
ファイル: golfBall4.cs プロジェクト: BOKeeffe/Golf_Game
    /*
     * Only hit the golfball and simulate movement based on input from the UI button in the UIController class
     *
     */
    void HitBall()
    {
        if (hitBall)
        {
            // inialize again, But only once
            initialize();


            time += Time.deltaTime;
            time /= 10;
            golfBall.UpdateLocationAndVelocity(time);

            if (golfBall.GetZ() >= 0.0)
            {
                gameObject.transform.position = new Vector3((float)golfBall.GetX(), (float)golfBall.GetZ(), (float)golfBall.GetY());
                //print ("x="+golfBall.GetX() +" y="+golfBall.GetZ());
            }
            else
            {
                hitBall     = false;
                trailSwitch = false;
                //print ("x="+golfBall.GetX() +" y="+golfBall.GetZ());
            }
        }
    }
コード例 #2
0
    //  This method is called by the Timer every 0.05 seconds.
    public void ActionPerformed(object source, EventArgs e)
    {
        //  Update the time and compute the new position
        //  of the basketball.
        double timeIncrement = 0.025;

        basketball.UpdateLocationAndVelocity(timeIncrement);

        //  Update the display
        UpdateDisplay();

        //  Access the Graphics object of the drawing panel.
        Graphics   g     = drawingPanel.CreateGraphics();
        SolidBrush brush = new SolidBrush(Color.Black);
        Font       font  = new Font("Arial", 12);

        //  Determine if the ball impacts the backboard. If it does,
        //  change the x-velocity assuming a frictionless collision.
        //  A collision occurs if the x-velocity is positive, and the
        //  ball location is inside the backboard area.
        if (basketball.GetVx() > 0.0 &&
            basketball.GetX() >= 5.5 &&
            basketball.GetZ() > 2.93 &&
            basketball.GetZ() < 4.0)
        {
            double ecor = 0.75;                             // coefficient of restitution
            basketball.SetQ(-ecor * basketball.GetVx(), 0); //  vx
        }

        //  Determine if the shot is good.
        //  The center of the basket is 4.2 m from the free
        //  throw line (which is at x = 1.0 m). A shot is considered
        //  to be made if the center of the ball is within 0.22
        //  of the center of the basket.
        double dx       = basketball.GetX() - 5.2;
        double dz       = basketball.GetZ() - 3.048;
        double distance = Math.Sqrt(dx * dx + dz * dz);

        if (distance <= 0.14)
        {
            shotMade = true;
            basketball.SetQ(0.0, 0); //  vx
        }

        //  If the basketball hits the ground, stop the simulation
        if (basketball.GetZ() <= 0.25)
        {
            if (shotMade == true)
            {
                g.DrawString("Shot is good.", font, brush, 80, 40);
            }
            else
            {
                g.DrawString("Shot missed.", font, brush, 80, 40);
            }

            //  Stop the simulation
            gameTimer.Stop();
        }
    }
コード例 #3
0
ファイル: Golf2.cs プロジェクト: BOKeeffe/Golf_Game
    void Update()
    {
        time += Time.deltaTime;
        golfBall.UpdateLocationAndVelocity(time);

        if (golfBall.GetZ() >= 1)
        {
            gameObject.transform.position = new Vector3((float)golfBall.GetX(), (float)golfBall.GetZ(), (float)golfBall.GetY());
            print("x=" + golfBall.GetX() + " y=" + golfBall.GetZ());
        }
    }
コード例 #4
0
ファイル: level2Game.cs プロジェクト: aidanmac91/BasketBall
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            isFiring          = true;
            shootingDirection = GameObject.Find("Main Camera").transform.forward;
            initialVelocity   = shootingDirection * (power);                                                                               //sets strengths
            basketBall        = new DragProjectile(gameObject.transform.position.x, gameObject.transform.position.z, gameObject.transform.position.y,
                                                   initialVelocity.x, initialVelocity.z, initialVelocity.y, 0.0, mass, area, density, cd); //creates projectile
            gameObject.transform.position = new Vector3((float)basketBall.GetX(), (float)basketBall.GetZ(), (float)basketBall.GetY());
        }
        if (isFiring)
        {
            time += Time.deltaTime / 100;               //slows down time
            basketBall.UpdateLocationAndVelocity(time); //updates position and speed

            if (basketBall.GetZ() >= -1)
            {
                gameObject.transform.position = new Vector3((float)basketBall.GetX(), (float)basketBall.GetZ(), (float)basketBall.GetY());
            }
            else
            {
                if (distance(ball.transform.position, target.transform.position) < 1) //hits
                {
                    audio.PlayOneShot(cheer);                                         //sound
                    score += 2;                                                       //increases
                }
                isFiring = false;                                                     //false
                time     = 0;                                                         //sets
                resetBall();                                                          //reset ball
            }
        }

        if (shootsTaken == 5)     //load next level
        {
            previousLevel++;
            PlayerPrefs.SetInt("currentScore", currentScore + score);
            PlayerPrefs.SetInt("previousLevel", previousLevel);
            PlayerPrefs.Save();
            Application.LoadLevel("briefing");
        }
    }
コード例 #5
0
    //  This method is called by the Timer every 0.05 seconds.
    public void ActionPerformed(object source, EventArgs e)
    {
        //  Update the time and compute the new position
        //  of the golfball.
        double timeIncrement = 0.07;

        golfball.UpdateLocationAndVelocity(timeIncrement);

        //  Update the display
        UpdateDisplay();

        //  Access the Graphics object of the drawing panel.
        Graphics g = drawingPanel.CreateGraphics();

        //  When the golfball hits the ground, stop the simulation
        //  and see where ball has landed.
        if (golfball.GetZ() <= 0.0)
        {
            Console.WriteLine("time=" + (float)golfball.GetTime() +
                              "  x=" + (float)golfball.GetX() +
                              "  y=" + (float)golfball.GetY() + "  z=" + (float)golfball.GetZ());

            //  Stop the simulation
            gameTimer.Stop();

            //  Determine if ball is on the green.
            SolidBrush brush = new SolidBrush(Color.Black);
            Font       font  = new Font("Arial", 12);
            if (golfball.GetX() > distanceToHole - 10.0 &&
                golfball.GetX() < distanceToHole + 10.0 &&
                golfball.GetY() < 10.0)
            {
                g.DrawString("You're on the green", font, brush, 100, 30);
            }
            else
            {
                g.DrawString("You missed", font, brush, 100, 30);
            }
        }
    }