Example #1
0
        public static Animation FromAnimationSave(AnimationChainSave animationSave)
        {
            //这个类没有构造函数,所以编译器自动会添加一个空的构造函数
            Animation toReturn = new Animation ();

            toReturn.Name = animationSave.Name;

            //读取frame(AnimationFrameSave)中的所有动画数据
            foreach (var frame in animationSave.Frames)
            {
                CCRect rectangle;

                rectangle = new CCRect (
                    frame.LeftCoordinate,
                    frame.TopCoordinate,
                    frame.RightCoordinate - frame.LeftCoordinate,
                    frame.BottomCoordinate - frame.TopCoordinate);

                var duration = TimeSpan.FromSeconds (frame.FrameLength);

                //toReturn.frames是一个frame的集合
                //每一个frame是动作的一步
                //AddFrame就是把读取到的frame添加到这个list里
                toReturn.AddFrame (rectangle, duration, flipHorizontal:frame.FlipHorizontal);
            }

            return toReturn;
        }
Example #2
0
        public CCFollow(Node followedNode, CCRect rect)
        {
            Debug.Assert(followedNode != null);

            this._followedNode = followedNode;
            this._isBoundaryFullyCovered = false;
            this.IsBoundarySet = true;

            CCSize winSize = Director.SharedDirector.DesignSize;
            this._fullScreenSize = new CCPoint(winSize.Width, winSize.Height);
            this._halfScreenSize = this._fullScreenSize * 0.5f;

            this._leftBoundary = -((rect.Origin.X + rect.Size.Width) - this._fullScreenSize.X);
            this._rightBoundary = -rect.Origin.X;
            this._topBoundary = -rect.Origin.Y;
            this._bottomBoundary = -((rect.Origin.Y + rect.Size.Height) - this._fullScreenSize.Y);

            if (this._rightBoundary < this._leftBoundary)
            {
                //screen width is larger than world's boundary width set both in the middle of the world
                this._rightBoundary = this._leftBoundary = (this._leftBoundary + this._rightBoundary) / 2;
            }
            if (this._topBoundary < this._bottomBoundary)
            {
                //screen width is larger than world's boundary width set both in the middle of the world
                this._topBoundary = this._bottomBoundary = (this._topBoundary + this._bottomBoundary) / 2;
            }

            if ((this._topBoundary == this._bottomBoundary) && (this._leftBoundary == this._rightBoundary))
            {
                this._isBoundaryFullyCovered = true;
            }
        }
Example #3
0
		private void CreateHowtoLabel()
		{
			float backgroundWidth = howToImage.ScaledContentSize.Width;
			const float backgroundHeight = 36;

			labelBackground = new CCDrawNode ();

			var rect = new CCRect (
				-backgroundWidth / 2.0f, -backgroundHeight / 2.0f, 
				backgroundWidth , backgroundHeight );
			labelBackground.DrawRect (
				rect, CCColor4B.Black);
			labelBackground.PositionX = ContentSize.Center.X;
			labelBackground.PositionY = 74;
			mainLayer.AddChild (labelBackground);


			howToLabel = new CCLabel(
				"Touch and move on the left side of the screen to move.\nTap on the right side to jump.", 
				"fonts/Aldrich-Regular.ttf", 12, CCLabelFormat.SystemFont);
			howToLabel.PositionX = ContentSize.Center.X;
			howToLabel.Scale = .5f;
			howToLabel.PositionY = 74;
			howToLabel.HorizontalAlignment = CCTextAlignment.Center;
			howToLabel.VerticalAlignment = CCVerticalTextAlignment.Center;
			howToLabel.IsAntialiased = false;

			mainLayer.AddChild (howToLabel);
		}
