Inheritance: PhysicsEntity
コード例 #1
0
        public TouchScreenInput(CCLayer Owner,PaddleEntity controledEntity)
        {
            this.owner = Owner;
            mControledEntity = controledEntity;

            touchListener = new CCEventListenerTouchAllAtOnce ();
            touchListener.OnTouchesBegan = OnTouchesBegan;
            touchListener.OnTouchesMoved = HandleTouchesMoved;
            touchListener.OnTouchesEnded = OnTouchesEnded;
            owner.AddEventListener (touchListener);
        }
コード例 #2
0
        public bool isCollideWithRotatedPaddle(PaddleEntity mPaddle, float angle)
        {
            bool collide=false;
            if (Math.Abs (angle) > 45) {
                VelocityAngle = -angle / 3;
            } else {
                VelocityAngle = -angle/2;
            }

            rotatedX = (float)Math.Cos (angle) * (this.PositionX-mPaddle.PositionX) - (float)Math.Sin (angle) * (this.PositionY-mPaddle.PositionY)+mPaddle.PositionX;
            rotatedY = (float)Math.Sin (angle) * (this.PositionX-mPaddle.PositionX) + (float)Math.Cos (angle) * (this.PositionY-mPaddle.PositionY)+mPaddle.PositionY;

            rotatedBallRect = new CCRect (rotatedX-this.BoundingWidth/2, rotatedY-this.BoundingHeight/2, this.BoundingWidth, this.BoundingHeight);
            flatPaddleRect = new CCRect (mPaddle.PositionX-mPaddle.flatBoundingBoxWidth/2, 50f-mPaddle.flatBoundingBoxHeight/2, mPaddle.flatBoundingBoxWidth, mPaddle.flatBoundingBoxHeight);

            collide = BallPaddleRectIntersects (rotatedBallRect, flatPaddleRect);

            if (rotatedBallRect.Center.Y < flatPaddleRect.Center.Y)
            {
                collide = false;
            }
            if (rotatedBallRect.Center.X < (flatPaddleRect.Center.X - mPaddle.flatBoundingBoxWidth / 2))
            {
                collide = false;
            }
            if (this.YVelocity > 0) {
                collide = false;
            }

            if (collide) {

            //				Console.WriteLine("X: "+(mPaddle.PositionX-mPaddle.flatBoundingBoxWidth/2).ToString());
            //				Console.WriteLine("Y: "+(50f-mPaddle.flatBoundingBoxHeight/2).ToString());
            //				Console.WriteLine("width: "+mPaddle.flatBoundingBoxWidth.ToString());
            //				Console.WriteLine("height: "+mPaddle.flatBoundingBoxHeight.ToString());
                Console.WriteLine("ball: "+rotatedBallRect.MinY.ToString());
                Console.WriteLine ("paddle: "+flatPaddleRect.MaxY.ToString ());

                Console.WriteLine ("-------------------------------------");

                gamelayer.RemoveChild (draw);
                draw = new CCDrawNode ();
                draw.DrawRect (rotatedBallRect,new CCColor4B(0,0,0));
                draw.DrawRect (flatPaddleRect, new CCColor4B(0,0,0));

                gamelayer.AddChild (draw);

                //Thread.Sleep (1000);
            }

            return collide;
        }
コード例 #3
0
        private void AddEntity()
        {
            mPaddle = new PaddleEntity ();
            mPaddle.PositionX = gameplayLayer.VisibleBoundsWorldspace.Center.X;
            mPaddle.PositionY = 50;
            gameplayLayer.AddChild (mPaddle);

            mBall = new BallEntity (gameplayLayer);
            mBall.Position = gameplayLayer.VisibleBoundsWorldspace.Center;
            mBall.Visible = false;
            mBall.YVelocity = -350;
            gameplayLayer.AddChild  (mBall);
        }