Example #1
0
        // made public for debugging, may make it private later:
        private void Spawn()
        {
            var fruit = new Fruit();

            if (Layer == null)
            {
                throw new InvalidOperationException("Need to set Layer before spawning");
            }

            fruit.PositionX = CCRandom.GetRandomFloat(0 + fruit.Radius, Layer.ContentSize.Width - fruit.Radius);
            fruit.PositionY = Layer.ContentSize.Height + fruit.Radius;

            if (CCRandom.Float_0_1() > .5f)
            {
                fruit.FruitColor = FruitColor.Red;
            }
            else
            {
                fruit.FruitColor = FruitColor.Yellow;
            }


            if (FruitSpawned != null)
            {
                FruitSpawned(fruit);
            }
        }
Example #2
0
        private void performanceScale(CCSprite pSprite)
        {
            CCSize size = CCDirector.SharedDirector.WinSize;

            pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            pSprite.Scale    = CCRandom.Float_0_1() * 100 / 50;
        }
        private void performanceActions20(CCSprite pSprite)
        {
            CCSize size = CCDirector.SharedDirector.WinSize;

            if (CCRandom.Float_0_1() < 0.2f)
            {
                pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            }
            else
            {
                pSprite.Position = new CCPoint(-1000, -1000);
            }

            float      period            = 0.5f + (CCRandom.Next() % 1000) / 500.0f;
            CCRotateBy rot               = new CCRotateBy(period, 360.0f * CCRandom.Float_0_1());
            var        rot_back          = (CCActionInterval)rot.Reverse();
            CCAction   permanentRotation = new CCRepeatForever(CCSequence.FromActions(rot, rot_back));

            pSprite.RunAction(permanentRotation);

            float            growDuration       = 0.5f + (CCRandom.Next() % 1000) / 500.0f;
            CCActionInterval grow               = new CCScaleBy(growDuration, 0.5f, 0.5f);
            CCAction         permanentScaleLoop = new CCRepeatForever(new CCSequence(grow, grow.Reverse()));

            pSprite.RunAction(permanentScaleLoop);
        }
        private void performanceScale(CCSprite pSprite)
        {
            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            pSprite.Scale    = CCRandom.Float_0_1() * 100 / 50;
        }
        void AddBall()
        {
            int idx    = (CCRandom.Float_0_1() > .5 ? 0 : 1);
            int idy    = (CCRandom.Float_0_1() > .5 ? 0 : 1);
            var sprite = new CCPhysicsSprite(ballTexture, new CCRect(32 * idx, 32 * idy, 32, 32), PTM_RATIO);

            ballsBatch.AddChild(sprite);

            CCPoint p = GetRandomPosition(sprite.ContentSize);

            sprite.Position = new CCPoint(p.X, p.Y);
            var def = new b2BodyDef();

            def.position       = new b2Vec2(p.X / PTM_RATIO, p.Y / PTM_RATIO);
            def.linearVelocity = new b2Vec2(0.0f, -1.0f);
            def.type           = b2BodyType.b2_dynamicBody;
            b2Body body = world.CreateBody(def);

            var circle = new b2CircleShape();

            circle.Radius = 0.5f;

            var fd = new b2FixtureDef();

            fd.shape       = circle;
            fd.density     = 1f;
            fd.restitution = 0.85f;
            fd.friction    = 0f;
            body.CreateFixture(fd);

            sprite.PhysicsBody = body;

            Console.WriteLine("sprite batch node count = {0}", ballsBatch.ChildrenCount);
        }
        private void performanceActions20(CCSprite pSprite)
        {
            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            if (CCRandom.Float_0_1() < 0.2f)
            {
                pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            }
            else
            {
                pSprite.Position = new CCPoint(-1000, -1000);
            }

            float      period            = 0.5f + (CCRandom.Next() % 1000) / 500.0f;
            CCRotateBy rot               = new CCRotateBy(period, 360.0f * CCRandom.Float_0_1());
            var        rot_back          = (CCFiniteTimeAction)rot.Reverse();
            CCAction   permanentRotation = new CCRepeatForever(new CCSequence(rot, rot_back));

            pSprite.RunAction(permanentRotation);

            float growDuration      = 0.5f + (CCRandom.Next() % 1000) / 500.0f;
            CCFiniteTimeAction grow = new CCScaleBy(growDuration, 0.5f, 0.5f);
            CCAction           permanentScaleLoop = new CCRepeatForever(new CCSequence(grow, grow.Reverse()));

            pSprite.RunAction(permanentScaleLoop);
        }
