Example #1
0
 public CCTextFieldTTF(string text, string fontName, float fontSize, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment)
     : base(text, fontName, fontSize, dimensions, new CCLabelFormat( CCLabelFormatFlags.Unknown ) { Alignment = hAlignment,
         LineAlignment = vAlignment})
 {
     EditTitle = "Input";
     EditDescription = "Please provide input";
 }
Example #2
0
 public IntroLayer(string jsonurl, CCSize size)
     : base(size)
 {
     //AnchorPoint = new CCPoint(0, 0);
     //Scene.Position = new CCPoint(-484.666f, 79.78197f);
     //Scale = 41;
 }
Example #3
0
        public override bool ApplicationDidFinishLaunching()
        {
            ContentRootDirectory = "Content";

            CCSpriteFontCache.FontScale = 0.6f;
            CCSpriteFontCache.RegisterFont("MarkerFelt", 22);

            CCDirector director = CCDirector.SharedDirector;
            director.DisplayStats = true;
            director.AnimationInterval = 1.0 / 60;

            CCSize designSize = new CCSize(480, 320);

            if (CCDrawManager.FrameSize.Height > 320)
            {
                CCSize resourceSize = new CCSize(960, 640);
                ContentSearchPaths.Add("hd");
                director.ContentScaleFactor = resourceSize.Height / designSize.Height;
            }

            CCDrawManager.SetDesignResolutionSize(designSize.Width, designSize.Height, CCResolutionPolicy.ShowAll);

            CCScene scene = new CCScene();

            var label = TestClass.PCLLabel(AppDelegate.PlatformMessage());

            scene.AddChild(label);

            director.RunWithScene(scene);

            return true;
        }
        /*
         *  TL    TR
         *   0----1 0,1,2,3 = index offsets for vertex indices
         *   |   /|
         *   |  / |
         *   | /  |
         *   |/   |
         *   2----3
         *  BL    BR
         */
        void GenerateGradient(CCSize textureSizeInPixels)
        {
            var gradientNode = new CCDrawNode();

            var gradientAlpha = new CCColor4B(0, 0, 0,(byte)(0.7f * 255f));
            CCV3F_C4B[] vertices = new CCV3F_C4B[6];

            // Left triangle TL - 0
            vertices[0].Vertices = new CCVertex3F(0, textureSizeInPixels.Height, 0);
            vertices[0].Colors = CCColor4B.Transparent;

            // Left triangle BL - 2
            vertices[1].Vertices = new CCVertex3F(0, 0, 0);
            vertices[1].Colors = gradientAlpha;

            // Left triangle TR - 1
            vertices[2].Vertices = new CCVertex3F(textureSizeInPixels.Width, textureSizeInPixels.Height, 0);
            vertices[2].Colors = CCColor4B.Transparent;

            // Right triangle BL - 2
            vertices[3].Vertices = new CCVertex3F(0, 0, 0);
            vertices[3].Colors = gradientAlpha;

            // Right triangle BR - 3
            vertices[4].Vertices = new CCVertex3F(textureSizeInPixels.Width, 0, 0);
            vertices[4].Colors = gradientAlpha;

            // Right triangle TR - 1
            vertices[5].Vertices = new CCVertex3F(textureSizeInPixels.Width, textureSizeInPixels.Height, 0);
            vertices[5].Colors = CCColor4B.Transparent;

            gradientNode.DrawTriangleList(vertices);

            gradientNode.Visit();
        }
Example #5
0
        public override void Update (float time)
        {

            // We may have started the action before the Visible Size was able
            // to be set from the Target so we will try it again
            if (width == 0)
            {
                VisibleSize = Target.VisibleBoundsWorldspace.Size;
                width = VisibleSize.Width;
            }

            int j;

            for (j = 0; j < GridSize.Y; ++j) {
                CCQuad3 coords = OriginalTile (0, j);
                float direction = 1;

                if ((j % 2) == 0) {
                    direction = -1;
                }

                coords.BottomLeft.X += direction * width * time;
                coords.BottomRight.X += direction * width * time;
                coords.TopLeft.X += direction * width * time;
                coords.TopRight.X += direction * width * time;

                SetTile (0, j, ref coords);
            }
        }
 public Background(CCSize size, CCColor4B color)
 {
     Color = new CCColor3B(color);
     Opacity = color.A;
     AnchorPoint = CCPoint.AnchorMiddle;
     ContentSize = size;
 }
        public override void OnEnter()
        {
            base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            spritePremulti.Position = new CCPoint(16, 48);
            spriteNonpremulti.Position = new CCPoint(16, 16);

            CCSize rendSize = new CCSize(32, 64);

            /* A2 & B2 setup */
            CCRenderTexture rend = new CCRenderTexture(rendSize,rendSize);

            //  It's possible to modify the RenderTexture blending function by
            //  CCBlendFunc bf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA);
            //  rend.Sprite.BlendFunc = bf;

            rend.BeginWithClear(CCColor4B.Transparent);
            // A2
            spritePremulti.Visit();
            // B2
            spriteNonpremulti.Visit();
            rend.End();

            /* A1: setup */
            spritePremulti.Position = new CCPoint(windowSize.Width / 2 - 16, windowSize.Height / 2 + 16);
            /* B1: setup */
            spriteNonpremulti.Position = new CCPoint(windowSize.Width / 2 - 16, windowSize.Height / 2 - 16);

            rend.Sprite.Position = new CCPoint(windowSize.Width / 2 + 16, windowSize.Height / 2);

            AddChild(spriteNonpremulti);
            AddChild(spritePremulti);
            AddChild(rend.Sprite);
        }
        public SpriteWithColor(CCColor4B bgColor, CCSize textureSizeInPixels) : base ()
        {
            // 1: Create new CCRenderTexture
            CCRenderTexture rt = new CCRenderTexture(textureSizeInPixels, textureSizeInPixels);

            // 2: Call CCRenderTexture:begin
            rt.BeginWithClear(bgColor);

            // 3: Draw into the texture
            // You'll add this later
            GenerateGradient(textureSizeInPixels);


            var noise = new CCSprite("images/Noise.png");
            noise.AnchorPoint = CCPoint.AnchorLowerLeft;
            noise.Position = CCPoint.Zero;
            noise.BlendFunc = new CCBlendFunc(CCOGLES.GL_DST_COLOR, CCOGLES.GL_ZERO);
            noise.Texture.SamplerState = Microsoft.Xna.Framework.Graphics.SamplerState.LinearWrap;

            // To get the linear wrap to work correctly we have to set the TextureRectInPixels as well as ContentSize
            noise.TextureRectInPixels = new CCRect(0, 0, textureSizeInPixels.Width, textureSizeInPixels.Height);
            noise.ContentSize = noise.TextureRectInPixels.Size;
            noise.Visit();

            // 4: Call CCRenderTexture:end
            rt.End();

            this.Texture = rt.Texture;

        }
Example #9
0
 public CCNodeGrid(CCSize contentSize) 
     : base(contentSize)
 {
     renderGrid = new CCCustomCommand(RenderGrid);
     renderBeginGrid = new CCCustomCommand(float.MinValue, OnGridBeginDraw);
     renderEndGrid = new CCCustomCommand(float.MaxValue, OnGridEndDraw); 
 }