Example #4
0
        public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
        {
            //application.SupportedOrientations = CCDisplayOrientation.LandscapeRight | CCDisplayOrientation.LandscapeLeft;
            //application.AllowUserResizing = true;
            //application.PreferMultiSampling = false;
            application.ContentRootDirectory = "Content";


            CCRect boundsRect = new CCRect(0.0f, 0.0f, 960, 640);

			sharedViewport = new CCViewport(new CCRect (0.0f, 0.0f, 1.0f, 1.0f));

            sharedWindow = mainWindow;
            sharedCamera = new CCCamera(boundsRect.Size, new CCPoint3(boundsRect.Center, 100.0f), new CCPoint3(boundsRect.Center, 0.0f));

            mainWindow.SetDesignResolutionSize(960, 640, CCSceneResolutionPolicy.ShowAll);

            #if WINDOWS || WINDOWSGL || WINDOWSDX 
			//application.PreferredBackBufferWidth = 1024;
			//application.PreferredBackBufferHeight = 768;
            #elif MACOS
            //application.PreferredBackBufferWidth = 960;
            //application.PreferredBackBufferHeight = 640;
            #endif

            #if WINDOWS_PHONE8
            application.HandleMediaStateAutomatically = false; // Bug in MonoGame - https://github.com/Cocos2DXNA/cocos2d-xna/issues/325
            #endif

            CCSpriteFontCache.FontScale = 0.6f;
            CCSpriteFontCache.RegisterFont("arial", 12, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 38, 50, 64);
            CCSpriteFontCache.RegisterFont("MarkerFelt", 16, 18, 22, 32);
            CCSpriteFontCache.RegisterFont("MarkerFelt-Thin", 12, 18);
            CCSpriteFontCache.RegisterFont("Paint Boy", 26);
            CCSpriteFontCache.RegisterFont("Schwarzwald Regular", 26);
            CCSpriteFontCache.RegisterFont("Scissor Cuts", 26);
            CCSpriteFontCache.RegisterFont("A Damn Mess", 26);
            CCSpriteFontCache.RegisterFont("Abberancy", 26);
            CCSpriteFontCache.RegisterFont("Abduction", 26);

            //sharedDirector = new CCDirector();
            //director.DisplayStats = true;
            //director.AnimationInterval = 1.0 / 60;


//            if (sharedWindow.WindowSizeInPixels.Height > 320)
//            {
//                application.ContentSearchPaths.Insert(0,"HD");
//            }

            //sharedWindow.AddSceneDirector(sharedDirector);

            CCScene scene = new CCScene(sharedWindow);
			scene.Camera = sharedCamera;

            CCLayer layer = new TestController();

            scene.AddChild(layer);
            sharedWindow.RunWithScene(scene);
        }
 public bool BallPaddleRectIntersects(CCRect r1, CCRect r2)
 {
     if (r1.MinY < r2.MaxY) {
         return true;
     } else {
         return false;
     }
 }
Example #6
0
 public CCSpriteFrame(CCSize contentSize, CCTexture2D texture, CCRect textureRectInPxls, 
     CCSize originalSizeInPxls, bool rotated=false, CCPoint? offsetInPxls=null)
 {
     TextureRectInPixels = textureRectInPxls;
     ContentSize = contentSize;
     OffsetInPixels = offsetInPxls ?? CCPoint.Zero;
     OriginalSizeInPixels = originalSizeInPxls;
     IsRotated = rotated;
     Texture = texture;
 }
Example #7
0
        public CCSize TileSize { get; set; }            // The size of this tile in unscaled pixels

        #endregion Properties

        public CCRect RectForGID(uint gid)
        {
            CCRect rect = new CCRect();
            rect.Size = TileSize;
            gid &= CCTMXTileFlags.FlippedMask;
            gid = gid - FirstGid;
            var max_x = (int) ((ImageSize.Width - Margin * 2 + Spacing) / (TileSize.Width + Spacing));
            rect.Origin.X = (gid % max_x) * (TileSize.Width + Spacing) + Margin;
            rect.Origin.Y = (gid / max_x) * (TileSize.Height + Spacing) + Margin;
            return rect;
        }
