Inheritance: MonoBehaviour
Ejemplo n.º 1
0
    private void HandleCollision(MoveBall b1, MoveBall b2)
    {                                                              //collision detected: the collision has happened anytime between the previous frame and this one.
        //find how much time has past since the the collision
        MyVector3 relVelocity = MoveBall.RelativeVelocity(b2, b1); // V° rel velocity (const)
        MyVector3 relPosition = MoveBall.RelativePosition(b2, b1); // P° rel position at t=0
        //  relative position P(t) = P° - V° * t
        //  the collision happens when |P(t)| = 2 * radius
        //  <P(t)|P(t)> = <(P° - V° * t)|(P° - V° * t)> = 4 * radius^2
        //  solve the above quadratic eq. for t
        float term1       = MyVector3.Dot(relVelocity, relPosition);
        float term2       = MyVector3.Dot(relPosition, relPosition);
        float term3       = MyVector3.Dot(relVelocity, relVelocity);
        float rootSquared = term1 * term1 - term3 * (term2 - 4 * SnookerBall.radius * SnookerBall.radius);

        if (rootSquared < 0)
        {
            rootSquared = 0;
        }
        float timeAfterCollision = (term1 + Mathf.Sqrt(rootSquared)) / term3;

        b1.MoveByVector(b1.GetVelocity().Scale(-timeAfterCollision)); //minus sign because we are moving the ball back in time
        b2.MoveByVector(b2.GetVelocity().Scale(-timeAfterCollision)); //minus sign because we are moving the ball back in time
        relPosition = MoveBall.RelativePosition(b2, b1);              //vector joining the centers of the 2 balls
        MyVector3 b1_parallel      = b1.GetLinearMomentum().ParallelComponent(relPosition);
        MyVector3 b1_perpendicular = b1.GetLinearMomentum().NormalComponent(relPosition);
        MyVector3 b2_parallel      = b2.GetLinearMomentum().ParallelComponent(relPosition);
        MyVector3 b2_perpendicular = b2.GetLinearMomentum().NormalComponent(relPosition);

        //the two ball exchange the parallel components of their linear momenta
        //this is only valid in the case of the masses being the same
        b1.SetLinearMomentum(MyVector3.Add(b1_perpendicular, b2_parallel));
        b2.SetLinearMomentum(MyVector3.Add(b2_perpendicular, b1_parallel));
    }
Ejemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Ball"))
        {
            Debug.Log("충돌");

            tempBallPos   = other.transform.position;
            tempBallScale = other.transform.localScale;

            CheckCollisionSide();

            MoveBall tempMoveBall = other.gameObject.GetComponent <MoveBall>();
            if (!tempMoveBall.frameCollisionCheck)
            {
                if (shortestSide < 3)
                {
                    other.gameObject.GetComponent <MoveBall>().TurnTheBall(2);
                }
                else
                {
                    other.gameObject.GetComponent <MoveBall>().TurnTheBall(1);
                }

                tempMoveBall.frameCollisionCheck = true;

//				gameObject.SetActive(false);
                GetDamage(other.gameObject.GetComponent <BallInfo>().damage);
            }

            shortestSide = 0;
        }
    }
Ejemplo n.º 3
0
        public void InitMovePieceTests()
        {
            BoardStrategy strat = BoardStrategy.Standard;

            g           = new GameBuilder().SetBoard(3, strat).SetPlayer0("Clément", "vert").SetPlayer1("Pierre", "orange").Build();
            commandMove = new MoveBall(0, 1, 0, 0);
        }
Ejemplo n.º 4
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveBall {
        };

        return(job.Schedule(this, inputDeps));
    }