Example #7
0
        static cpVect rand_pos(float radius)
        {
            cpVect v;

            do
            {
                v = new cpVect(CCRandom.Float_0_1() * (640 - 2 * radius) - (320 - radius), CCRandom.Float_0_1() * (480 - 2 * radius) - (240 - radius));
            } while (cpVect.cpvlength(v) < 85.0);
            return(v);
        }
Example #8
0
        public void altertime(float dt)
        {
            var action1 = (CCSpeed)(m_grossini.GetActionByTag(EaseTest.kTagAction1));
            var action2 = (CCSpeed)(m_tamara.GetActionByTag(EaseTest.kTagAction1));
            var action3 = (CCSpeed)(m_kathia.GetActionByTag(EaseTest.kTagAction1));

            action1.Speed = CCRandom.Float_0_1() * 2;
            action2.Speed = CCRandom.Float_0_1() * 2;
            action3.Speed = CCRandom.Float_0_1() * 2;
        }
Example #9
0
        private Fruit GenerateFruit()
        {
            var fruit =
                CCRandom.Float_0_1() > .5f
                    ? new Fruit(FruitColor.Red, this)
                    : new Fruit(FruitColor.Yellow, this);

            fruit.Visible = false;

            return(fruit);
        }
        private void performanceout20(CCSprite pSprite)
        {
            CCSize size = CCDirector.SharedDirector.WinSize;

            if (CCRandom.Float_0_1() < 0.2f)
            {
                pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            }
            else
            {
                pSprite.Position = new CCPoint(-1000, -1000);
            }
        }
Example #11
0
        private void performanceout20(CCSprite pSprite)
        {
            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            if (CCRandom.Float_0_1() < 0.2f)
            {
                pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
            }
            else
            {
                pSprite.Position = new CCPoint(-1000, -1000);
            }
        }
Example #12
0
        public override void OnEnter()
        {
            base.OnEnter();


            space.SetIterations(1);

            bodyCount = 0;

            cpBody body;
            cpBall shape;

            for (var y = 0; y < image_height; y++)
            {
                for (var x = 0; x < image_width; x++)
                {
                    if (get_pixel(x, y) == 0)
                    {
                        continue;
                    }

                    float x_jitter = 0.05f * CCRandom.Float_0_1();
                    float y_jitter = 0.05f * CCRandom.Float_0_1();

                    shape = make_ball((2 * (x - image_width / 2 + x_jitter)), (2 * (image_height / 2 - y + y_jitter)));

                    space.AddBody(shape.body);
                    space.AddShape(shape);
                    bodyCount++;
                }
            }

            body = space.AddBody(new cpBody(1e9f, cp.Infinity));
            body.SetPosition(new cpVect(-1000, 0 - 10));
            body.SetVelocity(new cpVect(400, 0));

            shape = space.AddShape(new cpBall(body, 8, cpVect.Zero)) as cpBall;
            shape.SetElasticity(0);
            shape.SetFriction(0);
            shape.SetFilter(NOT_GRABBABLE_FILTER);
            shape.ball = true;

            bodyCount++;

            finishedLoad = true;

            Schedule();
        }
