public void Move(Ball ball, float frameTimeInSeconds) { if (isPlayer) return; float a = ball.PositionX - PositionX; velocityX = Math.Sign(a) * Math.Min (GetMaxSpeedX(), Math.Abs(a/frameTimeInSeconds)); PositionX += velocityX * frameTimeInSeconds; a = VisibleBoundsWorldspace.MaxY - PositionY - ContentSize.Height; int directionY = -Math.Sign(ball.VelocityY); velocityY = Math.Min(directionY * GetMaxSpeedY(), a/frameTimeInSeconds); PositionY += velocityY * frameTimeInSeconds; }
void Init() { CCRect r = new CCRect (0,0, screenSize.Width,screenSize.Height); background = new CCSprite("images/bggrass", r); background.MaximizeTextureRect (); playerMarking = new CCSprite ("images/bgmarking"); enemyMarking = new CCSprite ("images/bgmarking"); //logo1 = new CCSprite ("images/logopong"); //logo2 = new CCSprite ("images/logoganymede"); playerPlatform = new Platform (true); enemyPlatform = new Platform (false); ball = new Ball(); string scoreText = playerScore.ToString () + " : " + enemyScore.ToString (); scoreLabel = new CCLabel( scoreText, "fonts/arial", 100); Layout(); AddChild (background); AddChild (playerMarking); AddChild (enemyMarking); //AddChild (logo1); //AddChild (logo2); AddChild (scoreLabel); AddChild (playerPlatform); AddChild (enemyPlatform); AddChild (ball); }
public bool IsCollision(Ball ball) { return ball.BoundingBoxTransformedToParent.IntersectsRect (BoundingBoxTransformedToParent) && Math.Sign(ball.VelocityY) == Math.Sign(PositionY-ball.PositionY); }