Ejemplo n.º 5
0
        public void DoMoveBallTest3()
        {
            BoardStrategy strat = BoardStrategy.Standard;

            g           = new GameBuilder().SetBoard(5, strat).SetPlayer0("Clément", "vert").SetPlayer1("Pierre", "orange").Build();
            commandMove = new MoveBall(0, 2, 0, 1);
            //Console.Write(g.Board.ToString());
            //Console.Write(commandMove.ToString());

            commandMove.Do(g);
            //Console.Write(g.Board.ToString());
            TileTypes[,] expectedTilesSize5 = { { TileTypes.PiecePlayer0, TileTypes.BallPlayer0,  TileTypes.PiecePlayer0, TileTypes.PiecePlayer0, TileTypes.PiecePlayer0 },
                                                { TileTypes.Default,      TileTypes.Default,      TileTypes.Default,      TileTypes.Default,      TileTypes.Default      },
                                                { TileTypes.Default,      TileTypes.Default,      TileTypes.Default,      TileTypes.Default,      TileTypes.Default      },
                                                { TileTypes.Default,      TileTypes.Default,      TileTypes.Default,      TileTypes.Default,      TileTypes.Default      },
                                                { TileTypes.PiecePlayer1, TileTypes.PiecePlayer1, TileTypes.BallPlayer1,  TileTypes.PiecePlayer1, TileTypes.PiecePlayer1 } };

            for (int i = 0; i < g.Board.BoardSize; i++)
            {
                for (int j = 0; j < g.Board.BoardSize; j++)
                {
                    Assert.IsTrue(g.Board.Tiles[i, j] == expectedTilesSize5[i, j]);
                }
            }
        }
Ejemplo n.º 6
0
 private void Awake()
 {
     Assert.IsNotNull(this.guiText);
     Assert.IsNotNull(this.ball);
     this._moveBall = this.ball.GetComponent <MoveBall>();
     Assert.IsNotNull(this._moveBall);
 }
Ejemplo n.º 7
0
    private void Update()
    {
        if (GameOver)
        {
            restartPanel.SetActive(true);
        }
        else
        {
            restartPanel.SetActive(false);

            if (ballInScene == null)
            {
                ballInScene = GameObject.FindGameObjectWithTag("Ball");
            }
            if (ballInScene != null)
            {
                moveBallScript  = ballInScene.GetComponent <MoveBall>();
                throwBallScript = ballInScene.GetComponent <ThrowBall>();
            }

            if (IsBallThrown && ThrustPower != 0)
            {
                moveBallScript.enabled  = false;
                throwBallScript.enabled = true;
            }
        }
    }
Ejemplo n.º 8
0
 // Start is called before the first frame update
 void Start()
 {
     moveBall          = ball.GetComponent <MoveBall>();
     moveBallRigidbody = ball.GetComponent <Rigidbody2D>();
     animateTrump1     = player1.GetComponent <AnimateTrump>();
     animateTrump2     = player2.GetComponent <AnimateTrump>();
 }
Ejemplo n.º 9
0
    public static void Main()
    {
        System.Console.WriteLine("assignment 3");
        MoveBall mb = new MoveBall();

        Application.Run(mb);
        System.Console.WriteLine("end of assignment 3");
    }
    private void OnEnable()
    {
        /// Publishers.
        _moveBall = FindObjectOfType <MoveBall>();
        Assert.IsNotNull(_moveBall);

        /// Subscribe to events.
        _moveBall.HitBackWall += OnBallHitBackWall;
    }
Ejemplo n.º 11
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveBall {
            forceAppliedMult = PlayTimeSettings.forceAppliedMult, forceMult = PlayTimeSettings.forceMult
        };


        return(job.Schedule(this, inputDeps));
    }
Ejemplo n.º 12
0
 private void startBallButton_Click(object sender, EventArgs e)
 {
     moveBalls = new List <MoveBall>();
     for (int i = 0; i < countBalls; i++)
     {
         var moveBall = new MoveBall(this);
         moveBalls.Add(moveBall);
         moveBall.Start();
     }
 }
Ejemplo n.º 13
0
    // Start is called before the first frame update
    void Start()
    {   //find the object ball and get the component moveBall
        Ball           = GameObject.Find("Ball").GetComponent <MoveBall>();
        TextLives.text = preTextScore2 + lives;
        Scoretxt.text  = preTextScore + score.ToString("D8");


        LoadLevel();                                //initialize first level

        bestScore = PlayerPrefs.GetInt("Score", 0); //read the old high score
    }
Ejemplo n.º 14
0
        public void MoveBallTest()
        {
            g.Update(new MoveBall(0, 1, 0, 0));
            MoveBall cmd = (MoveBall)g.CommandHistory.Pop().GetCommand();

            Assert.IsTrue(cmd.NextX == 0);
            Assert.IsTrue(cmd.NextY == 0);
            Assert.IsTrue(cmd.PrevX == 0);
            Assert.IsTrue(cmd.PrevY == 1);
            Assert.IsTrue(g.UndoHistory.Count == 0);
        }
