public override void Initialize() { base.Initialize(); clue = new Sprite(@"Clues\clue_exit"); clue.Center = true; body = new Body(Manager.PhysicEngine, new Rectangle(0, 0, 32, 32), 0); body.Trigger = true; body.Tag = "Exit"; body.OnCollision += this.OnCollisionExitZone; body.Enabled = false; Manager.PhysicEngine.Bodies.Add(body); glitch = new GlitchColor(); Manager.Scene.AddEntity(glitch); glitch.Manual = true; timer = new Timer(); this.ZOrder = 50; // Por encima de la niebla. }
public override void Initialize() { base.Initialize(); Session.Settings = new GameDefinitions.GameSettings(); scaleAnimationFinish = false; start = false; MusicPlayer.Play(MusicPlayer.MenuTheme); Manager.Graphics.EndShader(); // Cargamos la lista de cadenas de texto del juego: Session.Strings = Serializers.DeserializeFromTitleStorage <SerializableDictionary <string, string> >("GameData/Strings/" + Session.Culture + ".xml").ToDictionary(); Manager.Graphics.OffSet = Vector2.Zero; Manager.Graphics.LoadTexture("theGrid"); background = new Bitmap("theGrid"); background.Size = new Vector2(1280, 720); Manager.Graphics.LoadTexture("backgroundFog"); fog = new Bitmap("backgroundFog"); fog.Size = new Vector2(1280, 720); layer1 = new Sprite(Manager.Graphics.LoadTexture(@"GameUI\Gametitle\backgroundLayer1")); layer1.Scale = -0.4f; layer2 = new Sprite(Manager.Graphics.LoadTexture(@"GameUI\Gametitle\backgroundLayer1")); layer2.Location = new Vector2(1280, 0); layer2.Visible = false; Manager.Graphics.LoadTexture(@"GameUI\Gametitle\wall"); wall = new Bitmap(@"GameUI\Gametitle\wall"); fan = new Sprite(Manager.Graphics.LoadTexture(@"GameUI\Gametitle\fan")); fan.Location = new Vector2(-25, -100); fan.Animations.AddSecuence("default", new Rectangle(0, 0, 400, 400), 4, 64, true); fan.Animations.Play("default"); fan.Update(new GameTime()); lightLamp = new Sprite(Manager.Graphics.LoadTexture(@"GameUI\Gametitle\lightLamp")); lightLamp.Location = new Vector2(-24, 400); Manager.Graphics.LoadTexture(@"GameUI\Gametitle\joss"); joss = new Sprite(@"GameUI\Gametitle\joss"); joss.Scale = 4; Manager.Graphics.LoadTexture(@"GameUI\Gametitle\shine"); shine = new Bitmap(@"GameUI\Gametitle\shine"); logo = new Sprite(Manager.Graphics.LoadTexture(@"GameUI\Gametitle\logo")); logo.Location = new Vector2(800, 256); logo.Scale = 4; logo.Center = true; Manager.Graphics.LoadFont(@"Fonts\androidNation14"); footstep = new TextLabel(@"Fonts\androidNation14"); footstep.Location = new Vector2(Manager.Graphics.ScreenSafeArea.Center.X, Manager.Graphics.ScreenSafeArea.Bottom - 14); footstep.Text = Session.Strings["copyright"]; footstep.Visible = false; footstep.Center = true; footstepShadow = new TextLabel(@"Fonts\androidNation14"); footstepShadow.Location = new Vector2(Manager.Graphics.ScreenSafeArea.Center.X + 2, Manager.Graphics.ScreenSafeArea.Bottom - 14 + 2); footstepShadow.Text = Session.Strings["copyright"]; footstepShadow.Color = Color.Black; footstepShadow.Visible = false; footstepShadow.Center = true; Manager.Graphics.LoadFont(@"Fonts\androidNation20b"); pressStart = new TextLabel(@"Fonts\androidNation20b"); pressStart.Location = new Vector2(Manager.Graphics.ScreenSafeArea.Center.X, Manager.Graphics.ScreenSafeArea.Center.Y + 150); pressStart.Text = Session.Strings["pressStart"]; pressStart.Visible = false; pressStart.Center = true; pressStartShadow = new TextLabel(@"Fonts\androidNation20b"); pressStartShadow.Location = new Vector2(Manager.Graphics.ScreenSafeArea.Center.X + 2, Manager.Graphics.ScreenSafeArea.Center.Y + 150 + 2); pressStartShadow.Text = Session.Strings["pressStart"]; pressStartShadow.Color = Color.Black; pressStartShadow.Visible = false; pressStartShadow.Center = true; timer = new Timer(); timer2 = new Timer(); glitch = new GlitchColor(); Manager.Scene.AddEntity(glitch); }
// Carga el nivel indicado en la variable "currentLevel": private void LoadLevel() {// Comprobamos si hemos llegado al final del juego en modo trial: if (Guide.IsTrialMode && (int)Manager.Vars["currentLevel"] > 7) { Manager.Vars["purchaseAndReturnMenu"] = true; Manager.GameStates.ChangeState("endtrial"); } // Comprobamos si hemos llegado al final del juego en modo completo: else if (!Guide.IsTrialMode && (int)Manager.Vars["currentLevel"] > 32) { Manager.GameStates.ChangeState("gameover"); } // Cargamos el nivel: else { // Descargamaos previamente el nivel actual: UnloadLevel(); // Area del escenario para definir los elementos: Rectangle boxArea = new Rectangle(0, 0, 1024, 576); // Marco del escenario para delimitar el area de accion del jugador: { Manager.PhysicEngine.Bodies.Add(new Body(Manager.PhysicEngine, new Rectangle(boxArea.X, boxArea.Y - 64, boxArea.Width, 64), 1, true)); Manager.PhysicEngine.Bodies.Add(new Body(Manager.PhysicEngine, new Rectangle(boxArea.X - 64, 0, 64, boxArea.Height), 1, true)); Manager.PhysicEngine.Bodies.Add(new Body(Manager.PhysicEngine, new Rectangle(boxArea.Width, 0, 64, boxArea.Height), 1, true)); } // Area de muerte: la zona inferior de la escena matara al jugador si hay colision: { Body deathTrigger = new Body(Manager.PhysicEngine, new Rectangle(boxArea.X, boxArea.Height, boxArea.Width, 64), 0); deathTrigger.Tag = "deathZone"; deathTrigger.Trigger = true; deathTrigger.OnCollision += this.OnCollisionDeathZone; Manager.PhysicEngine.Bodies.Add(deathTrigger); } // Cargamos los objetos de la escena: try { GameDefinitions.LevelData level = Serializers.DeserializeFromTitleStorage <GameDefinitions.LevelData>("GameData/Levels/" + (Guide.IsTrialMode ? "Trial/" : "") + Manager.Vars["currentLevel"].ToString() + ".xml"); { // Agregamos las pistas: Clue clue; foreach (GameDefinitions.Clue c in level.Clues) { if (c.Texture != "clue_exit" && !c.Texture.StartsWith("level_")) { clue = new Clue(); Manager.Scene.AddEntity(clue); clue.Texture = c.Texture; clue.Location = c.Location; clue.Update(Manager.GameTime); } } // Agregamos los tiles: Tile tile; foreach (GameDefinitions.Tile t in level.Tiles) { tile = new Tile(); Manager.Scene.AddEntity(tile); tile.Texture = t.Texture; tile.Location = t.Location; tile.Tag = t.Tag; tile.Visible = t.Active; tile.Update(Manager.GameTime); } // Agregamos una entidad TileGroupQuery para el power-up de mostrar el camino completo: TileGroupQuery tileGroupQuery = new TileGroupQuery(); Manager.Scene.AddEntity(tileGroupQuery, "tileGroupQuery"); // Agregamos los enemigos: Enemy enemy; foreach (GameDefinitions.Enemy e in level.Enemies) { enemy = new Enemy(); Manager.Scene.AddEntity(enemy); enemy.Location = e.Location; enemy.Invincible = e.Invincible; enemy.Target = e.Target; enemy.Action = e.Action; // Si el target no esta vacio lo agregamos a la entidad TileGroupQuery: if (enemy.Target != "" && (enemy.Action == 0 || enemy.Action == 1) && tileGroupQuery.Query.Keys.Contains <string>(enemy.Target)) { tileGroupQuery.Query.Add(enemy.Target, enemy.Action == 0 ? false : true); } enemy.PathLength = e.PathLength; enemy.Step = e.Step; enemy.Behavior = e.Behavior; enemy.Type = e.Type; enemy.Respawn = e.Respawn; enemy.RespawnDelay = e.RespawnDelay; enemy.ReversePathAtStart = e.ReversePathAtStart; enemy.Update(Manager.GameTime); // Solo se cuentan las particulas que son sean items o especiales (0 - 2): if (e.Action < 3) { Manager.Vars["enemiesLeft"] = (int)Manager.Vars["enemiesLeft"] + 1; } } // Agregamos al jugador: Player player = new Player(); Manager.Scene.AddEntity(player, "player"); player.Location = level.Player.Location; player.Update(Manager.GameTime); // Agregamos la zona de salida del nivel: ExitArea exit = new ExitArea(); Manager.Scene.AddEntity(exit); exit.Location = level.ExitArea.Location; exit.InvertClue = level.ExitArea.InvertClue; } // Reiniciamos los contadores: Manager.Vars["shoots"] = 0; Manager.Vars["currentLevelScore"] = 0; } catch (Exception ex) { Manager.Vars["errorBoard"] = "*** Error al cargar el nivel #" + (int)Manager.Vars["currentLevel"] + ": \n" + ex.Message + "***"; Manager.GameStates.ChangeState("menu"); return; } Manager.Vars["errorBoard"] = ""; // Agregamos el componente del HUD: Manager.Scene.AddEntity(new Entities.GUI.HUD(), "HUD"); // Agregamos el componente de la ventana que hace marco de la escena: Manager.Scene.AddEntity(new Entities.GUI.MainWindowFrame()); // Cargamos el fondo de escena: Manager.Scene.AddEntity(new Background()); // Cargamos el efecto de escalineado de la pantalla: Manager.Scene.AddEntity(new ScanLines()); // En caso contrario se manda el mensaje para que inicien su actividad todos los componentes del juego: Manager.Messages.SendMessage("", "ready"); Manager.Vars["showMessageReady"] = false; Manager.Vars["showMessagePause"] = false; // Si el nivel ya se completo, se muestra en color: if ((int)Manager.Vars["currentLevel"] < Session.GameProgress.CurrentLevel) { Manager.Graphics.EndShader(); } else { Manager.Graphics.BeginShader(); } // Cargamos el efecto de glitch para el efecto color/bn al matar las particulas: GlitchColor glitch = new GlitchColor(); Manager.Scene.AddEntity(glitch, "glitch"); glitch.Manual = true; // Vigilamos que el usuario no cierra sesion. En caso de hacerlo mostramos aviso y lo mandamos a la pantalla de titulo: Manager.Scene.AddEntity(new PlayerSignedOut()); } }