private void Rebound(IReboundStrategy reboundStrategy, Vector2 surfaceNormal, Paddle p, ArenaObject obj) { var dir = reboundStrategy.ReboundDirection(this, surfaceNormal, p, obj); //var pos = reboundStrategy.ReboundPosition(Position, Direction, surfaceNormal, p, obj); Direction = dir; //SetPosition(pos); }
public void OnCollision(Paddle paddle, ArenaObject arenaObject) { Vector2 center = ArenaFacade.Instance.ArenaDimensions.Center; float radius = ArenaFacade.Instance.ArenaDimensions.Radius; Vector2 collisionNormal = null; IReboundStrategy reboundStrategy = null; if (paddle != null)// collision with a paddle { float paddleAngle = paddle.GetCenterAngle(); Vector2 paddleCenter = Utilities.GetPointOnCircle(center, radius, paddleAngle); collisionNormal = (center - paddleCenter).Normalize(); ReboundTemplate rbTemplate = new ReboundFromPaddle(paddle.CurrentAngularSpeed, bType, null, Obstacles.ArenaObjectType.NonPassable); reboundStrategy = rbTemplate.ChooseStrategy(); //switch (bType) //{ // case BallType.Deadly: // reboundStrategy = new BallDeadlyStrategy(); // break; // case BallType.Normal: // if (paddle.CurrentAngularSpeed < 0) // reboundStrategy = new PaddleMovingLeft(); // else if (paddle.CurrentAngularSpeed > 0) // reboundStrategy = new PaddleMovingRight(); // else //if (coll.AngularSpeed == 0) // reboundStrategy = new PaddleNotMoving(); // break; //} } else if (arenaObject != null)// collision with an arena object { ReboundTemplate rbTemplate = new ReboundFromArenaObject(0, BallType.Normal, arenaObject, arenaObject.Type); reboundStrategy = rbTemplate.ChooseStrategy(); var offset = (Direction * Diameter * 0.5f); Vector2 impactPos = Position + offset; collisionNormal = arenaObject.GetCollisionNormal(impactPos, Direction); } Rebound(reboundStrategy, collisionNormal, paddle, arenaObject); }