Ejemplo n.º 15
0
    private void SetCurrentBall(int number)
    {
        currentBall = balls[number].GetComponent <MoveBall>();

        touchHandler.ballMovement = balls[number].GetComponent <MoveBall>();

        mainCamera.targetTransform = balls[number].transform;

        speedController.ballMovement = balls[number].GetComponent <MoveBall>();

        speedController.slider.value = currentBall.GetVelocity() / 100f;
    }
Ejemplo n.º 16
0
    void MakeBall()
    {
        ball = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        Color        color        = createRandomColor();
        MeshRenderer ballRenderer = ball.GetComponent <MeshRenderer>();
        Material     newMaterial  = new Material(Shader.Find("Diffuse"));

        newMaterial.color     = color;
        ballRenderer.material = newMaterial;
        //add necessary components
        //add move ball
        MoveBall moveball = ball.AddComponent <MoveBall>();
    }
Ejemplo n.º 17
0
    private void Start()
    {
        BallCurrentState = State.Still;
        BallThrowPower   = ThrowPower.NoPower;

        moveBallScript  = gameObject.GetComponent <MoveBall>();
        throwBallScript = gameObject.GetComponent <ThrowBall>();

        rb = gameObject.GetComponent <Rigidbody>();
        stickCollisionScript = GameObject.Find("Stick").GetComponent <Stick>();

        maxDistance = 49.51f;

        finishCollider = GameObject.Find("Finish Collider").GetComponent <FinishCollider>();
    }
Ejemplo n.º 18
0
 void Start()
 {
     /* Inputs		| Outputs
      *              |
      * Ball X		| Paddle Velocity Y
      * Ball Y		|
      * Ball Speed X |
      * Ball Speed Y |
      * Paddle X     |
      * Paddle Y		|
      */
     ball        = ballRb.GetComponent <MoveBall> ();
     inputValues = new double[6];
     outputs     = new double[1];
     brain.StartNeuralNetwork(6, 1);
 }
    private void OnTriggerEnter2D(Collider2D other)
    {
        GameObject.Find("GameManager").GetComponent <AudioSource>().Play();
        if (other.gameObject.CompareTag("paddle") && !isRunned)
        {
            isRunned = true;
            var      extraBall = Instantiate(ball, ball.transform, true);
            MoveBall moveBall  = extraBall.GetComponent <MoveBall>();
            moveBall.isDupBall = true;
            Destroy(gameObject);
        }

        if (other.gameObject.CompareTag("death"))
        {
            Destroy(gameObject);
        }
    }
Ejemplo n.º 20
0
    private void Start()
    {
        Time.timeScale = 1f;

        GameIsOver = false;
        LevelWon   = false;
        Score      = 0;
        Coin       = 0;

        moveBallScript          = GameObject.Find("Ball").GetComponent <MoveBall>();
        moveBallScript.enabled  = true;
        throwBallScript         = GameObject.Find("Ball").GetComponent <ThrowBall>();
        throwBallScript.enabled = false;

        ball = GameObject.Find("Ball");

        gameOverScreen.SetActive(false);
        levelWonScreen.SetActive(false);
    }
Ejemplo n.º 21
0
    // Use this for initialization
    public void Start()
    {
        DayAndNightCycle(true);
        settingsCode       = GameObject.FindObjectOfType <Settings>();
        paddleSensitivity  = settingsCode.Sensitivity;
        ballCode           = ballObject.GetComponent <MoveBall>();
        ballSprite         = ballObject.GetComponent <SpriteRenderer>();
        paddleCode         = paddleObject.GetComponent <MovePaddle>();
        paddleSprite       = paddleObject.GetComponent <SpriteRenderer>();
        paddleSpriteOGSize = paddleSprite.size;

        scoreText.text  = "SCORE: " + points.ToString("D8");
        powerTx.enabled = false;
        SetCreditText();
        settingsCode.GetLeaderboard();
        bestScore       = settingsCode.LeaderboardScores[0];
        rankedText.text = string.Empty;
        LoadLvl();
        InitBallSpeed();
    }
Ejemplo n.º 22
0
    // Use this for initialization
    void Start()
    {
        Time.timeScale = 1f;

        GameParams.SetScore(0);
        _nextScene = "";
        MoveBall.ClearBallCount();

        _instance = this;

        /*
         * // 敵を出現
         * for (int i = 0; i < TekiCount; i++) {
         *      Instantiate (prefTeki);
         * }
         * // アイテムを出現
         * for (int i = 0; i < ItemCount; i++) {
         *      Instantiate (prefItem);
         * }
         */
    }
