//  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();
    }
Ejemplo n.º 2
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());
        }
    }
Ejemplo n.º 3
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");
            }
        }
    }
Ejemplo n.º 4
0
    /*
     * Initialize the starting variables again after setting with UI inputs;
     */
    void initialize()
    {
        if (init)
        {
            trailSwitch = true;
            vx0         = tempVx0;
            vy0         = tempVy0;
            vz0         = tempVz0;
            mass        = 20.0f;
            area        = .2f;
            cd          = .4f;
            density     = 1.2f;

            /*
             * if(Application.loadedLevel == 3){
             *      tempWindX = Random.Range(-50, 50);
             *      tempWindY = Random.Range(-50, 50);
             *      windVx = tempWindX;
             *      windVy = tempWindY;
             * }
             * else{
             *      windVx = 0;
             *      windVy = 0;
             * }
             */


            golfBall = new WindProjectile(gameObject.transform.position.x, gameObject.transform.position.z, gameObject.transform.position.y,
                                          vx0, vy0, vz0, 0.0, mass, area, density, cd, windVx, windVy);


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

            init = false;
            //	reverseVz = false;
            if (Application.loadedLevel == 3)
            {
                tempWindX = Random.Range(-50, 50);
                tempWindY = Random.Range(-50, 50);
                windVx    = tempWindX;
                windVy    = tempWindY;
            }
            else
            {
                windVx = 0;
                windVy = 0;
            }
        }
    }