private void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); return; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Set the sharing mode of the graphics device to turn on XNA rendering SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice); // TODO: use this.content to load your game content here playerTexture = contentManager.Load <Texture2D>("player"); laserTexture = contentManager.Load <Texture2D>("laser"); starTexture = contentManager.Load <Texture2D>("star"); font = contentManager.Load <SpriteFont>("font"); explosion = contentManager.Load <Texture2D>("explosion0"); gameOverTexture = contentManager.Load <Texture2D>("gameover"); //background = new FlowingBackground(this.contentManager.Load<Texture2D>("sky1"), 0.15f, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height); centerX = SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width / 2; playerYposition = SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height - 50; centerPosition = new Vector2(centerX, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height / 2); player = new Player(playerTexture, centerX, playerYposition, explosion); enemyHelper = new EnemyHelper(explosion); endGameScore = new EndGameScore(new Vector2(centerPosition.X, 380), font, gameOverTexture); if (e.NavigationMode == NavigationMode.Back) { elementRenderer = new UIElementRenderer(this, 800, 480); isGameOver = (bool)PhoneApplicationService.Current.State["isGameOver"]; if (particleSystem == null) { particleSystem = (Application.Current as App).BackgroundParticleSystem; LinkedList <Particle> particles = (LinkedList <Particle>)PhoneApplicationService.Current.State["particles"]; foreach (var item in particles) { item.Parent = particleSystem.EmitterList.FirstOrDefault(); } var emitter = particleSystem.EmitterList.FirstOrDefault(); if (emitter != null) { emitter.ActiveParticles = particles; } } if (enemies == null || PhoneApplicationService.Current.State.ContainsKey("enemies")) { enemies = (List <Enemy>)PhoneApplicationService.Current.State["enemies"]; enemies = (from en in enemies select new Enemy(font, en, explosion)).ToList(); } //if (bullets == null || PhoneApplicationService.Current.State.ContainsKey("bullets")) //{ // bullets = (List<LaserBullet>)PhoneApplicationService.Current.State["bullets"]; //} if (PhoneApplicationService.Current.State.ContainsKey("score")) { score = (int)PhoneApplicationService.Current.State["score"]; } if (PhoneApplicationService.Current.State.ContainsKey("wave")) { wave = (int)PhoneApplicationService.Current.State["wave"]; } } else { isGameOver = false; particleSystem = (Application.Current as App).BackgroundParticleSystem; } // Start the timer timer.Start(); base.OnNavigatedTo(e); }