private void resetStar() { CCPoint position = _grid[_gridIndex]; _gridIndex++; if (_gridIndex == _grid.Count()) { _gridIndex = 0; } _star.Position = position; _star.Visible = true; _star.ResetSystem(); // ->resetSystem(); }
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 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(); } } }