Example #10
0
        public CCRenderTexture(CCSize contentSize, CCSize textureSizeInPixels, 
            CCSurfaceFormat colorFormat=CCSurfaceFormat.Color, 
            CCDepthFormat depthFormat=CCDepthFormat.None, 
            CCRenderTargetUsage usage=CCRenderTargetUsage.DiscardContents) : this()
        {
            int textureWidth = (int)textureSizeInPixels.Width;
            int textureHeight = (int)textureSizeInPixels.Height;

            renderTarget2D = drawManager.CreateRenderTarget(
                textureWidth, textureHeight, colorFormat, depthFormat, usage);

            Texture = new CCTexture2D(renderTarget2D, colorFormat, true, false);
            Texture.IsAntialiased = false;

            Sprite = new CCSprite(Texture);
            Sprite.ContentSize = contentSize;
            Sprite.BlendFunc = CCBlendFunc.AlphaBlend;

            CCPoint center = contentSize.Center;

            renderViewMatrix = 
                Matrix.CreateLookAt(new CCPoint3(center, 300.0f).XnaVector, new CCPoint3(center, 0.0f).XnaVector, Vector3.Up);
            renderProjMatrix = 
                Matrix.CreateOrthographic(contentSize.Width, contentSize.Height, 1024f, -1024);
            renderViewport = new Viewport(0, 0, textureWidth, textureHeight);


            clearColor = CCColor4B.Transparent;
            drawManager.SetRenderTarget(Texture);
            drawManager.Clear(clearColor);
            drawManager.RestoreRenderTarget();
        }
Example #11
0
 public AlignmentPanel(CCSize size, CCColor4B color)
 {
     Color = new CCColor3B(color);
     Opacity = color.A;
     //AnchorPoint = CCPoint.AnchorMiddle;
     ContentSize = size;
 }
Example #12
0
 public GameLayer(CCSize screenSize, CCClipMode clipmode)
     : base(screenSize, clipmode)
 {
     this.screenSize = screenSize;
     Init ();
     Schedule (RunGameLogic);
 }
Example #13
0
        public override void Update (float time)
        {

            // We may have started the action before the Visible Size was able
            // to be set from the Target so we will try it again
            if (height == 0)
            {
                VisibleSize = Target.VisibleBoundsWorldspace.Size;
                height = VisibleSize.Height;
            }

            int i;

            for (i = 0; i < GridSize.X; ++i)
            {
                CCQuad3 coords = OriginalTile (i, 0);
                float direction = 1;

                if ((i % 2) == 0)
                {
                    direction = -1;
                }

                coords.BottomLeft.Y += direction * height * time;
                coords.BottomRight.Y += direction * height * time;
                coords.TopLeft.Y += direction * height * time;
                coords.TopRight.Y += direction * height * time;

                SetTile (i, 0, ref coords);
            }
        }
        public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
        {

            CCLog.Logger = DebugLogging;

            preferredWidth = 1024;
			preferredHeight = 768;

			application.PreferMultiSampling = true;
			application.ContentRootDirectory = "Content";

			//CCSpriteFontCache.FontScale = 0.5f;
			//CCSpriteFontCache.RegisterFont("MarkerFelt", 22);
			//CCSpriteFontCache.RegisterFont("arial", 12, 24);

			CCSize designSize = new CCSize(480, 320);

//			if (CCDrawManager.FrameSize.Height > 320)
//			{
//				//CCSize resourceSize = new CCSize(960, 640);
//				CCSize resourceSize = new CCSize(480, 320);
//				application.ContentSearchPaths.Add("hd");
//				director.ContentScaleFactor = resourceSize.Height / designSize.Height;
//			}

            CCScene.SetDefaultDesignResolution(designSize.Width, designSize.Height, CCSceneResolutionPolicy.ShowAll);

			// turn on display FPS
			mainWindow.DisplayStats = true;
            mainWindow.StatsScale = 2;

            CCScene pScene = GoblinLayer.Scene(mainWindow);

			mainWindow.RunWithScene(pScene);
		}
        internal static CCTexture2D CreateNativeLabel(string text, CCSize dimensions, CCTextAlignment hAlignment,
		                                   CCVerticalTextAlignment vAlignment, string fontName,
		                                   float fontSize, CCColor4B textColor)
		{

		    if (string.IsNullOrEmpty(text))
		    {
		        return new CCTexture2D();
		    }

		    var font = CreateFont (fontName, fontSize);

            if (dimensions.Equals(CCSize.Zero))
            {
                CreateBitmap(1, 1);

                var ms = _graphics.MeasureString(text, font);
                
                dimensions.Width = ms.Width;
                dimensions.Height = ms.Height;
            }

            CreateBitmap((int)dimensions.Width, (int)dimensions.Height);

            var stringFormat = new StringFormat();

		    switch (hAlignment)
		    {
		        case CCTextAlignment.Left:
                    stringFormat.Alignment = StringAlignment.Near;
		            break;
		        case CCTextAlignment.Center:
                    stringFormat.Alignment = StringAlignment.Center;
		            break;
		        case CCTextAlignment.Right:
                    stringFormat.Alignment = StringAlignment.Far;
		            break;
		    }

		    switch (vAlignment)
		    {
		        case CCVerticalTextAlignment.Top:
        		    stringFormat.LineAlignment = StringAlignment.Near;
		            break;
		        case CCVerticalTextAlignment.Center:
        		    stringFormat.LineAlignment = StringAlignment.Center;
		            break;
		        case CCVerticalTextAlignment.Bottom:
        		    stringFormat.LineAlignment = StringAlignment.Far;
		            break;
		    }

            _graphics.DrawString(text, font, _brush, new RectangleF(0, 0, dimensions.Width, dimensions.Height), stringFormat);
            _graphics.Flush();

            var texture = new CCTexture2D(SaveToStream(), CCSurfaceFormat.Bgra4444);

			return texture;
		}
Example #16
0
 public static CCPoint WorldToScreen(b2Vec2 worldPos, CCPoint actualPosition, float actualScale, CCSize wSize)
 {
     worldPos *= actualScale;
     CCPoint layerOffset = actualPosition;
     CCPoint p = new CCPoint(worldPos.x + layerOffset.X, worldPos.y + layerOffset.Y);
     p.Y = wSize.Height - p.Y;
     return p;
 }
Example #17
0
        public WallJumpManager(b2Body parentJumpBody, float JumpTimeNeeded, float JumpHeight, float JumpWidth)
        {
            jumpBody = parentJumpBody;
            maxTime = JumpTimeNeeded;
            jumpSize = new CCSize (JumpWidth, JumpHeight);

            CurrentJumpingDirection = Direction.Left;
        }
Example #18
0
        public void updateSize(CCPoint touchLocation)
        {
            CCSize s = Layer.VisibleBoundsWorldspace.Size;

            CCSize newSize = new CCSize(Math.Abs(touchLocation.X - s.Width / 2) * 2, Math.Abs(touchLocation.Y - s.Height / 2) * 2);
            CCLayerColor l = (CCLayerColor)GetChildByTag(kTagLayer);
            l.ContentSize = newSize;
        }
Example #19
0
 public virtual void Init(float width, float height)
 {
     EventListener = new CCEventListenerTouchOneByOne()
     {
         OnTouchBegan = OnTouchBegan,
         OnTouchEnded = OnTouchEnded,
     };
     ContentSize = new CCSize(width, height);
 }
Example #20
0
        public MergedLayer(CCWindow mainWindow, Container mainContainer)
        {
            screenSize = mainWindow.WindowSizeInPixels;
            gameContainer = mainContainer;

            mapVersion = "unspecified";
            mapCreator = "unspecified";
            mapName = "unspecified";
        }
Example #21
0
        public void updateSize(CCPoint touchLocation)
        {
            var s = Layer.VisibleBoundsWorldspace.Size;

            var newSize = new CCSize(Math.Abs(touchLocation.X - s.Width / 2) * 2, Math.Abs(touchLocation.Y - s.Height / 2) * 2);
            var l = (CCLayerColor)GetChildByTag(kTagLayer);
            l.ScaleX = newSize.Width / s.Width;
            l.ScaleY = newSize.Height / s.Height;
            l.Position = touchLocation;
        }
