Beispiel #1
0
        void MoveBoat(bool ignoreWindspeedChange)
        {
            if ((windSpeedChanged == true) ||
                (ignoreWindspeedChange == true))
            {
                CCRepeatForever boatMovingAnimation;
                CCSequence      boatMovingSequence;

                if (windSpeed > 0)
                {
                    float      targetPositionX = (windBlowingRight == true ? layerWidth + boatSprite.ContentSize.Width : -boatSprite.ContentSize.Width);
                    CCMoveTo   moveAcrossTo    = new CCMoveTo(windSpeed * 1.4f, new CCPoint(targetPositionX, boatSprite.PositionY));
                    CCCallFunc resetPositionX  = new CCCallFunc(() => boatSprite.PositionX = (windBlowingRight == true ? -boatSprite.ContentSize.Width :
                                                                                              layerWidth + boatSprite.ContentSize.Width));
                    CCEaseSineIn easeInAcrossTo = new CCEaseSineIn(moveAcrossTo);

                    previousWindSpeed   = windSpeed * 1.4f;
                    boatMovingSequence  = new CCSequence(resetPositionX, moveAcrossTo);
                    boatMovingAnimation = new CCRepeatForever(boatMovingSequence);

                    boatSprite.StopAllActions();
                    boatSprite.RunActions(easeInAcrossTo, boatMovingAnimation);
                }
                else if (previousWindSpeed > 0)
                {
                    float         targetPositionX = (windBlowingRight == true ? previousWindSpeed * 7 : previousWindSpeed * -7);
                    CCEaseSineOut easeOutBy       = new CCEaseSineOut(new CCMoveBy(previousWindSpeed * 1.2f, new CCPoint(targetPositionX, 0)));
                    CCEaseSineOut easeOutSlowerBy = new CCEaseSineOut(new CCMoveBy(previousWindSpeed * 1.4f, new CCPoint(targetPositionX, 0)));
                    CCEaseSineIn  easeInTo        = new CCEaseSineIn(new CCMoveTo(0.5f, new CCPoint(boatSprite.PositionX, oceanSprite.PositionY +
                                                                                                    boatSprite.ContentSize.Height / 2 - 3)));
                    CCCallFunc resetBoatPositionX = new CCCallFunc(() =>
                    {
                        if ((windBlowingRight == true) &&
                            (boatSprite.PositionX >= layerWidth + boatSprite.ContentSize.Width))
                        {
                            boatSprite.PositionX = -boatSprite.ContentSize.Width;
                        }
                        else if ((windBlowingRight == false) &&
                                 (boatSprite.PositionX <= -boatSprite.ContentSize.Width))
                        {
                            boatSprite.PositionX = layerWidth + boatSprite.ContentSize.Width;
                        }
                    });

                    boatMovingSequence = new CCSequence(easeOutBy, resetBoatPositionX, easeOutSlowerBy, easeInTo, boatAnimation);

                    boatSprite.StopAllActions();
                    boatSprite.RunAction(boatMovingSequence);
                }
            }
        }
Beispiel #2
0
        void UpdateMonkeyMovements(float dt)
        {
            if (Math.Abs(AccelerometerValue) > 0.5f)
            {
                CCPoint pos = monkey.Position;
                pos += new CCPoint(MONKEY_SPEED * AccelerometerValue * dt, 0);

                if (pos.X > VisibleBoundsWorldspace.Size.Width)
                {
                    pos.X = VisibleBoundsWorldspace.Size.Width;
                }
                else if (pos.X < 0)
                {
                    pos.X = 0;
                }

                monkey.Position = pos;
            }
            else
            {
                AccelerometerValue = 0;
            }

            if (Math.Abs(AccelerometerValue) < 0.5f)
            {
                monkey.StopAllActions();
            }
            else
            {
                if (monkey.NumberOfRunningActions < 1)
                {
                    monkey.RunAction(walkRepeat);
                }
            }
        }
        void OnTouchesEnded(List <CCTouch> touches, CCEvent touchEvent)
        {
            monkey.StopAllActions();

            var location = touches [0].LocationOnScreen;

            location = WorldToScreenspace(location);

            if (location.Y >= allowableMovementRect.Size.Height)
            {
                location.Y = allowableMovementRect.Size.Height;
            }

            float ds = CCPoint.Distance(monkey.Position, location);

            var dt = ds / monkeySpeed;

            var moveMonkey = new CCMoveTo(dt, location);

            //BUG: calling walkRepeat separately as it doesn't run when called in RunActions or CCSpawn
            monkey.RunAction(walkRepeat);
            monkey.RunActions(moveMonkey, walkAnimStop);

            // move the clouds relative to the monkey's movement
            MoveClouds(location.Y - monkey.Position.Y);
        }
