Пример #1
0
    /*
     * 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();


            if (golfBall.GetZ() >= 0.0)
            {
                time += Time.deltaTime;
                time /= 5;
                golfBall.UpdateLocationAndVelocity(time);

                gameObject.transform.position = new Vector3((float)golfBall.GetX(), (float)golfBall.GetZ(), (float)golfBall.GetY());

                //print ("x="+golfBall.GetX() +" y="+golfBall.GetZ());
            }
            else
            {
                restartShoot();
                //gameObject.transform.position = new Vector3((float)golfBall.GetX(), (float)golfBall.GetZ(), (float)golfBall.GetY());
                hitBall     = false;
                trailSwitch = false;
            }
            //print ("x="+golfBall.GetX() +" y="+golfBall.GetZ());
        }
    }
Пример #2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            isFiring = true;
            gameObject.transform.parent = null;
            shootingDirection           = GameObject.Find("Main Camera").transform.forward;
            initialVelocity             = shootingDirection * (power);
            windX      = Random.Range(0, 20);    //Randomly generates wind
            windY      = Random.Range(0, 20);    //Randomly generates wind
            basketBall = new WindProjectile(gameObject.transform.position.x, gameObject.transform.position.z, gameObject.transform.position.y,
                                            initialVelocity.x, initialVelocity.z, initialVelocity.y, 0.0, mass, area, density, cd, windX, windY);
            gameObject.transform.position = new Vector3((float)basketBall.GetX(), (float)basketBall.GetZ(), (float)basketBall.GetY());
        }
        if (isFiring)
        {
            time += Time.deltaTime / 100;
            basketBall.UpdateLocationAndVelocity(time);

            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)
                {
                    audio.PlayOneShot(cheer);    //sound
                    score += 3;                  //increases
                }
                isFiring = false;
                time     = 0;
                resetBall();
            }
            if (shootsTaken == 5)
            {
                previousLevel++;
                PlayerPrefs.SetInt("currentScore", currentScore + score);
                PlayerPrefs.SetInt("previousLevel", previousLevel);
                PlayerPrefs.Save();
                Application.LoadLevel("briefing");
            }
        }
    }
    //  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);
            }
        }
    }