Example #22
0
        CCTileMapAtlas(string tile, int tileWidth, int tileHeight, CCImageTGA tgaInfo, int numOfItemsToRender)
            : base(tile, tileWidth, tileHeight, numOfItemsToRender)
        {
            TGAInfo = tgaInfo;
            NumOfItemsToRender = numOfItemsToRender;

            PositionToAtlasIndex = new Dictionary<CCGridSize, int>();
            UpdateAtlasValues();
            ContentSize = new CCSize(TGAInfo.Width * ItemWidth, TGAInfo.Height * ItemHeight);
        }
Example #23
0
        public void Step(CCSize MapTotalSize, float MapMaxTop, float dt)
        {
            if (!klass.IsIA)
                return;

            Position = new CCPoint(
                Math.Min((MapTotalSize.Width) - centerToSides, Math.Max(centerToSides, desiredPosition.X)),
                                   Math.Min((MapMaxTop) + centerToBottom, Math.Max(centerToBottom, desiredPosition.Y))
                                   );
        }
Example #24
0
        public IntroLayer(string jsonurl, CCSize size)
            : base(size)
        {
            FILE = jsonurl;
            mouses = new Dictionary<int, CCNode>();

            //AnchorPoint = new CCPoint(0, 0);
            //Scene.Position = new CCPoint(-484.666f, 79.78197f);
            //Scale = 41;
        }
Example #25
0
 public void Step(SneakyPanelControl controlPanelLayer, CCSize MapTotalSize, float MapMaxTop, float dt)
 {
     if (actionState == ActionState.Walk)
         desiredPosition = Position + (velocity * dt);
     //Update player position
     CCPoint tmpPosition = SneakyPanelControl.GetPlayerPosition(this, dt, new CCSize(MapTotalSize.Width, MapTotalSize.Height));
     float posX = Math.Min((MapTotalSize.Width) - centerToSides, Math.Max(centerToSides, tmpPosition.X));
     float posY = Math.Min(MapMaxTop + centerToBottom, Math.Max(centerToBottom, tmpPosition.Y));
     Position = new CCPoint(posX, posY);
 }
Example #26
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 #27
0
        public GameLayer(CCSize size)
            : base(size)
        {
            PuzzleId = int.Parse(string.IsNullOrEmpty(this.Settings[PUZZLE_ID]) ? "0" : this.Settings[PUZZLE_ID]);
            this.pieceBuilder = new CocoPieceBuilder();
            Color = CCColor3B.DarkGray;

            this.Messenger.Register<NextPuzzleMessage>(this, LoadNextPuzzle);
            this.Messenger.Register<SkipPuzzleMessage>(this, LoadNextPuzzle);
        }
        /*
         *  TL    TR
         *   0----1 0,1,2,3 = index offsets for vertex indices
         *   |   /| 
         *   |  / |
         *   | /  |
         *   |/   |
         *   2----3
         *  BL    BR
         */
        void GenerateStripes (CCSize textureSizeInPixels, CCColor4B c2, int numberOfStripes)
        {
            var gradientNode = new CCDrawNode();

            // Layer 1: Stripes
            CCV3F_C4B[] vertices = new CCV3F_C4B[numberOfStripes*6];

            var textureWidth = textureSizeInPixels.Width;
            var textureHeight = textureSizeInPixels.Height;

            int nVertices = 0;
            float x1 = -textureHeight;
            float x2;
            float y1 = textureHeight;
            float y2 = 0;
            float dx = textureWidth / numberOfStripes * 2;
            float stripeWidth = dx/2;

            for (int i=0; i<numberOfStripes; i++) 
            {

                x2 = x1 + textureHeight;

                // Left triangle TL - 0
                vertices[nVertices].Vertices = new CCVertex3F(x1, y1, 0);
                vertices[nVertices++].Colors = c2;

                // Left triangle BL - 2
                vertices[nVertices].Vertices = new CCVertex3F(x1+stripeWidth, y1, 0);
                vertices[nVertices++].Colors = c2;

                // Left triangle TR - 1
                vertices[nVertices].Vertices = new CCVertex3F(x2, y2, 0);
                vertices[nVertices++].Colors = c2;

                // Right triangle BL - 2
                vertices[nVertices].Vertices = vertices[nVertices-2].Vertices;
                vertices[nVertices++].Colors = c2;

                // Right triangle BR - 3
                vertices[nVertices].Vertices = vertices[nVertices-2].Vertices;
                vertices[nVertices++].Colors = c2;

                // Right triangle TR - 1
                vertices[nVertices].Vertices = new CCVertex3F(x2+stripeWidth, y2, 0);
                vertices[nVertices++].Colors = c2;

                x1 += dx;
            }

            gradientNode.DrawTriangleList(vertices);

            gradientNode.Visit();

        }
		protected override void AddedToScene()
		{
			base.AddedToScene();

			//Init Game Elements
			_player1Score = 0;
			_player2Score = 0;


			//get screen size
			_screenSize = Window.WindowSizeInPixels; //CCDirector::sharedDirector()->getWinSize();

			//1. add court image
			GameSprite court = new GameSprite("court"); // CCSprite::create("court.png");
			court.SetPosition(new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.5f)); //->setPosition(ccp());

			AddChild(court);

			//2. add players
			_player1 = new GameSprite("mallet"); //GameSprite::gameSpriteWithFile("mallet.png");
			_player1.SetPosition(new CCPoint(_screenSize.Width * 0.5f, _player1.RotationX * 2f));

			AddChild(_player1, 0, kPlayer1Tag);

			_player2 = new GameSprite("mallet");
			_player2.SetPosition(new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height - _player1.RotationX * 2));
			AddChild(_player2, 0, kPlayer2Tag);

			_players = new GameSprite[] { _player1, _player2 };// CCArray::create(_player1, _player2, NULL);

			//3. add puck
			_ball = new GameSprite("puck");
			_ball.SetPosition(new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.5f - 2f * _ball.RotationX));
			AddChild(_ball);

			//4. add score display
			_player1ScoreLabel = new CCLabelTtf("0", "MarkerFelt", 22);
			_player1ScoreLabel.Position = new CCPoint(_screenSize.Width - 60f, _screenSize.Height * 0.5f - 80f);
			_player1ScoreLabel.Rotation = 90;
			AddChild(_player1ScoreLabel);

			_player2ScoreLabel = new CCLabelTtf("0", "MarkerFelt", 22);
			_player2ScoreLabel.Position = new CCPoint(_screenSize.Width - 60f, _screenSize.Height * 0.5f + 80f);
			_player2ScoreLabel.Rotation = 90;
			AddChild(_player2ScoreLabel);

			//listen for touches
			CCEventListenerTouchAllAtOnce tListener = new CCEventListenerTouchAllAtOnce();
			tListener.OnTouchesBegan = TouchesBegan;
			tListener.OnTouchesEnded = TouchesEnded;
			tListener.OnTouchesMoved = TouchesMoved;
			AddEventListener(tListener, this);

			Schedule(Update);
		}
        public void UpdateShipIA(CCEnemyBase enemy, CCPlayerBase player, CCSize wSize, int PLAYER_SPEED)
        {
            if (enemy.IsIA)
            {

                enemy.PositionX -= (PLAYER_SPEED + enemy.VELOCITY + enemy.VELOCITY + CCRandom.Next(1, 3));

                //Esta dentro de su rango;
                if (enemy.IADesiredActionState == EnemyDesiredActionState.Firing)
                {
                    if (ACTUAL_DELAY <= DELAY_SHOOT)
                        ACTUAL_DELAY++;
                    else
                    {
                        enemy.IADesiredActionState = EnemyDesiredActionState.SearchingTarget;
                        ACTUAL_DELAY = 0;
                    }
                }

                if (enemy.IAPersonalityState == EnemyPersonalityState.Suicide)
                {
                    if (enemy.PositionY > player.PositionY)
                        enemy.PositionY -= CCRandom.Next(1, 3);
                    else if (enemy.PositionY < player.PositionY)
                        enemy.PositionY += CCRandom.Next(1, 3);
                }
                else if (enemy.IAPersonalityState == EnemyPersonalityState.Attacking)
                {

                    //Si la posicion
                    if (enemy.IATarget.Y == enemy.Position.Y)
                        enemy.IATarget.Y = (int)CCRandom.GetRandomFloat(player.PositionY - 50f, player.PositionY + 50f);

                    if (enemy.PositionY > enemy.IATarget.Y)
                        enemy.PositionY -= CCRandom.Next(1, 3);
                    else if (enemy.PositionY < enemy.IATarget.Y)
                        enemy.PositionY += CCRandom.Next(1, 3);

                }

                if (enemy.PositionY > player.PositionY - 30 && enemy.PositionY < player.PositionY + 30 && enemy.PositionX < wSize.Width - 15)
                {

                    CCEventCustom eventC = new CCEventCustom(CCBeatEmUpGameLayer.EVENT_ENEMY_ID);
                    eventC.UserData = enemy;

                }

                if (player.PositionX > enemy.PositionX - 100)
                {
                    if (enemy.IADesiredActionState != EnemyDesiredActionState.OutOfRange)
                        enemy.IADesiredActionState = EnemyDesiredActionState.OutOfRange;
                }
            }
        }
 public CCPoint GetNextPositionFromImage(CCNode node, float dt, CCSize wSize)
 {
     return(GetPositionFromVelocity(Velocity, node, dt, wSize));
 }