Beispiel #4
0
        private void stopGame()
        {
            _running = false;
            //stop all actions currently running (meteors, health drops, animations...)
            int      i;
            int      count;
            CCSprite sprite;

            count = _fallingObjects.Count;
            for (i = count - 1; i >= 0; i--)
            {
                sprite = _fallingObjects[i];
                sprite.StopAllActions();
                sprite.Visible = false;
                _fallingObjects.RemoveAt(i);
            }
            if (_bomb.Visible)
            {
                _bomb.StopAllActions();
                _bomb.Visible = false;
                CCSprite child;
                child = (CCSprite)_bomb.GetChildByTag(kSpriteHalo);
                child.StopAllActions();
                child = (CCSprite)_bomb.GetChildByTag(kSpriteSparkle);
                child.StopAllActions();
            }
            if (_shockWave.Visible)
            {
                _shockWave.StopAllActions();
                _shockWave.Visible = false;
            }
        }
Beispiel #5
0
        private void resetHealth()
        {
            if (_fallingObjects.Count > 30)
            {
                return;
            }

            CCSprite health = (CCSprite)_healthPool[_healthPoolIndex];

            _healthPoolIndex++;
            if (_healthPoolIndex == _healthPool.Count)
            {
                _healthPoolIndex = 0;
            }

            int health_x        = CCRandom.GetRandomInt(0, 1000) % (int)(_screenSize.Width * 0.8f + _screenSize.Width * 0.1f);
            int health_target_x = CCRandom.GetRandomInt(0, 1000) % (int)(_screenSize.Width * 0.8f + _screenSize.Width * 0.1f);

            health.StopAllActions();
            health.Position = new CCPoint(health_x, _screenSize.Height + health.BoundingBox.Size.Height * 0.5f);

            //create action (swing, move to target, and call function when done)
            CCFiniteTimeAction sequence = new CCSequence(
                new CCMoveTo(_healthSpeed, new CCPoint(health_target_x, _screenSize.Height * 0.15f)),
                new CCCallFuncN(fallingObjectDone));

            health.Visible = true;
            health.RunAction(_swingHealth);
            health.RunAction(sequence);
            _fallingObjects.Add(health);
        }
