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 CCBezierBy(float t, CCBezierConfig config) : base(t) { BezierConfig = config; }
public CCBezierBy (float t, CCBezierConfig config) : base (t) { BezierConfig = config; }