Example #32
0
        void CreateGeometry()
        {
            var windowSize = Layer.VisibleBoundsWorldspace.Size;

            // Draw 10 circles
            for (int i = 0; i < 10; i++)
            {
                drawBuffer.DrawSolidCircle(windowSize.Center, 10 * (10 - i),
                                           new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1));
            }

            // Draw polygons
            CCPoint[] points = new CCPoint[]
            {
                new CCPoint(windowSize.Height / 4, 0),
                new CCPoint(windowSize.Width, windowSize.Height / 5),
                new CCPoint(windowSize.Width / 3 * 2, windowSize.Height)
            };
            drawBuffer.DrawPolygon(points, points.Length, new CCColor4F(1.0f, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1));

            // star poly (triggers buggs)
            {
                const float o    = 80;
                const float w    = 20;
                const float h    = 50;
                CCPoint[]   star = new CCPoint[]
                {
                    new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),                               // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),               // right spike
                };

                drawBuffer.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }

            // star poly (doesn't trigger bug... order is important un tesselation is supported.
            {
                const float o    = 180;
                const float w    = 20;
                const float h    = 50;
                var         star = new CCPoint[]
                {
                    new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),    // right spike
                    new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2),            // top spike
                    new CCPoint(o - h, o + w),                                               // left spike
                };

                drawBuffer.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }


            // Draw segment
            drawBuffer.DrawLine(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1), DrawNodeBuffer.LineCap.Round);

            drawBuffer.DrawLine(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                                new CCColor4F(1, 0, 1, 0.5f), DrawNodeBuffer.LineCap.Round);

            CCSize size = VisibleBoundsWorldspace.Size;

            var visibleRect = VisibleBoundsWorldspace;

            // draw quad bezier path
            drawBuffer.DrawQuadBezier(new CCPoint(0, size.Height),
                                      visibleRect.Center,
                                      (CCPoint)visibleRect.Size,
                                      50, 3,
                                      new CCColor4B(255, 0, 255, 255));

            // draw cubic bezier path
            drawBuffer.DrawCubicBezier(visibleRect.Center,
                                       new CCPoint(size.Width / 2 + 30, size.Height / 2 + 50),
                                       new CCPoint(size.Width / 2 + 60, size.Height / 2 - 50),
                                       new CCPoint(size.Width, size.Height / 2), 100, 2, CCColor4B.Green);

            // draw an ellipse within rectangular region
            drawBuffer.DrawEllipse(new CCRect(100, 300, 100, 200), 8, CCColor4B.AliceBlue);

            var splinePoints = new List <CCPoint>();

            splinePoints.Add(new CCPoint(0, 0));
            splinePoints.Add(new CCPoint(50, 70));
            splinePoints.Add(new CCPoint(0, 140));
            splinePoints.Add(new CCPoint(100, 210));
            splinePoints.Add(new CCPoint(0, 280));
            splinePoints.Add(new CCPoint(150, 350));

            int   numberOfSegments = 64;
            float tension          = .05f;

            drawBuffer.DrawCardinalSpline(splinePoints, tension, numberOfSegments);

            drawBuffer.DrawSolidArc(
                pos: new CCPoint(350, windowSize.Height * 0.75f),
                radius: 100,
                startAngle: CCMathHelper.ToRadians(45),
                sweepAngle: CCMathHelper.Pi / 2, // this is in radians, clockwise
                color: CCColor4B.Aquamarine);
        }
Example #33
0
        public IntervalLayer()
        {
            m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0.0f;

            CCSize s = CCDirector.SharedDirector.WinSize;

            // sun
            CCParticleSystem sun = new CCParticleSun();

            sun.Texture  = CCTextureCache.SharedTextureCache.AddImage("Images/fire");
            sun.Position = (new CCPoint(s.Width - 32, s.Height - 32));

            sun.TotalParticles = 130;
            sun.Life           = (0.6f);
            AddChild(sun);

            // timers
            m_label0 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt");
            m_label1 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt");
            m_label2 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt");
            m_label3 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt");
            m_label4 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt");

            ScheduleUpdate();

            Schedule(step1);
            Schedule(step2, 0);
            Schedule(step3, 1.0f);
            Schedule(step4, 2.0f);

            m_label0.Position = new CCPoint(s.Width * 1 / 6, s.Height / 2);
            m_label1.Position = new CCPoint(s.Width * 2 / 6, s.Height / 2);
            m_label2.Position = new CCPoint(s.Width * 3 / 6, s.Height / 2);
            m_label3.Position = new CCPoint(s.Width * 4 / 6, s.Height / 2);
            m_label4.Position = new CCPoint(s.Width * 5 / 6, s.Height / 2);

            AddChild(m_label0);
            AddChild(m_label1);
            AddChild(m_label2);
            AddChild(m_label3);
            AddChild(m_label4);

            // Sprite
            CCSprite sprite = new CCSprite(s_pPathGrossini);

            sprite.Position = new CCPoint(40, 50);

            CCJumpBy jump = new CCJumpBy(3, new CCPoint(s.Width - 80, 0), 50, 4);

            AddChild(sprite);
            sprite.RunAction(new CCRepeatForever(
                                 (CCActionInterval)(CCSequence.FromActions(jump, jump.Reverse())))
                             );

            // pause button
            CCMenuItem item1 = new CCMenuItemFont("Pause", onPause);
            CCMenu     menu  = new CCMenu(item1);

            menu.Position = new CCPoint(s.Width / 2, s.Height - 50);

            AddChild(menu);
        }
Example #34
0
        /// <summary>
        /// initializes the scenes
        /// </summary>
        public virtual void InitScenes()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            m_pInScene.Position = new CCPoint(-s.Width, 0);
        }