Beispiel #6
0
        private void fallingObjectDone(CCNode pSenderobj)
        {
            CCSprite pSender = (CCSprite)pSenderobj;

            //remove it from array
            _fallingObjects.Remove(pSender);
            pSender.StopAllActions();
            pSender.Rotation = 0;

            //if object is a meteor...
            if (pSender.Tag == kSpriteMeteor)
            {
                _energy -= 15;
                //show explosion animation
                pSender.RunAction((CCAction)_groundHit);
                //play explosion sound
                CCSimpleAudioEngine.SharedEngine.PlayEffect("boom");

                //if object is a health drop...
            }
            else
            {
                pSender.Visible = false;

                //if energy is full, score points from falling drop
                if (_energy == 100)
                {
                    _score += 25;

                    _scoreDisplay.Text = String.Format("{0}", _score);
                }
                else
                {
                    _energy += 10;
                    if (_energy > 100)
                    {
                        _energy = 100;
                    }
                }

                //play health bonus sound
                CCSimpleAudioEngine.SharedEngine.PlayEffect("health.png");
            }

            //if energy is less or equal 0, game over
            if (_energy <= 0)
            {
                _energy = 0;
                stopGame();
                CCSimpleAudioEngine.SharedEngine.PlayEffect("fire_truck");
                //show GameOver
                _gameOverMessage.Visible = true;
            }

            _energyDisplay.Text = String.Format("{0}%", _energy);
        }
        public void OnTouchesEnded(List <CCTouch> touches, CCEvent touchEvent)
        {
            monkey.StopAllActions();
            var location = touches[0].LocationOnScreen;

            location = WorldToScreenspace(location);
            float ds = CCPoint.Distance(monkey.Position, location);

            var dt = ds / Money_Speed;

            var MoveMonkey = new CCMoveTo(dt, location);

            monkey.RunAction(walkRepeat);
            monkey.RunActions(MoveMonkey, walkAnimStop);
            CCSimpleAudioEngine.SharedEngine.PlayEffect("Sounds/tap");
        }
Beispiel #8
0
        public override void Update(float dt)
        {
            base.Update(dt);

            if (joystickPanel != null)
            {
                currentSprite.Position = joystickPanel.GetPlayerPosition(dt, VisibleBoundsWorldspace.Size);

                if (joystickPanel.HasAnyDirection)
                {
                    currentSprite.FlipX = (joystickPanel.JoyControl.IsRight);
                }

                if (isWalking && currentSprite.NumberOfRunningActions == 0)
                {
                    currentSprite.RunAction(currentAction);
                }

                if (!isWalking && currentSprite.NumberOfRunningActions > 0)
                {
                    currentSprite.StopAllActions();
                }
            }
        }
Beispiel #9
0
        public void Update(double sliderNewValue)
        {
            hito.StopAllActions();

            // 1回のCCMoveByアクションで進む距離を求める。0.15秒でスライダの値÷2進むことにする。
            var distanceUnit = (float)sliderNewValue / 2;

            // 何回のCCMoveByアクションで画面の端から端まで行けるかを算出。
            var actionCount = distance / distanceUnit;

            // Spriteの現在地情報から、終着点から最初の位置まで戻るアクションを入れる要素番号を取得する。
            var index = Convert.ToInt32(Math.Floor((distance - (hito.ContentSize.Width / 2) - hito.PositionX) / distanceUnit));

            // 端から端までCCMoveByで移動し、反対側の端に戻るシーケンスを組み立てる。
            var moveAction = new CCMoveBy(0.15f, new CCPoint(distanceUnit, 0));
            var backAction = new CCMoveTo(0, new CCPoint(firstPositionX, firstPositionY));
            List <CCFiniteTimeAction> actionList = Enumerable.Repeat <CCFiniteTimeAction>(moveAction, (int)actionCount).ToList();

            actionList.Insert(index, backAction);
            var sequence = new CCSequence(actionList.ToArray());

            // 上で組み立てたシーケンスを永遠に繰り返す。
            hito.RepeatForever(sequence);
        }