Example #13
0
        cpBody add_box(float size, float mass)
        {
            float radius = cpVect.cpvlength(new cpVect(size, size));

            cpBody body = space.AddBody(new cpBody(mass, cp.MomentForBox(mass, size, size)));

            body.SetPosition(new cpVect((float)CCRandom.Float_0_1() * (640 - 2 * radius) - (320 - radius), (float)CCRandom.Float_0_1() * (480 - 2 * radius) - (240 - radius)));


            cpShape shape = space.AddShape(cpPolyShape.BoxShape(body, size, size, 0));

            shape.SetElasticity(0);
            shape.SetFriction(0.7f);

            return(body);
        }
Example #14
0
        public CCEnemySprite(CCTexture2D f, CCRect r, float totalAliveTime, GameLayer.ShootBulletDelg shootbullet) : base(f, r)
        {
            this.mShootBulletCallback = shootbullet;
            this.mDidShootBullet      = false;
            this.mShootAtTime         = CCRandom.Float_0_1() * totalAliveTime;

            Schedule(t => { if (!mDidShootBullet)
                            {
                                mTimeDel += 0.5f;
                                if (mTimeDel > mShootAtTime)
                                {
                                    mDidShootBullet = true;
                                    if (mShootBulletCallback != null)
                                    {
                                        mShootBulletCallback(this);
                                    }
                                }
                            }
                     }, 0.5f);
        }
Example #15
0
        void AddEnemy()
        {
            if (enemyBatch.ChildrenCount < MAX_ENEMY_COUNT)
            {
                float         idx         = (CCRandom.Float_0_1() > .5 ? 0 : 1);
                float         idxOp       = 1 - idx;
                float         idy         = (float)(0.6 + (CCRandom.Float_0_1() * 0.2));
                CCEnemySprite enemySprite = new CCEnemySprite(enemyBatch.Texture, new CCRect(0, 0, enemyBatch.Texture.PixelsWide, enemyBatch.Texture.PixelsHigh), 5.0f, ShootBullet);
                enemySprite.Scale = 0.3f;
                enemyBatch.AddChild(enemySprite);

                enemySprite.Position = new CCPoint(idx * VisibleBoundsWorldspace.Size.Width, idy * VisibleBoundsWorldspace.Size.Height);
                //enemySprite.ZOrder  =

                // sending the enemy to the opposite direction
                var moveEnemy = new CCMoveTo(1 / _EnemySpeed, new CCPoint(idxOp * VisibleBoundsWorldspace.Size.Width,
                                                                          enemySprite.Position.Y));
                enemySprite.RunActions(moveEnemy, moveBananaComplete);
                //enemySprite.RepeatForever (rotateBanana);
            }
        }
Example #16
0
        void ShootBullet(CCSprite enemySprite)
        {
            if (ballsBatch.ChildrenCount < MAX_NUM_BALLS)
            {
                int idx    = (CCRandom.Float_0_1() > .5 ? 0 : 1);
                int idy    = (CCRandom.Float_0_1() > .5 ? 0 : 1);
                var sprite = new CCPhysicsSprite(ballTexture, new CCRect(32 * idx, 32 * idy, 32, 32), PTM_RATIO);

                ballsBatch.AddChild(sprite);

                //CCPoint p = GetRandomPosition (sprite.ContentSize);

                sprite.Position = enemySprite.Position;                // new CCPoint (p.X, p.Y);

                var def = new b2BodyDef();
                def.position = new b2Vec2(sprite.Position.X / PTM_RATIO, sprite.Position.Y / PTM_RATIO);
                Random rand = new Random();

                /*if(rand.Next (100) < 50)
                 * def.linearVelocity = new b2Vec2 (-10.0f, 0.0f);
                 * else
                 *      def.linearVelocity = new b2Vec2 (10.0f, 0.0f);*/
                def.linearVelocity = new b2Vec2(0.0f, -1.0f);
                def.type           = b2BodyType.b2_dynamicBody;
                b2Body body = world.CreateBody(def);

                var circle = new b2CircleShape();
                circle.Radius = 0.5f;

                var fd = new b2FixtureDef();
                fd.shape       = circle;
                fd.density     = 1f;
                fd.restitution = 0.85f;
                fd.friction    = 0f;
                body.CreateFixture(fd);

                sprite.PhysicsBody = body;
            }
        }
