Inheritance: MonoBehaviour
コード例 #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));
    }
コード例 #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;
        }
    }
コード例 #3
0
ファイル: MoveBallTest.cs プロジェクト: mloup/diaballik
        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);
        }
コード例 #4
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveBall {
        };

        return(job.Schedule(this, inputDeps));
    }
コード例 #5
0
ファイル: MoveBallTest.cs プロジェクト: mloup/diaballik
        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]);
                }
            }
        }
コード例 #6
0
ファイル: ManageGame.cs プロジェクト: kdhageman/pong
 private void Awake()
 {
     Assert.IsNotNull(this.guiText);
     Assert.IsNotNull(this.ball);
     this._moveBall = this.ball.GetComponent <MoveBall>();
     Assert.IsNotNull(this._moveBall);
 }
コード例 #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;
            }
        }
    }
コード例 #8
0
ファイル: Global.cs プロジェクト: Emilien-Gts/mds-m1-unity-3d
 // 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>();
 }
コード例 #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");
    }
コード例 #10
0
    private void OnEnable()
    {
        /// Publishers.
        _moveBall = FindObjectOfType <MoveBall>();
        Assert.IsNotNull(_moveBall);

        /// Subscribe to events.
        _moveBall.HitBackWall += OnBallHitBackWall;
    }
コード例 #11
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new MoveBall {
            forceAppliedMult = PlayTimeSettings.forceAppliedMult, forceMult = PlayTimeSettings.forceMult
        };


        return(job.Schedule(this, inputDeps));
    }
コード例 #12
0
ファイル: MainForm.cs プロジェクト: NatVSher/Balls
 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();
     }
 }
コード例 #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
    }
コード例 #14
0
ファイル: GameTest.cs プロジェクト: mloup/diaballik
        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);
        }
コード例 #15
0
ファイル: BallsSwitcher.cs プロジェクト: lalune505/ball
    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;
    }
コード例 #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>();
    }
コード例 #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>();
    }
コード例 #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);
 }
コード例 #19
0
    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);
        }
    }
コード例 #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);
    }
コード例 #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();
    }
コード例 #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);
         * }
         */
    }
コード例 #23
0
ファイル: GameManager.cs プロジェクト: hhdfgg/yoketoru
    // 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>();
    }
コード例 #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;
        }
    }
コード例 #25
0
ファイル: MoveBallsSystem.cs プロジェクト: stramit/Graphics
    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);
    }
コード例 #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);
    }
コード例 #27
0
 private void Awake()
 {
     moveBall = GetComponent <MoveBall>();
 }
コード例 #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));
 }
コード例 #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));
 }
コード例 #30
0
ファイル: MoveBallTest.cs プロジェクト: mloup/diaballik
 public void DoMoveBallTest2()
 {
     commandMove = new MoveBall(-1, -1, 0, 0);
     commandMove.Do(g);
     Assert.IsTrue(g.Board.Tiles[0, 0] == TileTypes.BallPlayer0);
 }