Example #35
0
        public new static CCActionInterval actionWithDuration(float t)
        {
            CCSize size = CCDirector.SharedDirector.WinSize;

            return(new CCTwirl(t, new CCGridSize(12, 8), new CCPoint(size.Width / 2, size.Height / 2), 1, 2.5f));
        }
Example #36
0
 public IntroLayer(CCSize size)
     : base(size)
 {
 }
Example #37
0
 public void DrawTexture(string texturePath, CCPoint position, CCSize size) => DrawTexture(texturePath, position, size, CCColor3B.White, 1);
Example #38
0
 public void DrawTexture(CCSpriteFrame spriteFrame, CCPoint position, CCSize size, float opacity) => DrawTexture(spriteFrame, position, size, CCColor3B.White, opacity);
Example #39
0
 public void DrawText(CCPoint position, string text, Font font, CCSize targetSize) => DrawText(position, text, font, targetSize, CCColor3B.White);
Example #40
0
 public void DrawText(float x, float y, string text, Font font, CCSize targetSize) => DrawText(new CCPoint(x, y), text, font, targetSize, CCColor3B.White);
        public SpriteBatchNodeChildrenScale()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_family");

            CCNode           aParent;
            CCSprite         sprite1, sprite2;
            CCActionInterval rot = CCRotateBy.actionWithDuration(10, 360);
            CCAction         seq = CCRepeatForever.actionWithAction(rot);

            //
            // Children + Scale using Sprite
            // Test 1
            //
            aParent          = CCNode.node();
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = new CCPoint(s.width / 4, s.height / 4);
            sprite1.scaleX   = -0.5f;
            sprite1.scaleY   = 2.0f;
            sprite1.runAction(seq);


            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);


            //
            // Children + Scale using SpriteBatchNode
            // Test 2
            //

            aParent          = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini_family");
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = new CCPoint(3 * s.width / 4, s.height / 4);
            sprite1.scaleX   = -0.5f;
            sprite1.scaleY   = 2.0f;
            sprite1.runAction((CCAction)(seq.copy()));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);


            //
            // Children + Scale using Sprite
            // Test 3
            //

            aParent          = CCNode.node();
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = (new CCPoint(s.width / 4, 2 * s.height / 3));
            sprite1.scaleX   = (1.5f);
            sprite1.scaleY   = -0.5f;
            sprite1.runAction((CCAction)(seq.copy()));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);

            //
            // Children + Scale using Sprite
            // Test 4
            //

            aParent          = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini_family");
            sprite1          = CCSprite.spriteWithSpriteFrameName("grossinis_sister1");
            sprite1.position = (new CCPoint(3 * s.width / 4, 2 * s.height / 3));
            sprite1.scaleX   = 1.5f;
            sprite1.scaleY   = -0.5f;
            sprite1.runAction((CCAction)(seq.copy()));

            sprite2          = CCSprite.spriteWithSpriteFrameName("grossinis_sister2");
            sprite2.position = (new CCPoint(50, 0));

            addChild(aParent);
            aParent.addChild(sprite1);
            sprite1.addChild(sprite2);
        }
Example #42
0
        public MenuLayer1()
        {
            CCMenuItemFont.FontSize = 30;
            CCMenuItemFont.FontName = "Arial";
            base.isTouchEnabled     = true;
            // Font Item

            CCSprite spriteNormal   = CCSprite.spriteWithFile(s_MenuItem, new CCRect(0, 23 * 2, 115, 23));
            CCSprite spriteSelected = CCSprite.spriteWithFile(s_MenuItem, new CCRect(0, 23 * 1, 115, 23));
            CCSprite spriteDisabled = CCSprite.spriteWithFile(s_MenuItem, new CCRect(0, 23 * 0, 115, 23));

            CCMenuItemSprite item1 = CCMenuItemSprite.itemFromNormalSprite(spriteNormal, spriteSelected, spriteDisabled, this, this.menuCallback);

            // Image Item
            CCMenuItem item2 = CCMenuItemImage.itemFromNormalImage(s_SendScore, s_PressSendScore, this, this.menuCallback2);

            // Label Item (LabelAtlas)
            CCLabelAtlas    labelAtlas = CCLabelAtlas.labelWithString("0123456789", "Images/fps_images", 16, 24, '.');
            CCMenuItemLabel item3      = CCMenuItemLabel.itemWithLabel(labelAtlas, this, this.menuCallbackDisabled);

            item3.DisabledColor = new ccColor3B(32, 32, 64);
            item3.Color         = new ccColor3B(200, 200, 255);

            // Font Item
            CCMenuItemFont item4 = CCMenuItemFont.itemFromString("I toggle enable items", this, this.menuCallbackEnable);

            item4.FontSizeObj = 20;
            item4.FontNameObj = "Arial";

            // Label Item (CCLabelBMFont)
            CCLabelBMFont   label = CCLabelBMFont.labelWithString("configuration", "fonts/fnt/bitmapFontTest3");
            CCMenuItemLabel item5 = CCMenuItemLabel.itemWithLabel(label, this, this.menuCallbackConfig);


            // Testing issue #500
            item5.scale = 0.8f;

            // Font Item
            CCMenuItemFont item6 = CCMenuItemFont.itemFromString("Quit", this, this.onQuit);

            CCActionInterval   color_action = CCTintBy.actionWithDuration(0.5f, 0, -255, -255);
            CCActionInterval   color_back   = (CCActionInterval)color_action.reverse();
            CCFiniteTimeAction seq          = CCSequence.actions(color_action, color_back);

            item6.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq));

            CCMenu menu = CCMenu.menuWithItems(item1, item2, item3, item4, item5, item6);

            menu.alignItemsVertically();

            // elastic effect
            CCSize        s = CCDirector.sharedDirector().getWinSize();
            int           i = 0;
            CCNode        child;
            List <CCNode> pArray  = menu.children;
            CCObject      pObject = null;

            if (pArray.Count > 0)
            {
                for (int j = 0; j < pArray.Count; j++)
                {
                    pObject = pArray[j];
                    if (pObject == null)
                    {
                        break;
                    }
                    child = (CCNode)pObject;
                    CCPoint dstPoint = child.position;
                    int     offset   = (int)(s.width / 2 + 50);
                    if (i % 2 == 0)
                    {
                        offset = -offset;
                    }

                    child.position = new CCPoint(dstPoint.x + offset, dstPoint.y);
                    child.runAction(CCEaseElasticOut.actionWithAction(CCMoveBy.actionWithDuration(2, new CCPoint(dstPoint.x - offset, 0)), 0.35f));
                    i++;
                }
            }
            m_disabledItem         = item3;
            m_disabledItem.Enabled = false;

            addChild(menu);
        }
