コード例 #1
0
ファイル: level4Game.cs プロジェクト: aidanmac91/BasketBall
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            isFiring          = true;
            shootingDirection = GameObject.Find("Main Camera").transform.forward;
            initialVelocity   = shootingDirection * (power);
            windX             = Random.Range(0, 20);
            windY             = Random.Range(0, 20);
            basketBall        = new SpinProjectile(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, rx, ry, rz, omega, radius);
            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");
            }
        }
    }
コード例 #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 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);
            }
        }
    }