Beispiel #1
0
    public override void OnAwake()
    {
        CreateBackground();

        //Create a container for "GamePlay" (a bunch of floating berries)
        _gameplayContainer = Library.New<CinchSprite>("StrawberriesContainer");
        AddChild(_gameplayContainer);

        //pausing this Clock will pause all children
        _gameplayContainer.Clock = new GameClock("GameplayClock");

        //Create 15 FloatingStrawberry's
        for (var i=0; i<7000; i++)
        {
            _gameplayContainer.AddChild(Library.New<FloatingStrawberry>("Berry" + Random.Range (1, 1000)));
        }

        //Create a button to pause gameplay
        _pause = CinchSprite.NewFromImage("Cinch2D/Pause");
        AddChild(_pause);
        //SetPosition is faster than setting X and Y individually, since X and Y each cause display chain updates
        _pause.SetPosition(ViewportWidth/2 - _pause.Width, ViewportHeight/2 - _pause.Height);
        _pause.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, Pause);

        //Create a button to start gameplay
        _play = CinchSprite.NewFromImage("Cinch2D/Play");
        AddChild(_play);
        _play.SetPosition(ViewportWidth/2 - _play.Width, ViewportHeight/2 - _play.Height);
        _play.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, Play);
        _play.Visible = false;
    }
Beispiel #2
0
    public override void OnAwake()
    {
        CreateBackground();

        _cardsContainer = Library.New<CinchSprite>("CardsContainer");
        AddChild(_cardsContainer);
        _cardsContainer.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, MoveCardToTop);

        float cardWidth = 100f;
        float cardHeight = 128f;

        CinchOptions.DefaultPixelsPerMeter = 100f;
        for (var number = 0; number < 5; number++)
        {
            for (var suit = 0; suit < 4; suit++){
                //even though the coordinate system is bottom up, sprite sheets default to top-down coordinates
                //this can be reversed by setting CinchOptions.UseTopLeftSpriteSheetCoordinates = false
                var left = number * cardWidth;	//move from left to right 100 px at a time
                var top = suit * cardHeight;	//move top to bottom 128 px at a time
                var pixPerMeter = 100f;

                var newCard = CinchSprite.NewFromSpriteSheet("Cinch2D/PlayingCards", left, top, cardWidth, cardHeight, pixPerMeter);
                _cardsContainer.AddChild(newCard);

                //give the cards random positions and rotations
                newCard.X = ViewportWidth * Random.Range(-.4f, .4f);
                newCard.Y = ViewportHeight * Random.Range(-.4f, .4f);
                newCard.RotationDegrees = Random.Range (-45f, 45f);
            }
        }
    }
    private void MoveCardToTop(MouseEvent e)
    {
        var targetCard = (CinchSprite)e.Target;

        //adding something that has already been added will just float it to the top
        _cardsContainer.AddChild(targetCard);
    }
    public override void OnAwake()
    {
        CreateBackground();

        _cardsContainer = Library.New <CinchSprite>("CardsContainer");
        AddChild(_cardsContainer);
        _cardsContainer.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, MoveCardToTop);

        float cardWidth  = 100f;
        float cardHeight = 128f;

        CinchOptions.DefaultPixelsPerMeter = 100f;
        for (var number = 0; number < 5; number++)
        {
            for (var suit = 0; suit < 4; suit++)
            {
                //even though the coordinate system is bottom up, sprite sheets default to top-down coordinates
                //this can be reversed by setting CinchOptions.UseTopLeftSpriteSheetCoordinates = false
                var left        = number * cardWidth;           //move from left to right 100 px at a time
                var top         = suit * cardHeight;            //move top to bottom 128 px at a time
                var pixPerMeter = 100f;

                var newCard = CinchSprite.NewFromSpriteSheet("Cinch2D/PlayingCards", left, top, cardWidth, cardHeight, pixPerMeter);
                _cardsContainer.AddChild(newCard);

                //give the cards random positions and rotations
                newCard.X = ViewportWidth * Random.Range(-.4f, .4f);
                newCard.Y = ViewportHeight * Random.Range(-.4f, .4f);
                newCard.RotationDegrees = Random.Range(-45f, 45f);
            }
        }
    }
Beispiel #5
0
    public override void OnAwake()
    {
        CreateBackground();

        //Create a container for "GamePlay" (a bunch of floating berries)
        _gameplayContainer = Library.New <CinchSprite>("StrawberriesContainer");
        AddChild(_gameplayContainer);

        //pausing this Clock will pause all children
        _gameplayContainer.Clock = new GameClock("GameplayClock");

        //Create 15 FloatingStrawberry's
        for (var i = 0; i < 15; i++)
        {
            _gameplayContainer.AddChild(Library.New <FloatingStrawberry>("Berry" + Random.Range(1, 1000)));
        }

        //Create a button to pause gameplay
        _pause = CinchSprite.NewFromImage("Cinch2D/Pause");
        AddChild(_pause);
        //SetPosition is faster than setting X and Y individually, since X and Y each cause display chain updates
        _pause.SetPosition(ViewportWidth / 2 - _pause.Width, ViewportHeight / 2 - _pause.Height);
        _pause.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, Pause);

        //Create a button to start gameplay
        _play = CinchSprite.NewFromImage("Cinch2D/Play");
        AddChild(_play);
        _play.SetPosition(ViewportWidth / 2 - _play.Width, ViewportHeight / 2 - _play.Height);
        _play.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, Play);
        _play.Visible = false;
    }
Beispiel #6
0
    private Joe CreateJoe()
    {
        var joe = Library.New <Joe>("Joe");

        _joesContainer.AddChild(joe);
        var velX = Random.Range(-2f, 2f);
        var velY = Random.Range(-2f, 2f);

        joe.Rotation     = -90 + Mathf.Atan2(velY, velX) * Mathf.Rad2Deg;
        joe.FakeVelocity = new Vector2(velX, velY);
        return(joe);
    }
Beispiel #7
0
    public override void OnEnterFrame(float time)
    {
        base.OnEnterFrame(time);

        for (var i = _gameplayContainer.NumChildren - 1; i >= 0; i--)
        {
            //reset to center if we've drifted too far
            var child = _gameplayContainer.GetChildAt(i);
            if (Mathf.Abs(child.X) > ViewportWidth / 2 || Mathf.Abs(child.Y) > ViewportHeight / 2)
            {
                child.Destroy();
            }
        }

        if (_gameplayContainer.NumChildren < 700)
        {
            _gameplayContainer.AddChild(Library.New <FloatingStrawberry>("Berry" + Random.Range(1, 1000)));
        }
    }
Beispiel #8
0
    public override void OnAwake()
    {
        CreateBackground();
        CinchOptions.DefaultPixelsPerMeter = 180;

        //make a container clip at the lower left corner
        CinchSprite lastParent = Library.New <CinchSprite>("root");

        AddChild(lastParent);
        lastParent.Rotation = 0f;

        for (var i = 0; i < 20; i++)
        {
            var newSprite = CinchSprite.NewFromImage("Cinch2D/Strawberry");
            lastParent.AddChild(newSprite);
            newSprite.X        = .6f;
            newSprite.Rotation = 12f;
            newSprite.ScaleX   = newSprite.ScaleY = .95f;

            lastParent = newSprite;
        }
    }