Example #43
0
        public SpriteOffsetAnchorSkewScale()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache();
                cache.addSpriteFramesWithFile("animations/grossini");
                cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray");

                //
                // Animation using Sprite batch
                //
                CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png");
                sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2));

                CCSprite point = CCSprite.spriteWithFile("Images/r1");
                point.scale    = 0.25f;
                point.position = sprite.position;
                addChild(point, 1);

                switch (i)
                {
                case 0:
                    sprite.anchorPoint = new CCPoint(0, 0);
                    break;

                case 1:
                    sprite.anchorPoint = (new CCPoint(0.5f, 0.5f));
                    break;

                case 2:
                    sprite.anchorPoint = (new CCPoint(1, 1));
                    break;
                }

                point.position = sprite.position;

                List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>();
                string tmp = "";
                for (int j = 0; j < 14; j++)
                {
                    string temp = "";
                    if (j + 1 < 10)
                    {
                        temp = "0" + (j + 1);
                    }
                    else
                    {
                        temp = (j + 1).ToString();
                    }
                    tmp = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.spriteFrameByName(tmp);
                    animFrames.Add(frame);
                }

                CCAnimation animation = CCAnimation.animationWithFrames(animFrames);
                sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(2.8f, animation, false)));

                animFrames = null;

                // Skew
                CCSkewBy         skewX      = CCSkewBy.actionWithDuration(2, 45, 0);
                CCActionInterval skewX_back = (CCActionInterval)skewX.reverse();
                CCSkewBy         skewY      = CCSkewBy.actionWithDuration(2, 0, 45);
                CCActionInterval skewY_back = (CCActionInterval)skewY.reverse();

                CCFiniteTimeAction seq_skew = CCSequence.actions(skewX, skewX_back, skewY, skewY_back);
                sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_skew));

                // Scale
                CCScaleBy          scale      = CCScaleBy.actionWithDuration(2, 2);
                CCActionInterval   scale_back = (CCActionInterval)scale.reverse();
                CCFiniteTimeAction seq_scale  = CCSequence.actions(scale, scale_back);
                sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_scale));

                addChild(sprite, 0);
            }
        }
Example #44
0
 public void DrawTexture(string texturePath, CCPoint position, CCSize size, float opacity) => DrawTexture(texturePath, position, size, CCColor3B.White, opacity);
        public new static CCActionInterval actionWithDuration(float t)
        {
            CCSize size = CCDirector.sharedDirector().getWinSize();

            return(CCJumpTiles3D.actionWithJumps(2, 30, new ccGridSize(15, 10), t));
        }
Example #46
0
 public void DrawRect(CCPoint position, CCSize size, CCColor4B fillColor, float borderThickness, CCColor4B borderColor) => DrawRect(position, size.Width, size.Height, fillColor, borderThickness, borderColor);
Example #47
0
        public SpriteOffsetAnchorSkew()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
                cache.AddSpriteFramesWithFile("animations/grossini.plist");
                cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");

                //
                // Animation using Sprite batch
                //
                CCSprite sprite = new CCSprite("grossini_dance_01.png");
                sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2));

                CCSprite point = new CCSprite("Images/r1");
                point.Scale    = 0.25f;
                point.Position = sprite.Position;
                AddChild(point, 1);

                switch (i)
                {
                case 0:
                    sprite.AnchorPoint = new CCPoint(0, 0);
                    break;

                case 1:
                    sprite.AnchorPoint = new CCPoint(0.5f, 0.5f);
                    break;

                case 2:
                    sprite.AnchorPoint = new CCPoint(1, 1);
                    break;
                }

                point.Position = sprite.Position;

                var    animFrames = new List <CCSpriteFrame>();
                string tmp        = "";
                for (int j = 0; j < 14; j++)
                {
                    tmp = string.Format("grossini_dance_{0:00}.png", j + 1);
                    CCSpriteFrame frame = cache.SpriteFrameByName(tmp);
                    animFrames.Add(frame);
                }

                CCAnimation animation = new CCAnimation(animFrames, 0.3f);
                sprite.RunAction(new CCRepeatForever(new CCAnimate(animation)));

                animFrames = null;

                CCSkewBy         skewX      = new CCSkewBy(2, 45, 0);
                CCActionInterval skewX_back = (CCActionInterval)skewX.Reverse();
                CCSkewBy         skewY      = new CCSkewBy(2, 0, 45);
                CCActionInterval skewY_back = (CCActionInterval)skewY.Reverse();

                CCFiniteTimeAction seq_skew = new CCSequence(skewX, skewX_back, skewY, skewY_back);
                sprite.RunAction(new CCRepeatForever((CCActionInterval)seq_skew));

                AddChild(sprite, 0);
            }
        }
Example #48
0
 public void DrawRect(CCPoint position, CCSize size, CCColor4B fillColor) => DrawRect(position, size.Width, size.Height, fillColor, 0, CCColor4B.Transparent);
        public override void InitScenes()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            m_pInScene.Position = new CCPoint(0, s.Height);
        }
 public static CCPoint GetPositionFromVelocity(CCPoint velocity, CCPoint actualPosition, CCSize size, CCSize winSize, float dt)
 {
     return(GetPositionFromVelocity(velocity, actualPosition, size.Width, size.Height, winSize.Width, winSize.Height, dt));
 }