Example #8
0
 public CCRect RectForGID(uint gid)
 {
     CCRect rect = new CCRect();
     rect.Size = m_tTileSize;
     gid &= ccTMXTileFlags.kCCFlippedMask;
     gid = gid - m_uFirstGid;
     var max_x = (int) ((m_tImageSize.Width - m_uMargin * 2 + m_uSpacing) / (m_tTileSize.Width + m_uSpacing));
     //	int max_y = (imageSize.height - margin*2 + spacing) / (tileSize.height + spacing);
     rect.Origin.X = (gid % max_x) * (m_tTileSize.Width + m_uSpacing) + m_uMargin;
     rect.Origin.Y = (gid / max_x) * (m_tTileSize.Height + m_uSpacing) + m_uMargin;
     return rect;
 }
        public CCDrawNode()
        {
            renderTriangles = new CCCustomCommand(FlushTriangles);
            renderLines = new CCCustomCommand(FlushLines);
            renderStrings = new CCCustomCommand(DrawStrings);

            BlendFunc = CCBlendFunc.AlphaBlend;
            triangleVertices = new CCRawList<CCV3F_C4B>(DefaultBufferSize);
            lineVertices = new CCRawList<CCV3F_C4B>(DefaultBufferSize);

            verticeBounds = CCRect.Zero;
        }
Example #10
0
            public void Initialize(CCRect bounds, float mag)
            {
                ColorPen = new Pen(new Microsoft.Xna.Framework.Color(rand.Next(255), rand.Next(255), rand.Next(255)));

                for (int i = 0; i < Points.Length; i++)
                {
                    Points[i] = new CCVector2(bounds.MinX + (float)rand.NextDouble() * bounds.Size.Width, bounds.MaxY + (float)rand.NextDouble() * bounds.Size.Height);
                    Velocities[i] = new CCVector2((float)(rand.NextDouble() - .5) * mag, (float)(rand.NextDouble() - .5) * mag);

                    for (int j = 0; j < History.Count; j++)
                        History[j][i] = Points[i];
                }
            }
 public SneakyButtonControl(CCRect rect, int id, CCDrawNode drawNode )
 {
     this.drawNode = drawNode;
     status = true; //defaults to enabled
     value = false;
     active = false;
     isHoldable = true;
     isToggleable = false;
     radius = 32.0f;
     rateLimit = 1.0f / 120.0f;
     Position = rect.Origin;
     ID = id;
     buttonEvent = new CCEventCustom(SneakyPanelControl.BUTTON_LISTENER_ID);
 }
Example #12
0
        public CCRect TextureRectForGID(short gid)
        {
            CCRect rect = new CCRect();

            if (gid != 0)
            {
                // Rect offset relative to first gid
                gid -= FirstGid;
                rect.Size = TileTexelSize;
                var max_x = (int)((TilesheetSize.Width - BorderWidth * 2 + TileSpacing) / (TileTexelSize.Width + TileSpacing));
                rect.Origin.X = (gid % max_x) * (TileTexelSize.Width + TileSpacing) + BorderWidth;
                rect.Origin.Y = (gid / max_x) * (TileTexelSize.Height + TileSpacing) + BorderWidth;
            }
            return rect;
        }
Example #13
0
        public CCFollow(CCNode followedNode, CCRect rect)
        {
            Debug.Assert (followedNode != null);

            FollowedNode = followedNode;
            if (rect.Equals (CCRect.Zero))
            {
                UsingBoundary = false;
            }
            else
            {
                UsingBoundary = true;
            }

            BoundaryFullyCovered = false;

            CCRect viewportBounds = followedNode.Layer.VisibleBoundsWorldspace;
            FullScreenSize = (CCPoint)new CCPoint(viewportBounds.Size.Width, viewportBounds.Size.Height);
            HalfScreenSize = FullScreenSize * 0.5f;

            if (UsingBoundary)
            {
                float leftBoundary = -((rect.Origin.X + rect.Size.Width) - FullScreenSize.X - viewportBounds.Origin.X);
                float rightBoundary = -rect.Origin.X;
                float topBoundary = -rect.Origin.Y;
                float bottomBoundary = -((rect.Origin.Y + rect.Size.Height) - FullScreenSize.Y - viewportBounds.Origin.Y);

                if (rightBoundary < leftBoundary)
                {
                    // screen width is larger than world's boundary width
                    //set both in the middle of the world
                    rightBoundary = leftBoundary = (leftBoundary + rightBoundary) / 2;
                }
                if (topBoundary < bottomBoundary)
                {
                    // screen width is larger than world's boundary width
                    //set both in the middle of the world
                    topBoundary = bottomBoundary = (topBoundary + bottomBoundary) / 2;
                }

                if ((topBoundary == bottomBoundary) && (leftBoundary == rightBoundary))
                {
                    BoundaryFullyCovered = true;
                }

                Boundary = new CCFollowBoundary (bottomBoundary, leftBoundary, rightBoundary, topBoundary);
            }
        }
