Beispiel #1
0
        public bool Detect(IBall ball)
        {
            ball.GetSize(out int width, out int height);

            if (!(ball is IElement ballElement))
            {
                return(false);
            }

            if (ballElement.PosX < -width)
            {
                return(true);
            }

            if (ballElement.PosX > screen.Width)
            {
                return(true);
            }

            if (ballElement.PosY < -height)
            {
                return(true);
            }

            if (ballElement.PosY > screen.Height)
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public bool Detect(IBall ball)
        {
            ball.GetSize(out int width, out int height);

            if (ball.Boundary.Min.X < -width)
            {
                return(true);
            }

            if (ball.Boundary.Min.X > screen.Width)
            {
                return(true);
            }

            if (ball.Boundary.Min.Y < -height)
            {
                return(true);
            }

            if (ball.Boundary.Min.Y > screen.Height)
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
 void OnBottomCollision(IBall ball, IBlock block)
 {
     if (ball.Rebounds || !block.Breakable)
     {
         _nextBallSpeed = new Vector2(_nextBallSpeed.X, _nextBallSpeed.Y * -1);
     }
 }
        public static Player GeneratePlayer(IBall ball, string name = "Leo")
        {
            var db = Container.Get <IFootballDatabase>();

            return(new Player(name, Squad.GetRandomSquad(db, "N", "3-4-3"),
                              new Hand(db.GetCards(10).ToList()), ball));
        }
Beispiel #5
0
        private void DetectBrickCollision(IBall ball, bool isDestroyer)
        {
            bool bounce = false;

            bool result = DetectBrickCollision(ball, out List <int> bricksHitList);

            if (result)
            {
                if (isDestroyer)
                {
                    foreach (var number in bricksHitList)
                    {
                        if (!bricks.ElementAt(number).IsBeatable)
                        {
                            bounce = true;
                        }
                    }
                }
                else
                {
                    bounce = true;
                }

                collisionState.SetBrickCollisionState(true, bounce, bricksHitList);
            }
        }
    private void MyGUICall()
    {
        GUILayout.Label("Hello world");
        GUILayout.Label("Coroutines manager is: " + coroutines);

        if (GUILayout.Button("Go to zzz scene"))
        {
            sceneLoader.Load("zzz");
        }

        if (ball == null)
        {
            if (GUILayout.Button("Spawn ball"))
            {
                ball = ballFactory.Create();
            }
        }
        else
        {
            if (GUILayout.Button("Shake ball"))
            {
                ball.Shake();
            }

            if (GUILayout.Button("Stop ball"))
            {
                ball.Stop();
            }

            if (GUILayout.Button("Destroy ball"))
            {
                ball = ballFactory.Destroy(ball);
            }
        }
    }
Beispiel #7
0
        private void DrawTail(IBall ball)
        {
            ITail tail = tailManager.Find(ball);

            if (tail != null)
            {
                int i       = 0;
                int opacity = 150;

                ball.GetSize(out int width, out int height);

                foreach (Vector2 position in tail)
                {
                    ++i;
                    if (i % 14 == 0)
                    {
                        if (opacity < 0)
                        {
                            break;
                        }

                        Color color = Color.Cyan;
                        color.A = (byte)opacity;

                        CircleShape circle = new CircleShape();
                        circle.Position  = new Vector2f(position.X, position.Y);
                        circle.Radius    = (float)width / 2;
                        circle.FillColor = color;
                        render.Draw(circle);

                        opacity = opacity - 60;
                    }
                }
            }
        }
Beispiel #8
0
        private bool BounceBallFromCorner(IBall ball)
        {
            if (!XLeftInside && XRightInside && YTopInside && !YBottomInside)
            {
                ball.BounceCorner(Corner.BottomLeft);
                return(true);
            }

            if (XLeftInside && !XRightInside && YTopInside && !YBottomInside)
            {
                ball.BounceCorner(Corner.BottomRight);
                return(true);
            }

            if (!XLeftInside && XRightInside && !YTopInside && YBottomInside)
            {
                ball.BounceCorner(Corner.TopLeft);
                return(true);
            }

            if (XLeftInside && !XRightInside && !YTopInside && YBottomInside)
            {
                ball.BounceCorner(Corner.TopRight);
                return(true);
            }

            return(false);
        }
        private void Move(AIController AI, IBall ball)
        {
            var step   = AI.SpeedData.Value * Time.deltaTime;
            var target = new Vector2(ball.BallTransform.position.x, AI.transform.position.y);

            AI.transform.position = Vector2.MoveTowards(AI.transform.position, target, step);
        }
Beispiel #10
0
 public Team(Squad starts, Hand subs, IBall ball)
 {
     Squad = starts;
     Hand  = subs;
     Ball  = ball;
     Ball.AddObserver(this);
 }
Beispiel #11
0
 public void Initialize()
 {
     _ball          = _ballsFactory.Create();
     _ballTransform = _ball.Transform;
     _speed         = _settings.ballSpeed / 100f;
     _direction     = Vector2.up;
 }
Beispiel #12
0
        public void Create(IBall ball, BrickType type)
        {
            switch (type)
            {
            case BrickType.ThreeBalls:
            {
                IPad pad = ballManager.GetPadAssignedToBall(ball);
                ballBuilder.Create(pad);
                ballBuilder.Create(pad);
                break;
            }

            case BrickType.DestroyerBall:
            {
                ITail tail = new Tail {
                    FireBallTimerCallback = fireBallCounter.FireBallTimerHandler
                };
                tailManager.Add(ball, tail);
                break;
            }

            default:
                break;
            }
        }
Beispiel #13
0
        public IBall ApplyPowerup(PoweredUpData data)
        {
            IBall result = this;

            PoweredUpData.Add(data);
            if (data.ChangeBallDirection)
            {
                result = new BallDirectionDecorator(this);
            }
            if (data.ChangeBallSpeed)
            {
                result = new BallSpeedDecorator(this);
            }
            if (data.ChangePaddleSpeed)
            {
                result = new PaddleSpeedDecorator(this);
            }
            if (data.GivePlayerLife)
            {
                result = new PlayerLifeDecorator(this);
            }
            if (data.MakeBallDeadly)
            {
                result = new DeadlyBallDecorator(this);
            }
            return(result);
        }
Beispiel #14
0
        protected void DetectPadCollision(IBall ball)
        {
            IPad pad = null;

            bool collisionDetected = false;

            foreach (var value in padManager)
            {
                pad = value.Item3;
                if (collisionManager.Detect(pad, ball))
                {
                    collisionDetected = true;

                    CorrectBallPosition(pad, ball);

                    if (pad.Speed > padSpeedToGoBallFaster)
                    {
                        ball.SetFasterSpeed();
                    }

                    break;
                }
            }

            if (collisionDetected)
            {
                collisionState.SetPadCollistionState(true, true, pad);
            }
        }
Beispiel #15
0
 public void Bounce(IBall ball)
 {
     if (collisionState.BounceFromPad)
     {
         collisionManager.Bounce(collisionState.Pad, ball);
     }
 }
Beispiel #16
0
        private bool BounceBallFromCorner(IBall ball)
        {
            if (Flags.OverlapCornerBottomLeft())
            {
                ball.BounceCorner(Corner.BottomLeft);
                return(true);
            }

            if (Flags.OverlapCornerBottomRight())
            {
                ball.BounceCorner(Corner.BottomRight);
                return(true);
            }

            if (Flags.OverlapCornerTopLeft())
            {
                ball.BounceCorner(Corner.TopLeft);
                return(true);
            }

            if (Flags.OverlapCornerTopRight())
            {
                ball.BounceCorner(Corner.TopRight);
                return(true);
            }

            return(false);
        }
Beispiel #17
0
        public void Create(IPad pad)
        {
            IBall ball = Create();

            padManager.SetBallStartPosition(pad, ball);
            ballManager.Add(ball, pad);
        }
Beispiel #18
0
        public bool action(IBall ball)
        {
            IPad pad = padManager.GetFirst();

            padManager.SetBallStartPosition(pad, ball);
            return(true);
        }
Beispiel #19
0
 public void Add(IBall ball, ITail tail)
 {
     if (!tails.ContainsKey(ball))
     {
         tails.Add(ball, tail);
     }
 }
Beispiel #20
0
 public BallController(IBall spriteEntity, IGameManager gameManager):base(gameManager)
 {
     Ball = spriteEntity;
     State = new StartBallState(this, gameManager, PlayerIndex.One);
     View = new BallView(Ball, this );
     GameScore = GameManager["GameScore"] as GameScore;
 }
 public PingPongGameData(Tuple <IGate, IGate> gates, IBall ball, IGameFieldInfo gameFieldInfo, IBallKicker <IBall> ballKicker)
 {
     Gates         = gates;
     Ball          = ball;
     GameFieldInfo = gameFieldInfo;
     BallKicker    = ballKicker;
 }
Beispiel #22
0
        /// <summary>
        /// Check if ball hitted any borders.
        /// if true' the method change ball direction
        /// </summary>
        /// <returns></returns>
        private bool CheckIfBallHitBorders(IBall ball = default(IBall))
        {
            if (ball == null)
            {
                ball = Ball;
            }
            bool isHit = false;

            if (ball.DirectionY <= 0 && ball.Top <= bordersDictionary["Top"].Bottom)
            {
                ball.DirectionY *= -1;
                isHit            = true;
            }
            if (ball.DirectionX <= 0 && ball.Left <= bordersDictionary["Left"].Right)
            {
                ball.DirectionX *= -1;
                isHit            = true;
            }
            if (ball.DirectionX >= 0 && ball.Right >= bordersDictionary["Right"].Left)
            {
                ball.DirectionX *= -1;
                isHit            = true;
            }
            return(isHit);
        }
Beispiel #23
0
 void OnRightCollision(IBall ball, IBlock block)
 {
     if (ball.Rebounds || !block.Breakable)
     {
         _nextBallSpeed = new Vector2(_nextBallSpeed.X * -1, _nextBallSpeed.Y);
     }
 }
Beispiel #24
0
    public void Pass()
    {
        float yGround = 0 + 0.15f;

        Vector3 passOrigin = transform.position;

        passOrigin.y = yGround;
        Vector3 passDirection = new Vector3(xzController.XLook, 0, xzController.ZLook);

        RaycastHit[] hits = Physics.RaycastAll(passOrigin, passDirection, maxPassDistance);
        float        nearestPlayerHitDistance = Mathf.Infinity;
        Player       nearestPlayerHit         = null;

        foreach (RaycastHit hit in hits)
        {
            Player player = hit.collider.GetComponent <Player>();
            if (player != null && hit.distance < nearestPlayerHitDistance)
            {
                nearestPlayerHitDistance = hit.distance;
                nearestPlayerHit         = player;
            }
        }

        if (nearestPlayerHit != null && nearestPlayerHit.CanReceivePass)
        {
            nearestPlayerHit.HoldBall(heldBall);
            Debug.Log("Pass Recipient:" + nearestPlayerHit.transform.parent.name);
            heldBall = null;
            SoundManager.Instance.Play(successfulPass);
        }
        else
        {
            Debug.Log("No Pass Recipient.");
        }
    }
Beispiel #25
0
        private void DrawTail(Graphics g, IBall ball)
        {
            ITail tail = Game.TailManager.Find(ball);

            if (tail != null)
            {
                int i       = 0;
                int opacity = 150;
                foreach (Position position in tail)
                {
                    ++i;
                    if (i % 12 == 0)
                    {
                        if (opacity < 0)
                        {
                            opacity = 0;
                        }

                        ball.GetSize(out var width, out var height);

                        SolidBrush tailBrush = new SolidBrush(Color.FromArgb(opacity, Color.LightCoral));
                        g.FillEllipse(
                            tailBrush,
                            new Rectangle(position.X, position.Y, width, height));
                        tailBrush.Dispose();

                        opacity = opacity - 40;
                    }
                }
            }
        }
Beispiel #26
0
 private void DetectScreenCollision(IBall ball)
 {
     if (screenCollisionManager.Detect(ball))
     {
         collisionState.SetScreenCollistionState(true, false);
     }
 }
Beispiel #27
0
        public bool DetectAndVerify(IBall ball)
        {
            if (!(ball is IElement ballElement))
            {
                return(false);
            }

            if (ballElement.PosX < 0)
            {
                ballElement.PosX = 0;
                return(ball.Bounce(Edge.Right));
            }

            if (ballElement.PosX > screen.Width - ballElement.Width)
            {
                ballElement.PosX = screen.Width - ballElement.Width;
                return(ball.Bounce(Edge.Left));
            }

            if (ballElement.PosY < 0)
            {
                ballElement.PosY = 0;
                return(ball.Bounce(Edge.Bottom));
            }

            if (ballElement.PosY > screen.Height - ballElement.Height)
            {
                ballElement.PosY = screen.Height - ballElement.Height;
                return(ball.Bounce(Edge.Top));
            }

            return(false);
        }
Beispiel #28
0
        public bool DetectAndVerify(IBall ball)
        {
            if (ball.Boundary.Min.X < 0)
            {
                ball.Boundary.Min = new Vector2(0, ball.Boundary.Min.Y);
                return(ball.Bounce(Edge.Left));
            }

            if (ball.Boundary.Min.X > screen.Width - ball.Boundary.Size.X)
            {
                ball.Boundary.Min = new Vector2(screen.Width - ball.Boundary.Size.X, ball.Boundary.Min.Y);
                return(ball.Bounce(Edge.Right));
            }

            if (ball.Boundary.Min.Y < 0)
            {
                ball.Boundary.Min = new Vector2(ball.Boundary.Min.X, 0);
                return(ball.Bounce(Edge.Top));
            }

            if (ball.Boundary.Min.Y > screen.Height - ball.Boundary.Size.Y)
            {
                ball.Boundary.Min = new Vector2(ball.Boundary.Min.X, screen.Height - ball.Boundary.Size.Y);
                return(ball.Bounce(Edge.Bottom));
            }

            return(false);
        }
Beispiel #29
0
        /// <summary>
        /// Shoot ball from plank
        /// </summary>
        private void BallHitPlank(IBall ball = default(IBall))
        {
            /*
             * הפונקציה שולחת את הכדור לכיוון מסויים בהתאם למיקומו על הקרש
             * הפונקציב מתייחסת אל מרכז הקרש כאל מרכז של עיגול
             * הפונקציה מתייחסת אל הכדור כאילו היה על המעגל ואז מחפשת את המיקום שלו
             * היחס בין הX לY הוא כיוון הכדור
             */
            if (ball == null)
            {
                ball = Ball;
            }
            ball.DirectionY = -1;
            float  rBall       = ball.Width / 2;                                // Radius of ball
            float  rPlank      = Plank.Width / 2 + ball.Width + ball.Speed / 2; //Radius of circle of plank
            PointF centerPlank = new PointF(Plank.Left + Plank.Width / 2, Plank.Top);

            double[] y              = Geometry.FindPointOnCircleY(rPlank, centerPlank.X, centerPlank.Y, ball.Left + rBall);
            PointF   pointOnCircle  = new PointF(ball.Left + rBall, (float)Math.Min(y[0], y[1]));
            float    relationPoints = Math.Abs((pointOnCircle.X - centerPlank.X) / (pointOnCircle.Y - centerPlank.Y));

            ball.DirectionX = relationPoints;
            if (ball.Left + rBall < centerPlank.X)
            {
                ball.DirectionX *= -1;
            }
        }
Beispiel #30
0
        private void Bounce(IReadOnlyCollection <IBoundary> obstacles, IBall ball, out DegreeType degreeType)
        {
            degreeType = DegreeType.None;

            if (obstacles.Count == 1)
            {
                BounceBall(obstacles.First(), ball, out degreeType);
            }
            else if (obstacles.Count > 0)
            {
                if (IsPosXEqual(obstacles))
                {
                    BallBounceFromVertEdge(ball);
                }
                else if (IsPosYEqual(obstacles))
                {
                    BallBounceFromHorizEdge(ball);
                }
                else
                {
                    // bounce with 3 Bricks e.g. set in following way:
                    //    ==
                    //    o=
                    //
                    ball.BounceBack();
                }
            }
        }
Beispiel #31
0
        private void CorrectBallPosition(IPad pad, IBall ball)
        {
            Vector2 previous = ball.Boundary.Min;

            while (collisionManagerForMoveReversion.Detect(pad, ball))
            {
                if (!ball.MoveBall(true))
                {
                    ball.Boundary.Min = previous;
                    padManager.RestartBallYPosition(pad, ball);
                    return;
                }

                previous = ball.Boundary.Min;
                ball.SavePosition();

                foreach (IBorder border in borderManager)
                {
                    if (collisionManagerForMoveReversion.Detect(border, ball))
                    {
                        padManager.SetBallStartPosition(pad, ball);
                        break;
                    }
                }

                if (screenCollisionManager.DetectAndVerify(ball))
                {
                    padManager.SetBallStartPosition(pad, ball);
                    break;
                }
            }

            ball.Boundary.Min = previous;
        }
Beispiel #32
0
 public Ball(ContentManager content, Paddle p)
 {
     ballText = content.Load<Texture2D>(@"images/Game/Ball");
     ballRect = new Rectangle(720, 150, 15, 15);
      _content = content;
      Paddle = p;
      this.state = new BallStart(this, this.Paddle);
      XSpeed = 0;
      Direction = 1;
 }
Beispiel #33
0
 public void Initialize(IBall ball)
 {
     ball.Velocity = SpawnVelocity;
 }
Beispiel #34
0
 public void Render(IBall ball)
 {
     Primitives.DrawRectangle(ball.Position.X - 5, ball.Position.Y - 5, ball.Position.X + 5, ball.Position.Y + 5, new Color(1, 1, 1), 1);
 }
Beispiel #35
0
        public void Update(GameTime gt, Tetris tetris)
        {
            kState = Keyboard.GetState();
               if (Direction == 1)
               {
               ballRect.X = ballRect.X - XSpeed;
               }else{
               ballRect.X = ballRect.X + XSpeed;
               }
               if (kState.IsKeyDown(Keys.Space) && !GameStarted && tetris.TetDone)
               {
               XSpeed = 10;
               GameStarted = true;
               this.state = new Move0PercentUp(this);
               }
               if (GameStarted == true)
               {
               if (ballRect.Y <= 0)
               {
                   Side = true;
               }
               else if (ballRect.Y >= 630)
               {
                   Side = false;
               }
               if (ballRect.X + ballRect.Width >= Paddle.PaddleRect.X && ballRect.Y + ballRect.Height >= Paddle.PaddleRect.Y && ballRect.Y + ballRect.Height <= Paddle.PaddleRect.Y + Paddle.PaddleRect.Height)
               {
                    if (ballRect.Y <= Paddle.PaddleRect.Y + 10)
                    {
                        Side = false;
                        this.state = new Move10PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Y + 20)
                    {
                        Side = false;
                        this.state = new Move20PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Y + 30)
                    {
                        Side = false;
                        this.state = new Move30PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Y + 40)
                    {
                        Side = false;
                        this.state = new Move40PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Y + 50)
                    {
                        Side = false;
                        this.state = new Move50PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Center.Y)
                    {
                        this.state = new Move0PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Y + 70)
                    {
                        Side = true;
                        this.state = new Move60PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Y + 80)
                    {
                        Side = true;
                        this.state = new Move70PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Y + 90)
                    {
                        Side = true;
                        this.state = new Move80PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Y + 100)
                    {
                        Side = true;
                        this.state = new Move90PercentUp(this);
                    }
                    else if (ballRect.Y <= Paddle.PaddleRect.Y + 110 && ballRect.Y >= Paddle.PaddleRect.Y + 100)
                    {
                        Side = true;
                        this.state = new Move100PercentUp(this);
                    }
                    //this.state = new Move0PercentUp(this);

                   Direction = 1;
               }

                  // Direction = 1;
               if (ballRect.X <= 0)
               {
                   Direction = 0;
               }

               if (ballRect.X > 1280)
               {
                   //ballRect = new Rectangle(720, 150, 15, 15);
                   tetris.ArkScore = tetris.ArkScore - 500;
                   GameStarted = false;
                   this.state = new BallStart(this, this.Paddle);
                   XSpeed = 0;
                   Direction = 1;
               }
               }

               this.state.Update(gt);
        }
Beispiel #36
0
 public BallController(IBall spriteEntity, IBallState ballState, IGameManager gameManager)
 {
     Ball = spriteEntity;
     State = ballState;
     GameManager = gameManager;
 }
Beispiel #37
0
 public BallView(IBall ball, BallController controller)
 {
     Ball =ball;
     Controller  = controller;
 }
Beispiel #38
0
 public void Initialize(IBall ball)
 {
     ball.Velocity = new Point(random.Next(-10, 10), random.Next(-10, 10));
 }