Example #51
0
        public CameraCenterTest()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            CCSprite      sprite;
            CCOrbitCamera orbit;

            // LEFT-TOP
            sprite = new CCSprite();//::node();
            sprite.init();
            addChild(sprite, 0);
            sprite.position = (new CCPoint(s.width / 5 * 1, s.height / 5 * 1));
            sprite.Color    = (new ccColor3B(Color.Red));
            sprite.setTextureRect(new CCRect(0, 0, 120, 50));
            orbit = CCOrbitCamera.actionWithDuration(10, 1, 0, 0, 360, 0, 0);
            //sprite.runAction(CCRepeatForever.actionWithAction( orbit));
            //		[sprite setAnchorPoint: CCPointMake(0,1));



            // LEFT-BOTTOM
            sprite = new CCSprite();//::node();
            sprite.init();
            addChild(sprite, 0, 40);
            sprite.position = (new CCPoint(s.width / 5 * 1, s.height / 5 * 4));
            sprite.Color    = new ccColor3B(Color.Blue);
            sprite.setTextureRect(new CCRect(0, 0, 120, 50));
            orbit = CCOrbitCamera.actionWithDuration(10, 1, 0, 0, 360, 0, 0);
            //sprite.runAction(CCRepeatForever.actionWithAction( orbit ));
            //		[sprite setAnchorPoint: CCPointMake(0,0));


            // RIGHT-TOP
            sprite = new CCSprite();//::node();
            sprite.init();
            addChild(sprite, 0);
            sprite.position = (new CCPoint(s.width / 5 * 4, s.height / 5 * 1));
            sprite.Color    = new ccColor3B(Color.Yellow);
            sprite.setTextureRect(new CCRect(0, 0, 120, 50));
            orbit = CCOrbitCamera.actionWithDuration(10, 1, 0, 0, 360, 0, 0);
            //sprite.runAction(CCRepeatForever.actionWithAction(orbit));
            //		[sprite setAnchorPoint: CCPointMake(1,1));


            // RIGHT-BOTTOM
            sprite = new CCSprite();//::node();
            sprite.init();
            addChild(sprite, 0, 40);
            sprite.position = (new CCPoint(s.width / 5 * 4, s.height / 5 * 4));
            sprite.Color    = new ccColor3B(Color.Green);
            sprite.setTextureRect(new CCRect(0, 0, 120, 50));
            orbit = CCOrbitCamera.actionWithDuration(10, 1, 0, 0, 360, 0, 0);
            // sprite.runAction(CCRepeatForever.actionWithAction(orbit));
            //		[sprite setAnchorPoint: CCPointMake(1,0));

            // CENTER
            sprite = new CCSprite();
            sprite.init();
            addChild(sprite, 0, 40);
            sprite.position = (new CCPoint(s.width / 2, s.height / 2));
            sprite.Color    = new ccColor3B(Color.White);
            sprite.setTextureRect(new CCRect(0, 0, 120, 50));
            orbit = CCOrbitCamera.actionWithDuration(10, 1, 0, 0, 360, 0, 0);
            // sprite.runAction(CCRepeatForever.actionWithAction(orbit));
            //		[sprite setAnchorPoint: CCPointMake(0.5f, 0.5f));
        }
        void RenderDrawPrimTest()
        {
            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            var visibleRect = VisibleBoundsWorldspace;

            CCDrawNode drawNode = new CCDrawNode();

            // *NOTE* Using the Director.ContentScaleFactor for now until we work something out with the initialization
            // CCDrawPriitives should be able to do this converstion themselves.

            // draw a simple line
            // The default state is:
            // Line Width: 1
            // color: 255,255,255,255 (white, non-transparent)
            // Anti-Aliased
            //  glEnable(GL_LINE_SMOOTH);
            float     lineWidth = 1.0f;
            CCColor4B lineColor = CCColor4B.White;

            drawNode.DrawLine(visibleRect.LeftBottom(), visibleRect.RightTop(), lineWidth);

            // line: color, width, aliased
            lineWidth = 5.0f;
            lineColor = CCColor4B.Red;
            drawNode.DrawLine(visibleRect.LeftTop(), visibleRect.RightBottom(), lineWidth, lineColor);

            // TIP:
            // If you are going to use always thde same color or width, you don't
            // need to call it before every draw
            //

            // draw big point in the center

            drawNode.DrawSolidCircle(visibleRect.Center(), 64.0f, new CCColor4B(0, 0, 255, 128));

            // draw 4 small points
            CCPoint[] points = { new CCPoint(60, 60), new CCPoint(70, 70), new CCPoint(60, 70), new CCPoint(70, 60) };
            foreach (CCPoint point in points)
            {
                drawNode.DrawSolidCircle(point, 8.0f, new CCColor4B(0, 255, 255, 255));
            }

            // draw a green circle with 10 segments
            drawNode.DrawCircle(visibleRect.Center, 100.0f, 10, CCColor4B.Green);

            // draw an arc
            drawNode.DrawSolidArc(visibleRect.Center, 10.0f, 0, 180, CCColor4B.AliceBlue);

            // draw an ellipse within rectangular region
            drawNode.DrawEllipse(new CCRect(100, 100, 100, 200), 10.0f, CCColor4B.Red);


            // open yellow poly
            CCPoint[] vertices =
            {
                new CCPoint(0,  0), new CCPoint(50, 50), new CCPoint(100, 50), new CCPoint(100, 100),
                new CCPoint(50, 100)
            };

            // draw quad bezier path
            drawNode.DrawQuadBezier(
                new CCPoint(0, size.Height),
                visibleRect.Center,
                (CCPoint)visibleRect.Size,
                50,
                10.0f,
                new CCColor4B(255, 0, 255, 255));

            // draw cubic bezier path
            drawNode.DrawCubicBezier(
                visibleRect.Center,
                new CCPoint(size.Width / 2 + 30, size.Height / 2 + 50),
                new CCPoint(size.Width / 2 + 60, size.Height / 2 - 50),
                new CCPoint(size.Width, size.Height / 2), 100, 10.0f,
                new CCColor4B(255, 0, 255, 255));

            //draw a solid polygon
            CCPoint[] vertices3 =
            {
                new CCPoint(60, 160), new CCPoint(70, 190), new CCPoint(100, 190),
                new CCPoint(90, 160)
            };

            drawNode.DrawPolygon(vertices3, 4, new CCColor4F(1, 1, 0, 1), 1.0f, new CCColor4F(1, 1, 0, 1));

            AddChild(drawNode);
        }
 public static CCPoint GetPositionFromVelocity(CCPoint velocity, CCNode node, float dt, CCSize winSize)
 {
     return(GetPositionFromVelocity(velocity, node.Position, node.BoundingBox.Size, winSize, dt));
 }
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize     windowSize = Layer.VisibleBoundsWorldspace.Size;
            CCDrawNode draw       = new CCDrawNode();

            AddChild(draw, 10);

            var s = windowSize;

            // Draw 10 circles
            for (int i = 0; i < 10; i++)
            {
                draw.DrawSolidCircle(s.Center, 10 * (10 - i),
                                     new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1));
            }

            // Draw polygons
            CCV3F_C4B[] points = new CCV3F_C4B[3];

            points[0].Colors   = CCColor4B.Red;
            points[0].Colors.A = 127;

            points[1].Colors   = CCColor4B.Green;
            points[1].Colors.A = 127;

            points[2].Colors   = CCColor4B.Blue;
            points[2].Colors.A = 127;

            points[0].Vertices.X = windowSize.Height / 4;
            points[0].Vertices.Y = 0;

            points[1].Vertices.X = windowSize.Width;
            points[1].Vertices.Y = windowSize.Height / 5;

            points[2].Vertices.X = windowSize.Width / 3 * 2;
            points[2].Vertices.Y = windowSize.Height;

            draw.DrawTriangleList(points);

            // star poly (triggers buggs)
            {
                const float o    = 80;
                const float w    = 20;
                const float h    = 50;
                CCPoint[]   star = new CCPoint[]
                {
                    new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),                               // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),               // right spike
                };

                draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }

            // star poly (doesn't trigger bug... order is important un tesselation is supported.
            {
                const float o    = 180;
                const float w    = 20;
                const float h    = 50;
                var         star = new CCPoint[]
                {
                    new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),    // right spike
                    new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2),            // top spike
                    new CCPoint(o - h, o + w),                                               // left spike
                };

                draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }


            // Draw segment
            draw.DrawLine(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1), CCLineCap.Round);

            draw.DrawLine(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                          new CCColor4F(1, 0, 1, 0.5f), CCLineCap.Round);
        }
        public override void draw()
        {
            base.draw();

            CCApplication app = CCApplication.sharedApplication();
            CCSize        s   = CCDirector.sharedDirector().getWinSize();

            // draw a simple line
            // The default state is:
            // Line Width: 1
            // color: 255,255,255,255 (white, non-transparent)
            // Anti-Aliased
            //glEnable(GL_LINE_SMOOTH);
            CCDrawingPrimitives.ccDrawLine(new CCPoint(0, 0), new CCPoint(s.width, s.height), new ccColor4F(255, 255, 255, 255));

            // line: color, width, aliased
            // glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
            // GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
            //glDisable(GL_LINE_SMOOTH);
            //glLineWidth( 5.0f );
            /*glColor4ub(255,0,0,255);*/
            //glColor4f(1.0, 0.0, 0.0, 1.0);
            CCDrawingPrimitives.ccDrawLine(new CCPoint(0, s.height), new CCPoint(s.width, 0), new ccColor4F(255, 0, 0, 255));

            // TIP:
            // If you are going to use always the same color or width, you don't
            // need to call it before every draw
            //
            // Remember: OpenGL is a state-machine.

            // draw big point in the center
            //glPointSize(64);
            /*glColor4ub(0,0,255,128);*/
            //glColor4f(0.0, 0.0, 1.0, 0.5);
            //ccDrawPoint( CCPointMake(s.width / 2, s.height / 2) );

            // draw 4 small points
            CCPoint[] points = { new CCPoint(60, 60), new CCPoint(70, 70), new CCPoint(60, 70), new CCPoint(70, 60) };
            //glPointSize(4);
            /*glColor4ub(0,255,255,255);*/
            //glColor4f(0.0, 1.0, 1.0, 1.0);
            //ccDrawPoints( points, 4);

            // draw a green circle with 10 segments
            //glLineWidth(16);
            /*glColor4ub(0, 255, 0, 255);*/
            //glColor4f(0.0, 1.0, 0.0, 1.0);
            CCDrawingPrimitives.ccDrawCircle(new CCPoint(s.width / 2, s.height / 2), 100, 0, 10, false, new ccColor4B(0, 255, 0, 255));

            // draw a green circle with 50 segments with line to center
            //glLineWidth(2);
            /*glColor4ub(0, 255, 255, 255);*/
            //glColor4f(0.0, 1.0, 1.0, 1.0);
            CCDrawingPrimitives.ccDrawCircle(new CCPoint(s.width / 2, s.height / 2), 50, ccMacros.CC_DEGREES_TO_RADIANS(90), 50, true, new ccColor4B(0, 255, 255, 255));

            // open yellow poly
            /*glColor4ub(255, 255, 0, 255);*/
            //glColor4f(1.0, 1.0, 0.0, 1.0);
            //glLineWidth(10);
            CCPoint[] vertices = { new CCPoint(0, 0), new CCPoint(50, 50), new CCPoint(100, 50), new CCPoint(100, 100), new CCPoint(50, 100) };
            CCDrawingPrimitives.ccDrawPoly(vertices, 5, false, new ccColor4F(255, 255, 0, 255));

            // closed purble poly
            /*glColor4ub(255, 0, 255, 255);*/
            //glColor4f(1.0, 0.0, 1.0, 1.0);
            //glLineWidth(2);
            CCPoint[] vertices2 = { new CCPoint(30, 130), new CCPoint(30, 230), new CCPoint(50, 200) };
            CCDrawingPrimitives.ccDrawPoly(vertices2, 3, true, new ccColor4F(255, 0, 255, 255));

            // draw quad bezier path
            CCDrawingPrimitives.ccDrawQuadBezier(new CCPoint(0, s.height),
                                                 new CCPoint(s.width / 2, s.height / 2),
                                                 new CCPoint(s.width, s.height),
                                                 50,
                                                 new ccColor4F(255, 255, 0, 255));

            // draw cubic bezier path
            CCDrawingPrimitives.ccDrawCubicBezier(new CCPoint(s.width / 2, s.height / 2),
                                                  new CCPoint(s.width / 2 + 30, s.height / 2 + 50),
                                                  new CCPoint(s.width / 2 + 60, s.height / 2 - 50),
                                                  new CCPoint(s.width, s.height / 2), 100,
                                                  new ccColor4F(255, 0, 255, 255));

            // restore original values
            //glLineWidth(1);
            /*glColor4ub(255,255,255,255);*/
            //glColor4f(1.0, 1.0, 1.0, 1.0);
            //glPointSize(1);
        }
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize windowSize = VisibleBoundsWorldspace.Size;

            var move = new CCMoveBy(4, new CCPoint(windowSize.Width / 2, 0));

            backGround.Position   = VisibleBoundsWorldspace.Left();
            backGround.PositionX += windowSize.Width / 4;

            // Run background animation
            backGround.RepeatForever(move, move.Reverse());

            backGround.DrawSolidCircle(CCPoint.Zero, 220, CCColor4B.White);
            AddChild(backGround);


            var color = CCColor4B.Red;
            var alpha = (byte)(255 * 0.3f);

            color.A = alpha;

            // Draw polygons
            //P1: 380:-160 P2: 200:-240 P3: 160:-420
            CCPoint[] points = new CCPoint[]
            {
                //P1: 380:-160 P2: 200:-240 P3: 160:-420
                new CCPoint(380, -160),
                new CCPoint(200, -240),
                new CCPoint(160, -420),
            };

            DrawSolidPolygon(points, color);

            //P1: 160:-420 P2: 200:-520 P3: 360:-540
            points[0] = new CCPoint(160, -420);
            points[1] = new CCPoint(200, -520);
            points[2] = new CCPoint(360, -540);

            DrawSolidPolygon(points, color);

            //P1: 360:-540 P2: 420:-600 P3: 520:-520
            points[0] = new CCPoint(360, -540);
            points[1] = new CCPoint(420, -600);
            points[2] = new CCPoint(530, -520);

            DrawSolidPolygon(points, color);

            //P1: 520:-520 P2: 380:-160 P3: 160:-420
            points[0] = new CCPoint(520, -520);
            points[1] = new CCPoint(380, -160);
            points[2] = new CCPoint(160, -420);

            DrawSolidPolygon(points, color);

            // P1: 160:-420 P2: 360:-540 P3: 520:-520
            points[0] = new CCPoint(160, -420);
            points[1] = new CCPoint(360, -540);
            points[2] = new CCPoint(520, -520);

            DrawSolidPolygon(points, color);

            drawTriangles.Position = windowSize.Center;
            // Offset by the bounds of the polygons to more or less center it
            drawTriangles.PositionX -= 370;
            drawTriangles.PositionY += 440;
        }