Example #14
0
 public void OnTouchEnded(CCTouch touch, CCEvent e)
 {
     if (Enable)
     {
         foreach (var control in ControlList)
         {
             var p = control.PositionWorldspace;
             var rect = new CCRect(p.X, p.Y, control.ContentSize.Width, control.ContentSize.Height);
             if (rect.ContainsPoint(Target.Layer.ScreenToWorldspace(touch.LocationOnScreen)))
             {
                 control.OnTouchEnded(touch, e);
                 return;
             }
         }
     }
 }
        public SneakyJoystickControl(CCRect rect)
            : base()
        {
            Degrees = 0.0f;
            Velocity = CCPoint.Zero;
            AutoCenter = true;

            HasDeadzone = false;
            NumberOfDirections = 4;

            isDPad = false;
            joystickRadius = rect.Size.Width / 2;

            ThumbRadius = 32.0f;
            DeadRadius = 0.0f;

            AnchorPoint = CCPoint.AnchorMiddle;

            ControlSize = rect;
        }
Example #16
0
        void InitCloud()
        {

            CCRect rect;
            switch (ran.Next() % 3)
            {
                case 0:
                    rect = new CCRect(336, 16, 256, 108);
                    break;
                case 1:
                    rect = new CCRect(336, 128, 257, 110);
                    break;
                default:
                    rect = new CCRect(336, 240, 252, 119);
                    break;
            }

            var batchNode = GetChildByTag((int)Tags.SpriteManager) as CCSpriteBatchNode;
            var cloud = new CCSprite(batchNode.Texture, rect);
            batchNode.AddChild(cloud, 3, currentCloudTag);

            cloud.Opacity = 128;
        }
Example #17
0
		public static Animation FromAnimationSave(AnimationChainSave animationSave)
		{
			Animation toReturn = new Animation ();

			toReturn.Name = animationSave.Name;

			foreach (var frame in animationSave.Frames)
			{
				CCRect rectangle;

				rectangle = new CCRect (
					frame.LeftCoordinate, 
					frame.TopCoordinate, 
					frame.RightCoordinate - frame.LeftCoordinate, 
					frame.BottomCoordinate - frame.TopCoordinate);

				var duration = TimeSpan.FromSeconds (frame.FrameLength);

				toReturn.AddFrame (rectangle, duration, flipHorizontal:frame.FlipHorizontal);
			}

			return toReturn;
		}
Example #18
0
            public void Update(CCRect bounds, float time)
            {
                for (int i = 0; i < Points.Length; i++)
                {
                    Points[i] += Velocities[i] * time;
                    if (Points[i].X < bounds.MinX)
                        Velocities[i].X = Math.Abs(Velocities[i].X);
                    else if (Points[i].X > bounds.MaxX)
                        Velocities[i].X = -Math.Abs(Velocities[i].X);
                    if (Points[i].Y < bounds.MaxY)
                        Velocities[i].Y = Math.Abs(Velocities[i].Y);
                    else if (Points[i].Y > bounds.MinY)
                        Velocities[i].Y = -Math.Abs(Velocities[i].Y);
                }

                Skip += time;
                if (Skip >= SkipLimit)
                {
                    Skip = 0;
                    for (int i = History.Count - 1; i > 0; i--)
                        History[i - 1].CopyTo(History[i], 0);
                    Points.CopyTo(History[0], 0);
                }
            }
