public void ScaleBalloon(float touchForce, float maxTouchForce) { if (gamePaused == false) { if (touchForce >= 1) { CCScaleTo scaleUpTo = new CCScaleTo(0.25f, 1 + float.Parse((touchForce / 3).ToString())); this.touchForce = touchForce; balloonSprite.RunActions(scaleUpTo, new CCCallFunc(() => { if (touchForce >= Math.Floor(double.Parse(maxTouchForce.ToString()))) { this.touchForce = -1; ExplodeBalloon(); } })); } else { CCScaleTo scaleDownTo = new CCScaleTo(0.25f, 1); balloonSprite.RunAction(scaleDownTo); } } }
void AddBalloon() { string previousBestTime = GetDefault(PREVIOUS_BEST_TIME_KEY); string currentTime = ((CCLabel)stopwatchSprite.GetChildByTag(1)).Text; TimeSpan currentTimeSpan = new TimeSpan(int.Parse(currentTime.Split(':')[0]), int.Parse(currentTime.Split(':')[1]), int.Parse(currentTime.Split(':')[2])); previousTimeSpan = (String.IsNullOrWhiteSpace(previousBestTime) ? new TimeSpan(0, 0, 0) : new TimeSpan(int.Parse(previousBestTime.Split(':')[0]), int.Parse(previousBestTime.Split(':')[1]), int.Parse(previousBestTime.Split(':')[2]))); GetRandomBalloonColor(); balloonSprite = new CCSprite("Balloon:" + balloonColor); balloonSprite.Name = "Balloon:" + balloonColor; balloonSprite.PositionX = layerWidth / 2 + 3; balloonSprite.PositionY = 0; balloonSprite.Opacity = 200; balloonMoved = false; balloonLaunched = false; balloonXVelocity = 0; balloonYVelocity = 0; newBalloonYVelocity = 0; lastPlayTime = DateTime.Now; if ((currentTimeSpan.TotalSeconds - previousTimeSpan.TotalSeconds) > 0) { CCEaseIn shakeIn; CCEaseOut shakeOut; CCEaseIn shakeBackIn; CCEaseOut shakeBackOut; CCCallFunc resetFunction; CCCallFunc bestTimeAlertFunction; CCSequence motionSequence; shakeIn = new CCEaseIn(new CCMoveBy(0.05f, new CCPoint(15, 0)), 1f); shakeOut = new CCEaseOut(new CCMoveBy(0.05f, new CCPoint(-30, 0)), 1f); resetFunction = new CCCallFunc(() => ((CCLabel)previousBestTimeSprite.GetChildByTag(1)).Text = currentTime); shakeBackIn = new CCEaseIn(new CCMoveBy(0.1f, new CCPoint(30, 0)), 1f); shakeBackOut = new CCEaseOut(new CCMoveBy(0.1f, new CCPoint(-15, 0)), 1f); bestTimeAlertFunction = new CCCallFunc(() => ShowBestTimeAlert()); motionSequence = new CCSequence(shakeIn, shakeOut, resetFunction, shakeBackIn, shakeBackOut, bestTimeAlertFunction); previousTimeSpan = currentTimeSpan; previousBestTimeSprite.RunAction(motionSequence); SetDefault(((CCLabel)stopwatchSprite.GetChildByTag(1)).Text, PREVIOUS_BEST_TIME_KEY); } else { ControlMenu("Show"); } AddChild(balloonSprite); balloonSprite.RunActions(new CCScaleTo(0.10f, 1.5f), new CCScaleTo(0.10f, 1f)); }
protected override void AddedToScene() { base.AddedToScene(); var bounds = VisibleBoundsWorldspace; var action = new CCScaleTo(1.0f, 1.0f); titleLabel.Position = new CCPoint(bounds.Center.X, 50); menu.Position = new CCPoint(bounds.Center.X, bounds.MaxY - 100); onOffSwitch.Scale = 0.1f; onOffSwitch.RunActions(action); frequencyLabel.Position = new CCPoint(bounds.Center.X, bounds.Center.Y + 120); frequencyKnob.Scale = 0.0f; frequencyKnob.Position = bounds.Center; frequencyKnob.AnchorPoint = new CCPoint(0.5f, 0.5f); frequencyKnob.RunActions(action); var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesBegan = OnTouchesBegan; touchListener.OnTouchesMoved = OnTouchesMoved; touchListener.OnTouchesEnded = OnTouchesEnded; AddEventListener(touchListener, this); UpdateFrequency(frequency); var appDelegate = Application.ApplicationDelegate as AppDelegate; if (appDelegate != null && appDelegate.BackButtonWasPressed != null) { Schedule((dt) => { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { appDelegate.BackButtonWasPressed(); } }); } }
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); } } }
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"); }
/* Play a list of animations */ public void PlayAnims(string[] animList) { CCFiniteTimeAction[] actions = new CCFiniteTimeAction[animList.Length]; for (int i = 0; i < animList.Length; i++) { if (anims.ContainsKey(animList[i])) { actions[i] = (CCFiniteTimeAction)anims[animList[i]]; } else { return; } } sprite.RunActions(actions); }
public override void OnEnter() { base.OnEnter(); CCSprite child = new CCSprite(s_pPathGrossini); child.Position = Layer.VisibleBoundsWorldspace.Size.Center; AddChild(child, 1); //Sum of all action's duration is 1.5 second. child.RunAction(new CCRotateBy(1.5f, 90)); child.RunActions(new CCDelayTime(1.4f), new CCFadeOut(1.1f)); //After 1.5 second, self will be removed. RunActions(new CCDelayTime(1.4f), new CCCallFunc((removeThis))); }
CCSprite AddBanana() { var spriteSheet = new CCSpriteSheet("animations/monkey.plist"); var banana = new CCSprite(spriteSheet.Frames.Find((x) => x.TextureFilename.StartsWith("Banana"))); var p = GetRandomPosition(banana.ContentSize); banana.Position = p; banana.Scale = 0.5f; AddChild(banana); var moveBanana = new CCMoveTo(5.0f, new CCPoint(banana.Position.X, 0)); banana.RunActions(moveBanana, moveBananaComplete); banana.RepeatForever(rotateBanana); return(banana); }
void ShowActivityIndicator(bool startIndicator) { CCSprite activityIndicatorSprite; if (gameLayer.GetChildByTag(1) == null) { activityIndicatorSprite = new CCSprite("ActivityIndicator"); activityIndicatorSprite.Tag = 1; activityIndicatorSprite.Opacity = 0; activityIndicatorSprite.Name = "ActivityIndicator"; activityIndicatorSprite.PositionX = 27; activityIndicatorSprite.PositionY = 25; activityIndicatorSprite.ContentSize = new CCSize(48, 48); gameLayer.AddChild(activityIndicatorSprite); } else { activityIndicatorSprite = (CCSprite)gameLayer.GetChildByTag(1); } if (startIndicator == true) { activityTask = new Task((taskObject) => { CCSprite activityIndicatorTaskSprite = (CCSprite)taskObject; activityIndicatorTaskSprite.RunActions(new CCFadeIn(1), new CCRotateBy(60, 360 * 12)); }, activityIndicatorSprite); ControlMenu("Hide"); activityTask.Start(); } else { activityTask.Dispose(); activityIndicatorSprite.RunAction(new CCFadeOut(1)); gameLayer.RemoveChild(activityIndicatorSprite); ControlMenu("Show"); } }
void OnTouchesEnded(List <CCTouch> touches, CCEvent touchEvent) { monkey.StopAllActions(); var location = touches [0].LocationOnScreen; location = WorldToScreenspace(location); //Layer.WorldToScreenspace(location); float ds = CCPoint.Distance(monkey.Position, location); var dt = ds / MONKEY_SPEED; 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); }
CCSprite AddBanana() { var banana = new CCSprite("Banana"); double rnd = new Random().NextDouble(); double randomX = (rnd > 0) ? rnd * CCDirector.SharedDirector.WinSize.Width - banana.ContentSize.Width / 2 : banana.ContentSize.Width / 2; banana.Position = new CCPoint((float)randomX, CCDirector.SharedDirector.WinSize.Height - banana.ContentSize.Height / 2); AddChild(banana); var moveBanana = new CCMoveTo(5.0f, new CCPoint(banana.Position.X, 0)); banana.RunActions(moveBanana, moveBananaComplete); banana.RepeatForever(rotateBanana); return(banana); }
CCSprite ShootBanana() { if (bananaBatch.ChildrenCount < MAX_BANANAS_COUNT) { var banana = new CCSprite(bananasTexture); //var p = GetRandomPosition (banana.ContentSize); banana.Position = new CCPoint(monkey.Position.X, monkey.Position.Y + (banana.ContentSize.Height / 2)); banana.Scale = 0.5f; bananaBatch.AddChild(banana, 1); var moveBanana = new CCMoveTo(1 / _BananaSpeed, new CCPoint(banana.Position.X, VisibleBoundsWorldspace.Size.Height + banana.ContentSize.Height / 2)); banana.RunActions(moveBanana, moveBananaComplete); banana.RepeatForever(rotateBanana); CCSimpleAudioEngine.SharedEngine.PlayEffect("Sounds/EnemyShoot.wav"); return(banana); } return(null); }
private void AddMonster(float time) { var selectedMonster = new Random().Next() % _monsters.Count; var monster = _monsters[selectedMonster]; var m = monster.Movement; //!IMPORTANT -- Every Sprite in Screen must be an new CCSprite! Each Sprite can only be one time on screen var spriteMonster = new CCSprite(monster.MonsterSprite); spriteMonster.Scale = _appScale; spriteMonster.Tag = monster.Tag; //BLOCK 1 - Determine where to spawn the monster along the Y axis var winSize = Window.WindowSizeInPixels; var minX = (spriteMonster.ContentSize.Width / 2); var maxX = winSize.Width - spriteMonster.ContentSize.Width / 2; var rangeX = maxX - minX; var actualY = (new Random().Next() % rangeX) + minX; //BLOCK 2 - Determine speed of the monster var minDuration = monster.MinVelocity; var maxDuration = monster.MaxVelocity; var rangeDuration = maxDuration - minDuration; var actualDuration = (new Random().Next() % rangeDuration) + minDuration; if (m == 1) { spriteMonster.Position = new CCPoint(actualY, winSize.Height + spriteMonster.ContentSize.Height / 2); AddChild(spriteMonster); var actionMove = new CCMoveTo(actualDuration, new CCPoint(actualY, -spriteMonster.ContentSize.Height / 2)); var actionMoveComplete = new CCCallFuncN(node => { _monstersOnScreen.Remove(node); node.RemoveFromParent(); _lives--; var index = _hearths.Count - 1; RemoveChild(_hearths[index]); _hearths.RemoveAt(index); if (_lives == 0) { Window.DefaultDirector.ReplaceScene(GameStartLayer.GameStartLayerScene(Window)); } }); spriteMonster.RunActions(actionMove, actionMoveComplete); _monstersOnScreen.Add(spriteMonster); } else if (m == 2) { spriteMonster.Position = new CCPoint(actualY, winSize.Height + spriteMonster.ContentSize.Height / 2); AddChild(spriteMonster); var actionMoveComplete = new CCCallFuncN(node => { _monstersOnScreen.Remove(node); node.RemoveFromParent(); _lives--; var index = _hearths.Count - 1; RemoveChild(_hearths[index]); _hearths.RemoveAt(index); if (_lives == 0) { Window.DefaultDirector.ReplaceScene(GameStartLayer.GameStartLayerScene(Window)); } }); var bezierList = new List <CCFiniteTimeAction>(); var bezier = new CCBezierConfig(); var splitDuration = actualDuration / 6.0f; CCBezierTo bezierAction; for (int i = 0; i < 6; i++) { if (i % 2 == 0) { bezier.ControlPoint1 = new CCPoint(actualY + 100, winSize.Height - (100 + (i * 200))); bezier.ControlPoint2 = new CCPoint(actualY + 100, winSize.Height - (100 + (i * 200))); bezier.EndPosition = new CCPoint(actualY, winSize.Height - (200 + (i * 200))); bezierAction = new CCBezierTo(splitDuration, bezier); } else { bezier.ControlPoint1 = new CCPoint(actualY - 100, winSize.Height - (100 + (i * 200))); bezier.ControlPoint2 = new CCPoint(actualY - 100, winSize.Height - (100 + (i * 200))); bezier.EndPosition = new CCPoint(actualY, winSize.Height - (200 + (i * 200))); bezierAction = new CCBezierTo(splitDuration, bezier); } bezierList.Add(bezierAction); } bezierList.Add(actionMoveComplete); var seq = new CCSequence(bezierList.ToArray()); spriteMonster.RunAction(seq); _monstersOnScreen.Add(spriteMonster); } }
public void HideBackground() { background_white.Visible = true; background.RunActions(new CCFadeOut(1.5f), new CCCallFunc(OnBackgroundHided)); }
public GameLayer(float scaleX, float scaleY) { contentScaleFactorY = scaleY; contentScaleFactorX = scaleX; var speedFactor = contentScaleFactorX < contentScaleFactorY ? contentScaleFactorX : contentScaleFactorY; monkeySpeed *= (float)speedFactor; var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesEnded = OnTouchesEnded; AddEventListener(touchListener, this); Color = new CCColor3B(CCColor4B.White); Opacity = 255; visibleBananas = new List <CCSprite> (); hitBananas = new List <CCSprite> (); // batch node for physics balls ballsBatch = new CCSpriteBatchNode("balls", 100); ballTexture = ballsBatch.Texture; AddChild(ballsBatch, 1, 1); AddGrass(); AddSun(); StartScheduling(); CCSimpleAudioEngine.SharedEngine.PlayBackgroundMusic("sounds/backgroundMusic", true); #if IOS wormhole = new Wormhole("group.com.mikebluestein.GoneBananas", "messageDir"); wormhole.ListenForMessage <int> ("dpad", (message) => { CCPoint ds; float delta = 25.0f; switch (message) { case 1: //right float dx0 = allowableMovementRect.Size.Width - monkey.Position.X; delta = dx0 < delta ? dx0 : delta; ds = new CCPoint(delta, 0); break; case 2: //left delta = monkey.Position.X - delta < 0 ? 0 : delta; ds = new CCPoint(-delta, 0); break; case 3: //up float dy0 = allowableMovementRect.Size.Height - monkey.Position.Y; delta = dy0 < delta ? dy0 : delta; ds = new CCPoint(0, delta); break; case 4: //down delta = monkey.Position.Y - delta < 0 ? 0 : delta; ds = new CCPoint(0, -delta); break; default: ds = new CCPoint(); break; } var dt = delta / monkeySpeed; var moveMonkey = new CCMoveBy(dt, ds); monkey.RunAction(walkRepeat); monkey.RunActions(moveMonkey, new CCDelayTime(0.2f), walkAnimStop); }); #endif }