Example #17
0
        public void addNewSpriteAtPosition(CCPoint p)
        {
            //CCLog.Log("Add sprite #{2} : {0} x {1}", p.X, p.Y, _batch.ChildrenCount + 1);

            //We have a 64x64 sprite sheet with 4 different 32x32 images.  The following code is
            //just randomly picking one of the images
            int idx    = (CCRandom.Float_0_1() > .5 ? 0 : 1);
            int idy    = (CCRandom.Float_0_1() > .5 ? 0 : 1);
            var sprite = new CCPhysicsSprite(spriteTexture, new CCRect(32 * idx, 32 * idy, 32, 32));

            AddChild(sprite, 0, kTagForPhysicsSprite);

            sprite.Position = new CCPoint(p.X, p.Y);

            // Define the dynamic body.
            //Set up a 1m squared box in the physics world
            b2BodyDef def = new b2BodyDef();

            def.position = new b2Vec2(p.X / PTM_RATIO, p.Y / PTM_RATIO);
            def.type     = b2BodyType.b2_dynamicBody;
            b2Body body = _world.CreateBody(def);
            // Define another box shape for our dynamic body.
            var dynamicBox = new b2PolygonShape();

            dynamicBox.SetAsBox(.5f, .5f); //These are mid points for our 1m box

            // Define the dynamic body fixture.
            b2FixtureDef fd = new b2FixtureDef();

            fd.shape    = dynamicBox;
            fd.density  = 1f;
            fd.friction = 0.3f;
            b2Fixture fixture = body.CreateFixture(fd);

            sprite.PhysicsBody = body;
            //_world.SetContactListener(new Myb2Listener());

            // _world.Dump();
        }
Example #18
0
        private void pokeHoleAtPoint(CCPoint point)
        {
            float scale    = CCRandom.Float_0_1() * 0.2f + 0.9f;
            float rotation = CCRandom.Float_0_1() * 360f;

            CCSprite hole = new CCSprite("Images/hole_effect.png");

            hole.Position = point;
            hole.Rotation = rotation;
            hole.Scale    = scale;

            m_pHoles.AddChild(hole);

            CCSprite holeStencil = new CCSprite("Images/hole_stencil.png");

            holeStencil.Position = point;
            holeStencil.Rotation = rotation;
            holeStencil.Scale    = scale;

            m_pHolesStencil.AddChild(holeStencil);

            m_pOuterClipper.RunAction(new CCSequence(new CCScaleBy(0.05f, 0.95f), new CCScaleTo(0.125f, 1)));
        }
        void AddBall()
        {
            var contentScale = contentScaleFactorX < contentScaleFactorY ? contentScaleFactorX : contentScaleFactorY;             //use the smaller scale if they are not equal

            if (ballsBatch.ChildrenCount < MAX_NUM_BALLS)
            {
                int idx        = (CCRandom.Float_0_1() > .5 ? 0 : 1);
                int idy        = (CCRandom.Float_0_1() > .5 ? 0 : 1);
                var ballSprite = new CCPhysicsSprite(ballTexture, new CCRect(32 * idx, 32 * idy, 32, 32), PTM_RATIO);
                ballSprite.Scale = contentScale;

                ballsBatch.AddChild(ballSprite);

                CCPoint p = GetRandomPosition(ballSprite.ContentSize);

                ballSprite.Position = new CCPoint(p.X, p.Y);

                var def = new b2BodyDef();
                def.position       = new b2Vec2(p.X / PTM_RATIO, p.Y / PTM_RATIO);
                def.linearVelocity = new b2Vec2(0.0f, -1.0f);
                def.type           = b2BodyType.b2_dynamicBody;
                b2Body body = world.CreateBody(def);

                var circle = new b2CircleShape();
                circle.Radius = 0.5f * contentScale;

                var fd = new b2FixtureDef();
                fd.shape       = circle;
                fd.density     = 1f;
                fd.restitution = 0.85f;
                fd.friction    = 0f;
                body.CreateFixture(fd);

                ballSprite.PhysicsBody = body;
            }
        }