Example #19
0
        /// <summary>
        /// Initializes an sprite with a texture and a rect.
        /// The offset will be (0,0).
        /// </summary>
        public bool initWithTexture(Texture texture, CCRect rect)
        {
            if (texture == null)
            {
                throw (new ArgumentNullException("texture", "Texture cannot be null"));
            }
            init();
            Texture = texture;
            setTextureRect(rect);

            return true;
        }
Example #20
0
        /// <summary>
        /// Initializes an sprite with a texture.
        /// The rect used will be the size of the texture.
        /// The offset will be (0,0).
        /// </summary>
        public bool initWithTexture(Texture texture)
        {
            if (texture == null)
            {
                throw (new ArgumentNullException("texture", "Texture cannot be null"));
            }

            CCRect rect = new CCRect();
            rect.Size = texture.ContentSize;

            return initWithTexture(texture, rect);
        }
Example #21
0
        /// <summary>
        /// Initializes an sprite with an image filename, and a rect.
        /// The offset will be (0,0).
        /// </summary>
        public bool initWithFile(string fileName, CCRect rect)
        {
            Debug.Assert(fileName != null);

            Texture pTexture = CCTextureCache.sharedTextureCache().addImage(fileName);
            if (pTexture != null)
            {
                return initWithTexture(pTexture, rect);
            }

            // don't release here.
            // when load texture failed, it's better to get a "transparent" sprite then a crashed program
            // this->release();
            return false;
        }
Example #22
0
        /// <summary>
        /// Initializes an sprite with an image filename.
        /// The rect used will be the size of the image.
        /// The offset will be (0,0).
        /// </summary>
        public bool initWithFile(string fileName)
        {
            Debug.Assert(null != fileName, "fileName is null");

            Texture textureFromFile = CCTextureCache.sharedTextureCache().addImage(fileName);

            if (null != textureFromFile)
            {
                CCRect rect = new CCRect();
                rect.Size = textureFromFile.ContentSize;
                return initWithTexture(textureFromFile, rect);
            }

            return false;
        }
Example #23
0
 /// <summary>
 /// Initializes an sprite with an CCSpriteBatchNode and a rect in pixels
 /// @since v0.99.5
 /// </summary>
 public bool initWithBatchNodeRectInPixels(CCSpriteBatchNode batchNode, CCRect rect)
 {
     if (initWithTexture(batchNode.Texture))
     {
         setTextureRectInPixels(rect, false, rect.Size);
         useBatchNode(batchNode);
         return true;
     }
     return false;
 }
Example #24
0
 /// <summary>
 /// Initializes an sprite with an CCSpriteBatchNode and a rect in points
 /// </summary>
 public bool initWithBatchNode(CCSpriteBatchNode batchNode, CCRect rect)
 {
     if (initWithTexture(batchNode.Texture, rect))
     {
         useBatchNode(batchNode);
         return true;
     }
     return false;
 }
Example #25
0
 bool Intersects(CCRect first, RectWithDirection second)
 {
     //判断两个rect是否有重叠
     return first.UpperRight.X > second.Left &&
         first.LowerLeft.X < second.Left + second.Width &&
         first.UpperRight.Y > second.Bottom &&
         first.LowerLeft.Y < second.Bottom + second.Height;
 }
Example #26
0
        /// <summary>
        /// Creates an sprite with a texture and a rect.
        /// The offset will be (0,0).
        /// </summary>
        public static CCSprite spriteWithTexture(Texture texture, CCRect rect)
        {
            CCSprite sprite = new CCSprite();
            if (sprite != null && sprite.initWithTexture(texture, rect))
            {
                return sprite;
            }

            sprite = null;
            return null;
        }
