Exemple #1
0
 // Start is called before the first frame update
 void Start()
 {
     name             = transform.parent.name;
     ballDur          = GetComponent <BallDurability>();
     ballCollision    = GetComponent <BallCollision>();
     nameplateDisplay = GetComponent <NameplateDisplay>();
 }
Exemple #2
0
    void Start()
    {
        ballCollision         = GetComponent <BallCollision>();
        ballCollision.hasBomb = true;
        cam = FindObjectOfType <Camera>();

        worldOffset  = new Vector3(0f, 1f, 0f);
        canvasOffset = new Vector3(0f, 50f, 0f);
    }
Exemple #3
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            BallCollision collision = AdjustBallPositionWithScreenBounds(ref ballRect, ref ballVelocity);

            if (collision > 0)
            {
                passedCenter = false;

                float newY = (new Random().Next(80) + 1) / 10.0f;
                ballVelocity.Y = ballVelocity.Y > 0 ? newY : -newY;
            }

            if (collision == BallCollision.RightMiss || collision == BallCollision.LeftMiss)
            {
                RestartGame();
            }

            if (passedCenter == false && ballVelocity.X > 0 && (ballRect.X + kBallWidth >= GraphicsDevice.Viewport.Bounds.Center.X))
            {
                SimulateRestOfTurn();
                passedCenter = true;
            }

            int ballCenter     = (int)predictedBallHeight + (kBallHeight / 2);
            int aiPaddleCenter = aiPaddleRect.Center.Y;

            if (predictedBallHeight > 0 && ballCenter != aiPaddleCenter)
            {
                if (ballCenter < aiPaddleCenter)
                {
                    aiPaddleRect.Y -= kMaxAIPaddleVelocity;
                }
                else if (ballCenter > aiPaddleCenter)
                {
                    aiPaddleRect.Y += kMaxAIPaddleVelocity;
                }

                if (Math.Abs(ballCenter - aiPaddleCenter) < kMaxAIPaddleVelocity)
                {
                    aiPaddleRect.Y = ballCenter - (kPaddleHeight / 2);
                }
            }

            base.Update(gameTime);
        }
Exemple #4
0
        private void SimulateRestOfTurn()
        {
            Rectangle currentBallRect     = ballRect;
            Vector2   currentBallVelocity = ballVelocity;

            bool done = false;

            while (!done)
            {
                BallCollision result = AdjustBallPositionWithScreenBounds(ref currentBallRect, ref currentBallVelocity);
                done = (result == BallCollision.RightMiss || result == BallCollision.RightPaddle);
            }

            predictedBallHeight = currentBallRect.Y;
        }
Exemple #5
0
        private BallCollision AdjustBallPositionWithScreenBounds(ref Rectangle enclosingRect, ref Vector2 velocity)
        {
            BallCollision collision = BallCollision.None;

            enclosingRect.X += (int)velocity.X;
            enclosingRect.Y += (int)velocity.Y;

            if (enclosingRect.Y >= GraphicsDevice.Viewport.Height - kBallHeight)
            {
                velocity.Y *= -1;
            }
            else if (enclosingRect.Y <= 0)
            {
                velocity.Y *= -1;
            }

            if (aiPaddleRect.Intersects(enclosingRect))
            {
                velocity.X *= -1;
                collision   = BallCollision.RightPaddle;
            }
            else if (ourPaddleRect.Intersects(enclosingRect))
            {
                velocity.X *= -1;
                collision   = BallCollision.LeftPaddle;
            }
            else if (enclosingRect.X >= GraphicsDevice.Viewport.Width - kBallWidth)
            {
                collision = BallCollision.RightMiss;
            }
            else if (enclosingRect.X <= 0)
            {
                collision = BallCollision.LeftMiss;
            }

            return(collision);
        }
 public void Hit(BallCollision ballCollision)
 {
     this.block.Hit();
 }
Exemple #7
0
 public static BallStepResult StepGolfBall(
     Entity entity,
     ref float angularVelocity)
 {
     return(BallCollision.Step(GolfHelper.PhysicsProperties, entity, ref angularVelocity, (IBallContactListener)GolfHelper.Listener));
 }
Exemple #8
0
 public override void Init()
 {
     sprite        = Resources.Load <Sprite>("Images/Icon/Grow Icon");
     ballCollision = GetComponent <BallCollision>();
 }
 public static BallStepResult StepGolfBall(Entity entity, float angularVelocity)
 {
     return(BallCollision.Step(PhysicsProperties, entity, angularVelocity, Listener));
 }