Example #20
0
        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.DrawDot(s.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)
            };
            draw.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
                };

                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.DrawSegment(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1));

            draw.DrawSegment(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                             new CCColor4F(1, 0, 1, 0.5f));

            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            var visibleRect = VisibleBoundsWorldspace;

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

            // draw cubic bezier path
            draw.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
            draw.DrawEllipse(new CCRect(100, 300, 100, 200), 2, CCColor4B.AliceBlue);
        }
Example #21
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);
        }
        public override bool Init()
        {
            base.Init();

            CCSize s = CCDirector.SharedDirector.WinSize;

            CCDrawNode draw = new CCDrawNode();

            AddChild(draw, 10);

            // Draw 10 circles
            for (int i = 0; i < 10; i++)
            {
                draw.DrawDot(new CCPoint(s.Width / 2, s.Height / 2), 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(s.Height / 4, 0),
                new CCPoint(s.Width, s.Height / 5),
                new CCPoint(s.Width / 3 * 2, s.Height)
            };
            draw.DrawPolygon(points, points.Length, new CCColor4F(1, 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
                    //				{o +w, o+w*2+h}, {o,o+w*2},					// top spike
                    //				{o -h, o+w}, {o,o},							// left 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.DrawSegment(new CCPoint(20, s.Height), new CCPoint(20, s.Height / 2), 10, new CCColor4F(0, 1, 0, 1));

            draw.DrawSegment(new CCPoint(10, s.Height / 2), new CCPoint(s.Width / 2, s.Height / 2), 40,
                             new CCColor4F(1, 0, 1, 0.5f));

            return(true);
        }
Example #23
0
        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.DrawDot(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.DrawSegment(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1));

            draw.DrawSegment(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                             new CCColor4F(1, 0, 1, 0.5f));
        }
Example #24
0
        public override void Update(float dt)
        {
            base.Update(dt);

            if (!_running)
            {
                return;
            }

            if (_lineContainer._lineType != lineTypes.LINE_NONE)
            {
                _lineContainer._tip = _rocket.Position;
            }

            //track collision with sides
            if (_rocket.collidedWithSides())
            {
                _lineContainer._lineType = lineTypes.LINE_NONE;
            }

            _rocket.Update(dt);

            //update jet particle so it follow rocket
            if (!_jet.IsActive)
            {
                _jet.ResetSystem();
            }

            _jet.RotationX = _rocket.RotationX;
            _jet.RotationY = _rocket.RotationY;


            _jet.Position = _rocket.Position;
            //_jet->setRotation(_rocket->getRotation());
            //_jet->setPosition(_rocket->getPosition());


            //update timers
            _cometTimer += dt;
            float newY;

            if (_cometTimer > _cometInterval)
            {
                _cometTimer = 0;
                if (_comet.Visible == false)
                {
                    _comet.PositionX = 0;

                    newY = CCRandom.Float_0_1() / (RAND_MAX / _screenSize.Height * 0.6f) + _screenSize.Height * 0.2f;

                    if (newY > _screenSize.Height * 0.9f)
                    {
                        newY = _screenSize.Height * 0.9f;
                    }

                    _comet.PositionY = newY;
                    _comet.Visible   = true;
                    _comet.ResetSystem();
                }
            }

            if (_comet.Visible)
            {
                //collision with comet
                if ((float)Math.Pow(_comet.PositionX - _rocket.PositionX, 2) +
                    (float)Math.Pow(_comet.PositionY - _rocket.PositionY, 2) <= (float)Math.Pow(_rocket._radius, 2))
                {
                    if (_rocket.Visible)
                    {
                        killPlayer();
                    }
                }
                _comet.PositionX = _comet.PositionX + 50 * dt;
                if (_comet.PositionX > _screenSize.Width * 1.5f)
                {
                    _comet.StopSystem();
                    _comet.Visible = false;
                }
            }

            _lineContainer.Update(dt);
            _rocket.Opacity = (byte)(_lineContainer._energy * 255);

            //collision with planets
            int        count = _planets.Count;
            GameSprite planet;

            for (int i = 0; i < count; i++)
            {
                planet = _planets[i];

                if ((float)Math.Pow(planet.PositionX - _rocket.PositionX, 2)
                    + (float)Math.Pow(planet.PositionY - _rocket.PositionY, 2) <=
                    (float)Math.Pow(_rocket._radius * 0.8f + planet._radius * 0.65f, 2))
                {
                    if (_rocket.Visible)
                    {
                        killPlayer();
                    }

                    break;
                }
            }

            //collision with star
            if ((float)Math.Pow(_star.PositionX - _rocket.PositionX, 2)
                + (float)Math.Pow(_star.PositionY - _rocket.PositionY, 2) <=
                (float)Math.Pow(_rocket._radius * 1.2f, 2))
            {
                _pickup.Position = _star.Position;
                _pickup.ResetSystem();

                if (_lineContainer._energy + 0.25f < 1)
                {
                    _lineContainer._energy = _lineContainer._energy + 0.25f;
                }
                else
                {
                    _lineContainer._energy = 1.0f;
                }
                _rocket._speed = _rocket._speed + 2;
                _lineContainer.setEnergyDecrement(0.001f);

                CCSimpleAudioEngine.SharedEngine.PlayEffect("pickup");
                resetStar();

                int points = 100 - (int)_timeBetweenPickups;
                if (points < 0)
                {
                    points = 0;
                }

                _score += points;

                _scoreDisplay.Text = String.Format("{0}", _score);

                _timeBetweenPickups = 0;
            }

            _timeBetweenPickups += dt;
            if (_lineContainer._energy == 0)
            {
                if (_rocket.Visible)
                {
                    killPlayer();
                }
            }
        }
Example #25
0
        public CCSprite createSpriteWithTag(int tag)
        {
            // create

            CCSprite sprite = null;

            switch (subtestNumber)
            {
            case 1:
            {
                sprite = new CCSprite("Images/grossinis_sister1");
                parent.AddChild(sprite, 0, tag + 100);
                break;
            }

            case 2:
            case 3:
            {
                sprite = new CCSprite(batchNode.Texture, new CCRect(0, 0, 52, 139));
                batchNode.AddChild(sprite, 0, tag + 100);
                break;
            }

            case 4:
            {
                var    idx = CCRandom.Next(1, 14);
                string str = string.Format("Images/grossini_dance_{0:00}", idx);
                sprite = new CCSprite(str);
                parent.AddChild(sprite, 0, tag + 100);
                break;
            }

            case 5:
            case 6:
            {
                int y, x;
                var r = (int)(CCRandom.Float_0_1() * 1400 / 100);

                y = r / 5;
                x = r % 5;

                x     *= 85;
                y     *= 121;
                sprite = new CCSprite(batchNode.Texture, new CCRect(x, y, 85, 121));
                batchNode.AddChild(sprite, 0, tag + 100);
                break;
            }

            case 7:
            {
                int y, x;
                var r = (int)(CCRandom.Float_0_1() * 1400 / 100);

                y = r / 8;
                x = r % 8;

                string str = string.Format("Images/sprites_test/sprite-{0}-{1}", x, y);
                sprite = new CCSprite(str);
                parent.AddChild(sprite, 0, tag + 100);
                break;
            }

            case 8:
            case 9:
            {
                int y, x;
                var r = (int)(CCRandom.Float_0_1() * 6400 / 100);

                y = r / 8;
                x = r % 8;

                x     *= 32;
                y     *= 32;
                sprite = new CCSprite(batchNode.Texture, new CCRect(x, y, 32, 32));
                batchNode.AddChild(sprite, 0, tag + 100);
                break;
            }

            default:
                break;
            }

            return(sprite);
        }