Beispiel #10
0
        private void resetMeteor()
        {
            //if too many objects on screen, return
            if (_fallingObjects.Count > 30)
            {
                return;
            }


            CCSprite meteor = _meteorPool[_meteorPoolIndex];

            _meteorPoolIndex++;
            if (_meteorPoolIndex == _meteorPool.Count)
            {
                _meteorPoolIndex = 0;
            }

            //pick start and target positions for new meteor
            int meteor_x        = CCRandom.GetRandomInt(1, 1000) % (int)((_screenSize.Width * 0.8f) + _screenSize.Width * 0.1f);
            int meteor_target_x = CCRandom.GetRandomInt(1, 1000) % (int)((_screenSize.Width * 0.8f) + _screenSize.Width * 0.1f);

            meteor.StopAllActions();
            meteor.Position = new CCPoint(meteor_x, _screenSize.Height + meteor.BoundingBox.Size.Height * 0.5f);

            //create action for meteor (rotate forever, move to target, and call function)
            CCRotateBy         rotate       = new CCRotateBy(0.5f, -90);
            CCAction           repeatRotate = new CCRepeatForever(rotate);
            CCFiniteTimeAction sequence     = new CCSequence(
                new CCMoveTo(_meteorSpeed, new CCPoint(meteor_target_x, _screenSize.Height * 0.15f)),
                new CCCallFuncN(fallingObjectDone));

            meteor.Visible = true;
            meteor.RunAction(repeatRotate);
            meteor.RunAction(sequence);
            _fallingObjects.Add(meteor);
        }
Beispiel #11
0
 public void StopActions()
 {
     sprite.StopAllActions();
 }
Beispiel #12
0
        void TouchesBegan(List <CCTouch> touches, CCEvent touchEvent)
        {
            // base.TouchesBegan(touches, touchEvent);

            if (!_running)
            {
                //if intro, hide intro message
                if (_introMessage.Visible)
                {
                    _introMessage.Visible = false;

                    //if game over, hide game over message
                }
                else if (_gameOverMessage.Visible)
                {
                    CCSimpleAudioEngine.SharedEngine.StopAllEffects();
                    _gameOverMessage.Visible = false;
                }

                resetGame();
                return;
            }

            CCTouch touch = touches.FirstOrDefault();

            if (touch != null)
            {
                //if bomb already growing...
                if (_bomb.Visible)
                {
                    //stop all actions on bomb, halo and sparkle
                    _bomb.StopAllActions();
                    CCSprite child;
                    child = (CCSprite)_bomb.GetChildByTag(kSpriteHalo);
                    ProcessSprite(child);
                    //child.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
                    child.StopAllActions();
                    child = (CCSprite)_bomb.GetChildByTag(kSpriteSparkle);
                    ProcessSprite(child);
                    //child.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
                    child.StopAllActions();

                    //if bomb is the right size, then create shockwave
                    if (_bomb.ScaleX > 0.3f)
                    {
                        _shockWave.Scale    = 0.1f;
                        _shockWave.Position = _bomb.Position;
                        _shockWave.Visible  = true;
                        _shockWave.RunAction(new CCScaleTo(0.5f, _bomb.ScaleX * 2.0f));
                        _shockWave.RunAction((CCFiniteTimeAction)_shockwaveSequence);
                        CCSimpleAudioEngine.SharedEngine.PlayEffect("music/bombRelease");
                    }
                    else
                    {
                        CCSimpleAudioEngine.SharedEngine.PlayEffect("music/bombFail");
                    }
                    _bomb.Visible = false;
                    //reset hits with shockwave, so we can count combo hits
                    _shockwaveHits = 0;

                    //if no bomb currently on screen, create one
                }
                else
                {
                    CCPoint tap = touch.LocationOnScreen;;;                       //??¿¿?¿?
                    tap.Y = Window.WindowSizeInPixels.Height - tap.Y;

                    _bomb.StopAllActions();
                    _bomb.Scale    = 0.1f;
                    _bomb.Position = tap;
                    _bomb.Visible  = true;
                    _bomb.Opacity  = 50;
                    _bomb.RunAction(_growBomb);

                    CCSprite child;
                    child = (CCSprite)_bomb.GetChildByTag(kSpriteHalo);
                    ProcessSprite(child);
                    //child.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
                    child.RunAction(_rotateSprite);
                    child = (CCSprite)_bomb.GetChildByTag(kSpriteSparkle);
                    ProcessSprite(child);
                    //child.BlendFunc = new CCBlendFunc(blendSrc, blendDst);
                    child.RunAction(_rotateSprite);
                }
            }
        }