Ejemplo n.º 23
0
    // Use this for initialization
    void Start()
    {
        Time.timeScale = 1f;
        GameParams.SetScore(0);
        _nextScene = "";
        MoveBall.ClearBallCount();


        _instance = this;

        /*
         * // 敵を出現
         * for (int i = 0; i < TekiCount; i++) {
         *      Instantiate (prefTeki);
         * }
         * // アイテムを出現
         * for (int i = 0; i < ItemCount; i++) {
         *      Instantiate (prefItem);
         * }
         */

        // 変数にコンポーネント格納
        sound01 = GetComponent <AudioSource>();
    }
Ejemplo n.º 24
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.CompareTag("Ball"))
        {
            Debug.Log("충돌");
            tempBallPos   = col.transform.position;
            tempBallScale = col.transform.localScale;

            CheckCollisionSide();

            MoveBall tempMoveBall = col.gameObject.GetComponent <MoveBall>();
            if (!tempMoveBall.frameCollisionCheck)
            {
                if (shortestSide < 3)
                {
                    tempMoveBall.TrunTheBall(2);
                }
                else
                {
                    tempMoveBall.TrunTheBall(1);
                }

                tempMoveBall.frameCollisionCheck = true;
                tempMoveBall = null;

                //gameObject.SetActive(false);
                GetDamage(col.gameObject.GetComponent <BallInfo>().damage);
            }
            else
            {
                tempMoveBall = null;
            }

            shortestSide = 0;
        }
    }
Ejemplo n.º 25
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        EntityCommandBuffer entityOriginsCommandBuffer = new EntityCommandBuffer(Allocator.TempJob, PlaybackPolicy.SinglePlayback);

        Entities.WithNone <BallOriginalTranslation>().ForEach((Entity entity, Translation translation, SphereId sphereId) =>
        {
            entityOriginsCommandBuffer.AddComponent(entity, new BallOriginalTranslation {
                Value = translation.Value
            });
        }).Run();
        entityOriginsCommandBuffer.Playback(EntityManager);
        entityOriginsCommandBuffer.Dispose();

        var moveBallJob = new MoveBall
        {
            TranslationType             = GetArchetypeChunkComponentType <Translation>(),
            BallOriginalTranslationType = GetArchetypeChunkComponentType <BallOriginalTranslation>(true),
            LastSystemVersion           = LastSystemVersion,
            ElapsedTime = Time.ElapsedTime
        };
        var moveBallJobHandle = moveBallJob.Schedule(m_Group, inputDeps);

        return(moveBallJobHandle);
    }
Ejemplo n.º 26
0
    void Start()
    {
        _ballMover = ball.GetComponent <MoveBall>();

        _line  = new Line(new Coordinate(ball.transform.position), lineEnd.position - ball.transform.position);
        _plane = new Plane(new Coordinate(planeOrigin.position), planeVectorV.position - planeOrigin.position,
                           planeVectorU.position - planeOrigin.position);
        _line.Draw(0.1f, Color.cyan);
        PopulatePlaneWithSpheres();
        //ShowIntersectionPoint();

        var ballPathSegment = CalculateIntersection();

        if (ballPathSegment == null)
        {
            return;
        }
        _ballMover.OnIntersectionCalculate(ballPathSegment);

        var reflectionLineSegment = ballPathSegment.ReflectsFrom(_plane);

        reflectionLineSegment.Draw(0.1f, Color.magenta);
        _ballMover.OnReflectionCalculate(reflectionLineSegment);
    }
Ejemplo n.º 27
0
 private void Awake()
 {
     moveBall = GetComponent <MoveBall>();
 }
Ejemplo n.º 28
0
 //relative position of ball 2 with respect of ball 1
 public static MyVector3 RelativePosition(MoveBall b2, MoveBall b1)
 {
     return(MyVector3.Subtract(b2.position, b1.position));
 }
Ejemplo n.º 29
0
 //relative velocity of ball 2 with respect of ball 1
 public static MyVector3 RelativeVelocity(MoveBall b2, MoveBall b1)
 {
     return(MyVector3.Subtract(b2.linearMomentum, b1.linearMomentum).Scale(1 / SnookerBall.mass));
 }
Ejemplo n.º 30
0
 public void DoMoveBallTest2()
 {
     commandMove = new MoveBall(-1, -1, 0, 0);
     commandMove.Do(g);
     Assert.IsTrue(g.Board.Tiles[0, 0] == TileTypes.BallPlayer0);
 }