Example #27
0
        CCVector2 GetSeparatingVector(CCRect first, RectWithDirection second)
        {
            // Default to no separation
            CCVector2 separation = CCVector2.Zero;

            // Only calculate separation if the rectangles intersect
            if (Intersects(first, second))
            {
                // The intersectionRect returns the rectangle produced
                // by overlapping the two rectangles.
                // This is protected by partitioning and deep collision, so it
                // won't happen too often - it's okay to do a ToRect here
                var intersectionRect = first.Intersection(second.ToRect());

                float minDistance = float.PositiveInfinity;

                float firstCenterX = first.Center.X;
                float firstCenterY = first.Center.Y;

                float secondCenterX = second.Left + second.Width / 2.0f;
                float secondCenterY = second.Bottom + second.Width / 2.0f;

                bool canMoveLeft  = (second.Directions & Directions.Left) == Directions.Left && firstCenterX < secondCenterX;
                bool canMoveRight = (second.Directions & Directions.Right) == Directions.Right && firstCenterX > secondCenterX;
                bool canMoveDown  = (second.Directions & Directions.Down) == Directions.Down && firstCenterY < secondCenterY;
                bool canMoveUp    = (second.Directions & Directions.Up) == Directions.Up && firstCenterY > secondCenterY;


                if (canMoveLeft)
                {
                    float candidate = first.UpperRight.X - second.Left;

                    if (candidate > 0)
                    {
                        minDistance = candidate;

                        separation.X = -minDistance;
                        separation.Y = 0;
                    }
                }
                if (canMoveRight)
                {
                    float candidate = (second.Left + second.Width) - first.LowerLeft.X;

                    if (candidate > 0 && candidate < minDistance)
                    {
                        minDistance = candidate;

                        separation.X = minDistance;
                        separation.Y = 0;
                    }
                }
                if (canMoveUp)
                {
                    float candidate = (second.Bottom + second.Height) - first.Origin.Y;

                    if (candidate > 0 && candidate < minDistance)
                    {
                        minDistance = candidate;

                        separation.X = 0;
                        separation.Y = minDistance;
                    }
                }
                if (canMoveDown)
                {
                    float candidate = first.UpperRight.Y - second.Bottom;

                    if (candidate > 0 && candidate < minDistance)
                    {
                        minDistance = candidate;

                        separation.X = 0;
                        separation.Y = -minDistance;
                    }
                }
            }

            return(separation);
        }
Example #28
0
 public CCSplitRowsState(CCSplitRows action, CCNode target) : base(action, target)
 {
     VisibleBounds = Target.Layer.VisibleBoundsWorldspace;
 }
Example #29
0
 internal static CCPoint[] BoxToDiamond(CCRect box)
 {
     return(new CCPoint[] { new CCPoint(box.MinX, box.MinY + (box.Size.Width / 2)), new CCPoint(box.MinX + (box.Size.Width / 2), box.MaxY), new CCPoint(box.MaxX, box.MinY + (box.Size.Height / 2)), new CCPoint(box.MinX + (box.Size.Width / 2), box.MinY) });
 }
Example #30
0
 void UpdateQuads(float dt)
 {
     index = (index + 1) % 4;
     var rect = new CCRect(index * 32, 0, 32, 32);
     var system = (CCParticleSystemQuad) Emitter;
     system.Texture = Emitter.Texture;
     system.TextureRect = rect;
 }
