//  This method redraws the GUI display.
    private void UpdateDisplay()
    {
        Graphics g      = drawingPanel.CreateGraphics();
        int      width  = drawingPanel.Width - 1;
        int      height = drawingPanel.Height - 1;

        //  Clear the current display.
//    g.Clear(drawingPanel.BackColor);
        g.Clear(Color.White);

        //  Update the position of the golfball on the screen.
        SolidBrush brush    = new SolidBrush(Color.Black);
        Pen        blackPen = new Pen(Color.Black, 1);

        //  Draw picture based on whether the XZ or
        //  XY axes are selected.
        string axes = (string)axesComboBox.SelectedItem;

        if (String.Equals(axes, "XZ"))
        {
            //  Draw the golfer.
            int zLocation = height - 50;
            g.DrawImage(golferIcon, 0, zLocation, 34, 50);

            //  Draw the flag
            zLocation = height - 62;
            g.DrawImage(flagIcon, (int)(2.0 * distanceToHole),
                        zLocation, 55, 62);

            //  Update the position of the golfball
            //  on the screen.
            int xPosition = (int)(2.0 * golfball.GetX() + 14);
            int zPosition = (int)(height - 5 - 2.0 * golfball.GetZ());
            g.FillEllipse(brush, xPosition, zPosition, 5, 5);
        }
        else
        {
            //  Draw location of green.
            g.DrawEllipse(blackPen, (int)(2.0 * distanceToHole - 20), 80, 40, 40);
            g.FillEllipse(brush, (int)(2.0 * distanceToHole - 4), 96, 8, 8);

            //  Update the position of the golfball
            //  on the screen.
            int xPosition = (int)(2.0 * golfball.GetX());
            int yPosition = (int)(100 - 2 - 2.0 * golfball.GetY());
            g.FillEllipse(brush, xPosition, yPosition, 5, 5);
        }

        //  Clean up the Graphics object.
        g.Dispose();
    }
Example #2
0
    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");
            }
        }
    }