Exemple #1
0
 public override void update(float dt)
 {
     if (m_pTarget != null)
     {
         m_pTarget.position = CCPointExtension.ccp(m_startPosition.x + m_delta.x * dt,
                                                   m_startPosition.y + m_delta.y * dt);
     }
 }
 public override void update(float dt)
 {
     if (m_pTarget != null)
     {
         // Is % equal to fmodf()???
         float frac = (dt * m_nJumps) % 1.0f;
         float y    = m_height * 4 * frac * (1 - frac);
         y += m_delta.y * dt;
         float x = m_delta.x * dt;
         m_pTarget.position = CCPointExtension.ccp(m_startPosition.x + x, m_startPosition.y + y);
     }
 }
        public override void ccTouchEnded(CCTouch touch, CCEvent eve)
        {
            CCPoint location          = touch.locationInView(touch.view());
            CCPoint convertedLocation = CCDirector.sharedDirector().convertToGL(location);

            CCPoint pos = new CCPoint(0, 0);

            if (m_background != null)
            {
                pos = m_background.convertToWorldSpace(new CCPoint(0, 0));
            }
            m_emitter.position = CCPointExtension.ccpSub(convertedLocation, pos);
        }
Exemple #4
0
 //BOOL initWithTexture(CCTexture2D* aTexture);
 //virtual void setTexture(CCTexture2D* newTexture);
 public void move(float delta)
 {
     this.position =
         CCPointExtension.ccpAdd(position, CCPointExtension.ccpMult(m_velocity, delta));
     if (position.x > 320 - radius())
     {
         position      = new CCPoint(320 - radius(), position.y);
         m_velocity.x *= -1;
     }
     else if (position.x < radius())
     {
         position      = new CCPoint(radius(), position.y);
         m_velocity.x *= -1;
     }
 }
        public override void ccTouchesMoved(List <cocos2d.CCTouch> touches, cocos2d.CCEvent event_)
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            var     it    = touches.FirstOrDefault();
            CCTouch touch = (CCTouch)(it);
            CCPoint start = touch.locationInView(touch.view());

            start = CCDirector.sharedDirector().convertToGL(start);

            CCPoint diff = new CCPoint(s.width / 2 - start.x, s.height / 2 - start.y);

            diff = CCPointExtension.ccpNormalize(diff);

            CCLayerGradient gradient = (CCLayerGradient)getChildByTag(1);

            gradient.Vector = diff;
        }
Exemple #6
0
        public void ccTouchesMoved(List <CCObject> touches, CCEvent events)
        {
            foreach (var it in touches)
            {
                CCTouch touch = (CCTouch)it;
                CCPoint start = touch.locationInView(touch.view());
                start = CCDirector.sharedDirector().convertToGL(start);
                CCPoint end = touch.previousLocationInView(touch.view());

                // begin drawing to the render texture
                //m_pTarget->begin();

                // for extra points, we'll draw this smoothly from the last position and vary the sprite's
                // scale/rotation/offset
                float distance = CCPointExtension.ccpDistance(start, end);
                if (distance > 1)
                {
                    int    d    = (int)distance;
                    Random rand = new Random();

                    for (int i = 0; i < d; i++)
                    {
                        float difx  = end.x - start.x;
                        float dify  = end.y - start.y;
                        float delta = (float)i / distance;
                        m_pBrush.position = new CCPoint(start.x + (difx * delta), start.y + (dify * delta));
                        m_pBrush.rotation = rand.Next() % 360;
                        float r = (float)(rand.Next() % 50 / 50.0f) + 0.25f;
                        m_pBrush.scale = r;
                        /*m_pBrush->setColor(ccc3(CCRANDOM_0_1() * 127 + 128, 255, 255));*/
                        // Use CCRANDOM_0_1() will cause error when loading libtests.so on android, I don't know why.
                        m_pBrush.Color = new ccColor3B {
                            r = (byte)(rand.Next() % 127 + 128), g = 255, b = 255
                        };
                        // Call visit to draw the brush, don't call draw..
                        m_pBrush.visit();
                    }
                }
            }
            // finish drawing and return context back to the screen
            //m_pTarget->end();
        }
