private void resetGame() { _rocket.Position = new CCPoint(_screenSize.Width * 0.5f, _screenSize.Height * 0.1f); _rocket.Opacity = 255; _rocket.Visible = true; _rocket.reset(); _cometInterval = 4; _cometTimer = 0; _timeBetweenPickups = 0.0f; _score = 0; _scoreDisplay.Text = String.Format("{0}", _score); _lineContainer.reset(); //TODO: shuffle grid cells //random_shuffle(_grid.begin(), _grid.end()); _gridIndex = 0; resetStar(); _warp.StopSystem(); _running = true; CCSimpleAudioEngine.SharedEngine.PlayBackgroundMusic("music/background", true); CCSimpleAudioEngine.SharedEngine.StopAllEffects(); CCSimpleAudioEngine.SharedEngine.PlayEffect("music/rocket", true); }
public void createParticles() { _jet = new CCParticleSystemQuad("jet.plist"); _jet.SourcePosition = new CCPoint(-_rocket._radius * 0.8f, 0); _jet.Angle = 180; _jet.StopSystem(); AddChild(_jet, kBackground); _boom = new CCParticleSystemQuad("boom.plist"); _boom.StopSystem(); AddChild(_boom, kForeground); _comet = new CCParticleSystemQuad("comet.plist"); _comet.StopSystem(); _comet.Position = new CCPoint(0, _screenSize.Height * 0.6f); _comet.Visible = false; AddChild(_comet, kForeground); _pickup = new CCParticleSystemQuad("plink.plist"); _pickup.StopSystem(); AddChild(_pickup, kMiddleground); _warp = new CCParticleSystemQuad("warp.plist"); _warp.Position = _rocket.Position; AddChild(_warp, kBackground); _star = new CCParticleSystemQuad("star.plist"); _star.StopSystem(); _star.Visible = false; AddChild(_star, kBackground, kSpriteStar); }
public void killPlayer() { CCSimpleAudioEngine.SharedEngine.StopBackgroundMusic(); CCSimpleAudioEngine.SharedEngine.StopAllEffects(); CCSimpleAudioEngine.SharedEngine.PlayEffect("music/shipBoom"); _boom.Position = _rocket.Position; _boom.ResetSystem(); _rocket.Visible = false; _jet.StopSystem(); // ->stopSystem(); _lineContainer._lineType = lineTypes.LINE_NONE; _running = false; _state = gamestates.kGameOver; _gameOver.Visible = true; _pauseBtn.Visible = false; }
public void createParticlesAsync() { isLoading = true; var label = new CCLabelTtf("Loading...", "MarkerFelt", 22); label.Position = _screenSize.Center; label.Position = new CCPoint(_screenSize.Center.X, _screenSize.Height * 0.75f); label.Visible = false; label.Name = "Loading"; AddChild(label, 10); var scale = new CCScaleBy(0.3f, 2); label.RunActions(new CCDelayTime(1.0f), new CCShow()); label.RepeatForever(scale, scale.Reverse()); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("jet.plist", (jetConfig) => { _jet = new CCParticleSystemQuad(jetConfig); _jet.SourcePosition = new CCPoint(-_rocket._radius * 0.8f, 0); _jet.Angle = 180; _jet.StopSystem(); AddChild(_jet, kBackground); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("boom.plist", (boomConfig) => { _boom = new CCParticleSystemQuad(boomConfig); _boom.StopSystem(); AddChild(_boom, kForeground); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("comet.plist", (cometConfig) => { _comet = new CCParticleSystemQuad(cometConfig); _comet.StopSystem(); _comet.Position = new CCPoint(0, _screenSize.Height * 0.6f); _comet.Visible = false; AddChild(_comet, kForeground); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("star.plist", (starConfig) => { _star = new CCParticleSystemQuad(starConfig); _star.StopSystem(); _star.Visible = false; AddChild(_star, kBackground, kSpriteStar); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("plink.plist", (plinkConfig) => { _pickup = new CCParticleSystemQuad(plinkConfig); _pickup.StopSystem(); AddChild(_pickup, kMiddleground); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("warp.plist", (warpConfig) => { _warp = new CCParticleSystemQuad(warpConfig); _warp.Position = _rocket.Position; AddChild(_warp, kBackground); loadedParticleSystems++; updateLoading(); }); }
public override void Update(float dt) { base.Update(dt); if (!_running) { return; } if (_lineContainer._lineType != lineTypes.LINE_NONE) { _lineContainer._tip = _rocket.Position; } //track collision with sides if (_rocket.collidedWithSides()) { _lineContainer._lineType = lineTypes.LINE_NONE; } _rocket.Update(dt); //update jet particle so it follow rocket if (!_jet.IsActive) { _jet.ResetSystem(); } _jet.RotationX = _rocket.RotationX; _jet.RotationY = _rocket.RotationY; _jet.Position = _rocket.Position; //_jet->setRotation(_rocket->getRotation()); //_jet->setPosition(_rocket->getPosition()); //update timers _cometTimer += dt; float newY; if (_cometTimer > _cometInterval) { _cometTimer = 0; if (_comet.Visible == false) { _comet.PositionX = 0; newY = CCRandom.Float_0_1() / (RAND_MAX / _screenSize.Height * 0.6f) + _screenSize.Height * 0.2f; if (newY > _screenSize.Height * 0.9f) { newY = _screenSize.Height * 0.9f; } _comet.PositionY = newY; _comet.Visible = true; _comet.ResetSystem(); } } if (_comet.Visible) { //collision with comet if ((float)Math.Pow(_comet.PositionX - _rocket.PositionX, 2) + (float)Math.Pow(_comet.PositionY - _rocket.PositionY, 2) <= (float)Math.Pow(_rocket._radius, 2)) { if (_rocket.Visible) { killPlayer(); } } _comet.PositionX = _comet.PositionX + 50 * dt; if (_comet.PositionX > _screenSize.Width * 1.5f) { _comet.StopSystem(); _comet.Visible = false; } } _lineContainer.Update(dt); _rocket.Opacity = (byte)(_lineContainer._energy * 255); //collision with planets int count = _planets.Count; GameSprite planet; for (int i = 0; i < count; i++) { planet = _planets[i]; if ((float)Math.Pow(planet.PositionX - _rocket.PositionX, 2) + (float)Math.Pow(planet.PositionY - _rocket.PositionY, 2) <= (float)Math.Pow(_rocket._radius * 0.8f + planet._radius * 0.65f, 2)) { if (_rocket.Visible) { killPlayer(); } break; } } //collision with star if ((float)Math.Pow(_star.PositionX - _rocket.PositionX, 2) + (float)Math.Pow(_star.PositionY - _rocket.PositionY, 2) <= (float)Math.Pow(_rocket._radius * 1.2f, 2)) { _pickup.Position = _star.Position; _pickup.ResetSystem(); if (_lineContainer._energy + 0.25f < 1) { _lineContainer._energy = _lineContainer._energy + 0.25f; } else { _lineContainer._energy = 1.0f; } _rocket._speed = _rocket._speed + 2; _lineContainer.setEnergyDecrement(0.001f); CCSimpleAudioEngine.SharedEngine.PlayEffect("pickup"); resetStar(); int points = 100 - (int)_timeBetweenPickups; if (points < 0) { points = 0; } _score += points; _scoreDisplay.Text = String.Format("{0}", _score); _timeBetweenPickups = 0; } _timeBetweenPickups += dt; if (_lineContainer._energy == 0) { if (_rocket.Visible) { killPlayer(); } } }