Example #57
0
        /// <summary>
        ///  Implement CCDirector and CCScene init code here.
        /// </summary>
        /// <returns>
        ///  true  Initialize success, app continue.
        ///  false Initialize failed, app terminate.
        /// </returns>
        public override bool ApplicationDidFinishLaunching()
        {
            //initialize director
            CCDirector pDirector = CCDirector.SharedDirector;

            pDirector.SetOpenGlView();

            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);
            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);

            // turn on display FPS
            pDirector.DisplayStats = true;
            // set FPS. the default value is 1.0/60 if you don't call this
            pDirector.AnimationInterval = 1.0 / 60;
            CCSize designSize = new CCSize(480, 320);

            if (CCDrawManager.FrameSize.Height > 320)
            {
                CCSize resourceSize = new CCSize(960, 640);
                CCContentManager.SharedContentManager.SearchPaths.Add("hd");

                /*
                 * CCContentManager.SharedContentManager.SearchPaths.Add("hd/extensions");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("extensions");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("hd/animations");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("animations");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("hd/TileMaps");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("TileMaps");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("hd/ccb");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("ccb");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("hd/Images");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("Particles");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("Sounds");
                 * CCContentManager.SharedContentManager.SearchPaths.Add("TileMaps");
                 */
                pDirector.ContentScaleFactor = resourceSize.Height / designSize.Height;
            }

            CCDrawManager.SetDesignResolutionSize(designSize.Width, designSize.Height, CCResolutionPolicy.ShowAll);

/*
 #if WINDOWS || WINDOWSGL
 *          CCDrawManager.SetDesignResolutionSize(1280, 768, CCResolutionPolicy.ExactFit);
 #else
 *          CCDrawManager.SetDesignResolutionSize(800, 480, CCResolutionPolicy.ShowAll);
 *          //CCDrawManager.SetDesignResolutionSize(480, 320, CCResolutionPolicy.ShowAll);
 #endif
 */

            // create a scene. it's an autorelease object
            CCScene pScene = new CCScene();
            CCLayer pLayer = new TestController();

            /*
             * CCScene pScene = CCScene.node();
             * var pLayer = Box2DView.viewWithEntryID(0);
             * pLayer.scale = 10;
             * pLayer.anchorPoint = new CCPoint(0, 0);
             * pLayer.position = new CCPoint(CCDirector.sharedDirector().getWinSize().width / 2, CCDirector.sharedDirector().getWinSize().height / 4);
             */

            pScene.AddChild(pLayer);
            pDirector.RunWithScene(pScene);

            return(true);
        }
Example #58
0
        public CCRect rect()
        {
            CCSize s = Texture.ContentSizeInPixels;

            return(new CCRect(-s.Width / 2, -s.Height / 2, s.Width, s.Height));
        }
 public Background(CCSize size, CCColor4B color)
 {
     Color       = new CCColor3B(color);
     Opacity     = color.A;
     AnchorPoint = CCPoint.AnchorMiddle;
 }
Example #60
0
        public new static CCActionInterval actionWithDuration(float t)
        {
            CCSize size = CCDirector.SharedDirector.WinSize;

            return(new CCLens3D(new CCPoint(size.Width / 2, size.Height / 2), 240, new CCGridSize(15, 10), t));
        }