Exemple #7
0
        public int check_for_error(CCPoint p1, CCPoint p2, CCPoint p3, CCPoint p4, float s, float t)
        {
            //	the hit point is		p3 + t * (p4 - p3);
            //	the hit point also is	p1 + s * (p2 - p1);

            CCPoint p4_p3     = CCPointExtension.ccpSub(p4, p3);
            CCPoint p4_p3_t   = CCPointExtension.ccpMult(p4_p3, t);
            CCPoint hitPoint1 = CCPointExtension.ccpAdd(p3, p4_p3_t);

            CCPoint p2_p1     = CCPointExtension.ccpSub(p2, p1);
            CCPoint p2_p1_s   = CCPointExtension.ccpMult(p2_p1, s);
            CCPoint hitPoint2 = CCPointExtension.ccpAdd(p1, p2_p1_s);

            // Since float has rounding errors, only check if diff is < 0.05
            if ((Math.Abs(hitPoint1.x - hitPoint2.x) > 0.1f) || (Math.Abs(hitPoint1.y - hitPoint2.y) > 0.1f))
            {
                Debug.WriteLine("ERROR: (%f,%f) != (%f,%f)", hitPoint1.x, hitPoint1.y, hitPoint2.x, hitPoint2.y);
                return(1);
            }

            return(0);
        }
        public override void ccTouchesMoved(List <CCTouch> touches, CCEvent events)
        {
            foreach (var it in touches)
            {
                CCTouch touch = it;
                CCPoint start = touch.locationInView(touch.view());
                start = CCDirector.sharedDirector().convertToGL(start);
                CCPoint end = touch.previousLocationInView(touch.view());
                end = CCDirector.sharedDirector().convertToGL(end);

                // begin drawing to the render texture
                //m_target->begin();

                // for extra points, we'll draw this smoothly from the last position and vary the sprite's
                // scale/rotation/offset
                float distance = CCPointExtension.ccpDistance(start, end);
                if (distance > 1)
                {
                    int    d    = (int)distance;
                    Random rand = new Random();
                    ;
                    for (int i = 0; i < d; i++)
                    {
                        float difx  = end.x - start.x;
                        float dify  = end.y - start.y;
                        float delta = (float)i / distance;
                        m_brush.position = new CCPoint(start.x + (difx * delta), start.y + (dify * delta));
                        m_brush.rotation = rand.Next() % 360;
                        float r = ((float)(rand.Next() % 50) / 50.0f) + 0.25f;
                        m_brush.scale = r;
                        // Call visit to draw the brush, don't call draw..
                        m_brush.visit();
                    }
                }
                // finish drawing and return context back to the screen
                //m_target->end(false);
            }
        }
Exemple #9
0
        public TMXOrthoZorder()
        {
            CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/orthogonal-test-zorder");

            base.addChild(map, 0, kTagTileMap);

            CCSize s = map.contentSize;

            ////----UXLOG("ContentSize: %f, %f", s.width,s.height);

            m_tamara = CCSprite.spriteWithFile(TestResource.s_pPathSister1);
            map.addChild(m_tamara, map.children.Count);
            m_tamara.anchorPoint = new CCPoint(0.5f, 0);

            CCActionInterval   move = CCMoveBy.actionWithDuration(10, CCPointExtension.ccpMult(new CCPoint(400, 450), 1 / ccMacros.CC_CONTENT_SCALE_FACTOR()));
            CCFiniteTimeAction back = move.reverse();
            CCFiniteTimeAction seq  = CCSequence.actions(move, back);

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


            schedule((this.repositionSprite));
        }
Exemple #10
0
        public TMXOrthoVertexZ()
        {
            CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/orthogonal-test-vertexz");

            addChild(map, 0, TileMapTestScene.kTagTileMap);

            CCSize s = map.contentSize;
            ////----UXLOG("ContentSize: %f, %f", s.width,s.height);

            // because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
            // can use any CCSprite and it will work OK.
            CCTMXLayer layer = map.layerNamed("trees");

            m_tamara = layer.tileAt(new CCPoint(0, 11));
            CCLog.Log("{0} vertexZ: {1}", m_tamara, m_tamara.vertexZ);

            CCActionInterval   move = CCMoveBy.actionWithDuration(10, CCPointExtension.ccpMult(new CCPoint(400, 450), 1 / CCDirector.sharedDirector().ContentScaleFactor));
            CCFiniteTimeAction back = move.reverse();
            CCFiniteTimeAction seq  = CCSequence.actions(move, back);

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

            schedule(repositionSprite);
        }
 public override void startWithTarget(CCNode target)
 {
     base.startWithTarget(target);
     m_delta = CCPointExtension.ccp(m_delta.x - m_startPosition.x, m_delta.y - m_startPosition.y);
 }
 public override void startWithTarget(CCNode target)
 {
     base.startWithTarget(target);
     m_startPosition = target.position;
     m_delta         = CCPointExtension.ccpSub(m_endPosition, m_startPosition);
 }
 public override CCFiniteTimeAction reverse()
 {
     return(CCJumpBy.actionWithDuration(m_fDuration, CCPointExtension.ccp(-m_delta.x, -m_delta.y), m_height, m_nJumps));
 }