Example #31
0
        CCVector2 GetSeparatingVector(CCRect first, RectWithDirection second)
        {
            //返回一个向量,是player在碰撞之后反方向移动的向量

            // Default to no separation
            CCVector2 separation = CCVector2.Zero;

            // Only calculate separation if the rectangles intersect
            if (Intersects(first, second))
            {
                // The intersectionRect returns the rectangle produced
                // by overlapping the two rectangles.
                // This is protected by partitioning and deep collision, so it
                // won't happen too often - it's okay to do a ToRect here
                //得到两个rect重叠部分的rect
                var intersectionRect = first.Intersection (second.ToRect());

                float minDistance = float.PositiveInfinity;

                float firstCenterX = first.Center.X;
                float firstCenterY = first.Center.Y;

                float secondCenterX = second.Left + second.Width / 2.0f;
                float secondCenterY = second.Bottom + second.Width / 2.0f;

                //second的方向和想要判断的方向(左)取交集,如果和想要判断的方向(左)一致,且第一个的中心点在第二个的中心点的(左边)
                //则当碰撞时,player可以向想要的方向移动
                bool canMoveLeft = (second.Directions & Directions.Left) == Directions.Left && firstCenterX < secondCenterX;
                bool canMoveRight = (second.Directions & Directions.Right) == Directions.Right && firstCenterX > secondCenterX;
                bool canMoveDown = (second.Directions & Directions.Down) == Directions.Down && firstCenterY < secondCenterY;
                bool canMoveUp = (second.Directions & Directions.Up) == Directions.Up && firstCenterY > secondCenterY;

                if (canMoveLeft)
                {
                    //左重叠
                    //得到重叠的rect的X方向边长
                    float candidate = first.UpperRight.X - second.Left;

                    if (candidate > 0)
                    {
                        minDistance = candidate;

                        //x方向移动回到地图实体瓦片的外面,y方向不动
                        separation.X = -minDistance;
                        separation.Y = 0;
                    }
                }
                if (canMoveRight)
                {
                    //右重叠
                    float candidate = (second.Left + second.Width) - first.LowerLeft.X;

                    if (candidate > 0 && candidate < minDistance)
                    {
                        minDistance = candidate;

                        //向右移动
                        separation.X = minDistance;
                        separation.Y = 0;
                    }
                }
                //其他方向同理
                if (canMoveUp)
                {
                    float candidate = (second.Bottom + second.Height) - first.Origin.Y;

                    if (candidate > 0 && candidate < minDistance)
                    {
                        minDistance = candidate;

                        separation.X = 0;
                        separation.Y = minDistance;
                    }

                }
                if (canMoveDown)
                {
                    float candidate = first.UpperRight.Y - second.Bottom;

                    if (candidate > 0 && candidate < minDistance)
                    {
                        minDistance = candidate;

                        separation.X = 0;
                        separation.Y = -minDistance;
                    }
                }
            }

            //左后返回player移动的vector
            return separation;
        }
Example #32
0
 /// <summary>
 /// Creates an sprite with a texture, a rect and offset. 
 /// </summary>
 public static CCSprite spriteWithTexture(Texture texture, CCRect rect, CCPoint offset)
 {
     // not implement
     return null;
 }
Example #33
0
		public void DrawRect(CCRect rect, cpColor color)
		{
			base.DrawRect(rect, color.ToCCColor4B());
		}
Example #34
0
 // dirty, because only the center of the bounding box + all points of the box are used to check the angle;
 // this function is using CCDegrees
 internal static bool CollideArcBoundingBox(CCPoint posCircle, float radius, float angleArcCenter, float angleHalfArcWidth, CCRect box)
 {
     if (CollideBoundingBoxCircle(box, posCircle, radius))
     {
         // check whether the center of the box is inside the arc
         CCPoint vectorCirclePoint = box.Center - posCircle;
         float   anglePoint        = Constants.DxDyToCCDegrees(vectorCirclePoint.X, vectorCirclePoint.Y);
         float   angleDifference   = Constants.AbsAngleDifferenceDeg(angleArcCenter, anglePoint);
         if (angleDifference <= angleHalfArcWidth)
         {
             return(true);
         }
         // check whether a point of the box is inside the arc
         foreach (CCPoint point in Constants.CCRectPoints(box))
         {
             vectorCirclePoint = point - posCircle;
             anglePoint        = Constants.DxDyToCCDegrees(vectorCirclePoint.X, vectorCirclePoint.Y);
             angleDifference   = Constants.AbsAngleDifferenceDeg(angleArcCenter, anglePoint);
             if (angleDifference <= angleHalfArcWidth)
             {
                 return(true);
             }
         }
     }
     return(false);
 }