Exemple #10
0
 private void Start()
 {
     ballCollision = GetComponent <BallCollision>();
 }
        public static void Update(GameTime gameTime, PlayerTypes type, IPlayer current)
        {
            RegenManager.EnergyRegenUpdate();
            current.Ship.Specialty.Update(gameTime, current);
            ControlsPlayer(type);

            #region Ball Players Collisions

            // KOGATO TEPAT PURVIQ
            ballColliding = BallCollision.Collide(
                FirstPlayer.Instance.Ship,
                BallControls.BallSecond);
            if (ballColliding)
            {
                firstPlayerHitCounter = 0;
                SecondPlayer.Instance.Ship.Attack(FirstPlayer.Instance.Ship);
            }

            ballColliding = BallCollision.Collide(
                SecondPlayer.Instance.Ship,
                BallControls.BallFirst);
            if (ballColliding)
            {
                secondPlayerHitCounter = 0;
                FirstPlayer.Instance.Ship.Attack(SecondPlayer.Instance.Ship);
            }
            #endregion

            #region Ball Boss Collisions
            // 5 - const i za spawn na bossa
            if (activateBossWatch.Elapsed.TotalSeconds > BossActivationSeconds)
            {
                // topchEto na pyrviq igrach
                bossBallCollide = OctopusCollision.BossBallCollide(BallControls.BallFirst);
                if (bossBallCollide)
                {
                    firstPlayerHitCounter = 0;
                    Boss.Instance.Health -= FirstPlayer.Instance.Ship.Damage;  // ne e dobre da e tuk, no Attack() priema Ship, a ne Boss
                }

                // topchEto na vtoriq igrach
                bossBallCollide = OctopusCollision.BossBallCollide(BallControls.BallSecond);
                if (bossBallCollide)
                {
                    secondPlayerHitCounter = 0;
                    Boss.Instance.Health  -= SecondPlayer.Instance.Ship.Damage; // ne e dobre da e tuk, no Attack() priema Ship, a ne Boss
                }
            }
            #endregion

            #region BossVsPlayer Collisions

            if (activateBossWatch.Elapsed.TotalSeconds > BossActivationSeconds)
            {
                Boss.Instance.Update();
                bossVsShipCollide = OctopusCollision.Collide(current.Ship);
                if (bossVsShipCollide)
                {
                    bossHitCounter = 0;
                    Boss.Instance.Attack(current.Ship);
                    if (current is FirstPlayer)
                    {
                        playerFlagBossCollide = 1;
                    }
                    else
                    {
                        playerFlagBossCollide = 0;
                    }
                }
            }

            #endregion
        }
Exemple #12
0
    void Awake()
    {
        GameObject gameMaster = GameObject.Find("GameMaster");

        if (stats == null)
        {
            stats = gameMaster.GetComponent <GameStats>();
        }
        if (stats == null)
        {
            stats = gameMaster.AddComponent <GameStats>();
        }
        if (level == null)
        {
            level = Utility.GetLevelData();
        }
        if (level == null)
        {
            Debug.LogError("LevelData is null");
        }
        if (debugger == null)
        {
            debugger = gameMaster.GetComponent <Debugger>();
        }
        if (debugger == null)
        {
            debugger = gameMaster.AddComponent <Debugger>();
        }
        if (ballCollision == null)
        {
            ballCollision = GetComponent <BallCollision>();
        }
        if (ballCollision == null)
        {
            Debug.LogError("ballCollision is null");
        }
        if (anchorRb == null)
        {
            anchorRb = transform.parent.GetComponent <Rigidbody2D>();
        }
        if (anchorRb == null)
        {
            Debug.LogError("anchorRb is null");
        }
        if (selfCollider == null)
        {
            selfCollider = GetComponent <CircleCollider2D>();
        }
        if (selfCollider == null)
        {
            Debug.LogError("selfCollider is null");
        }
        if (selfRb == null)
        {
            selfRb = GetComponent <Rigidbody2D>();
        }
        if (selfRb == null)
        {
            Debug.LogError("selfRb is null");
        }
        if (springJoint == null)
        {
            springJoint = GetComponent <SpringJoint2D>();
        }
        if (springJoint == null)
        {
            Debug.LogError("springJoint is null");
        }
    }
Exemple #13
0
 public override void DoAbility()
 {
     ballCollision             = GetComponent <BallCollision>();
     ballCollision.critChance += critChanceIncrement;
 }