Exemple #14
0
        public override bool init()
        {
            Random rand = new Random();

            if (base.init())
            {
                //      // seed
                //      srand(0);

                CCPoint A, B, C, D, p1, p2, p3, p4;
                float   s, t;

                int err = 0;
                int ok  = 0;

                //
                // Test 1.
                //
                Debug.WriteLine("Test1 - Start");
                for (int i = 0; i < 10000; i++)
                {
                    // A | b
                    // -----
                    // c | d
                    float ax = rand.Next() * -5000;
                    float ay = rand.Next() * 5000;

                    // a | b
                    // -----
                    // c | D
                    float dx = rand.Next() * 5000;
                    float dy = rand.Next() * -5000;

                    // a | B
                    // -----
                    // c | d
                    float bx = rand.Next() * 5000;
                    float by = rand.Next() * 5000;

                    // a | b
                    // -----
                    // C | d
                    float cx = rand.Next() * -5000;
                    float cy = rand.Next() * -5000;

                    A = new CCPoint(ax, ay);
                    B = new CCPoint(bx, by);
                    C = new CCPoint(cx, cy);
                    D = new CCPoint(dx, dy);
                    //if (CCPointExtension.ccpLineIntersect(A, D, B, C, ref s, ref t))
                    //{
                    //    if (check_for_error(A, D, B, C, s, t) != 0)
                    //        err++;
                    //    else
                    //        ok++;
                    //}
                }
                Debug.WriteLine("Test1 - End. OK=%i, Err=%i", ok, err);

                //
                // Test 2.
                //
                Debug.WriteLine("Test2 - Start");

                p1 = new CCPoint(220, 480);
                p2 = new CCPoint(304, 325);
                p3 = new CCPoint(264, 416);
                p4 = new CCPoint(186, 416);
                s  = 0.0f;
                t  = 0.0f;
                if (CCPointExtension.ccpLineIntersect(p1, p2, p3, p4, ref s, ref t))
                {
                    check_for_error(p1, p2, p3, p4, s, t);
                }

                Debug.WriteLine("Test2 - End");


                //
                // Test 3
                //
                Debug.WriteLine("Test3 - Start");

                ok  = 0;
                err = 0;
                for (int i = 0; i < 10000; i++)
                {
                    // A | b
                    // -----
                    // c | d
                    float ax = rand.Next() * -500;
                    float ay = rand.Next() * 500;
                    p1 = new CCPoint(ax, ay);

                    // a | b
                    // -----
                    // c | D
                    float dx = rand.Next() * 500;
                    float dy = rand.Next() * -500;
                    p2 = new CCPoint(dx, dy);


                    //////

                    float y = ay - ((ay - dy) / 2.0f);

                    // a | b
                    // -----
                    // C | d
                    float cx = rand.Next() * -500;
                    p3 = new CCPoint(cx, y);

                    // a | B
                    // -----
                    // c | d
                    float bx = rand.Next() * 500;
                    p4 = new CCPoint(bx, y);

                    s = 0.0f;
                    t = 0.0f;
                    if (CCPointExtension.ccpLineIntersect(p1, p2, p3, p4, ref s, ref t))
                    {
                        if (check_for_error(p1, p2, p3, p4, s, t) != 0)
                        {
                            err++;
                        }
                        else
                        {
                            ok++;
                        }
                    }
                }

                Debug.WriteLine("Test3 - End. OK=%i, err=%i", ok, err);
                return(true);
            }

            return(false);
        }
 public override CCFiniteTimeAction reverse()
 {
     return(CCMoveBy.actionWithDuration(m_fDuration, CCPointExtension.ccp(-m_delta.x, -m_delta.y)));
 }