/// <summary> /// Check victory in the game. /// </summary> /// <returns></returns> public bool IsMissionClear() { switch (levelInfo.VictoryConditionType) { case VictoryConditionTypeId.DestroyAllEnemies: { // Destroyed all enemies ? for (int i = 0; i < enemyList.Count; i++) { GameEnemy enemy = enemyList[i]; if (!enemy.IsDead) { return(false); } } // Enemies are down!! return(true); } case VictoryConditionTypeId.DestroyOnlyBoss: { for (int i = 0; i < enemyList.Count; i++) { if (enemyList[i] is EnemyBoss) { // Boss is down! if (enemyList[i].IsDead) { return(true); } } } } break; } return(false); }
/// <summary> /// load all of the data for stage level, player, enemies, items, weapons, etc. /// </summary> /// <returns></returns> public void LoadLevel(string levelFile) { this.levelInfo = (GameLevelInfo)HelperFile.LoadData(levelFile, levelInfo.GetType()); RobotGameGame.CurrentGameLevel = this; // Initialize level Initialize(); // Global fog if (levelInfo.FogEnable) { FrameworkCore.Viewer.BasicFog = new RenderFog(); FrameworkCore.Viewer.BasicFog.enabled = true; FrameworkCore.Viewer.BasicFog.start = levelInfo.FogStart; FrameworkCore.Viewer.BasicFog.end = levelInfo.FogEnd; FrameworkCore.Viewer.BasicFog.color = new Color( (byte)levelInfo.FogColor.X, (byte)levelInfo.FogColor.Y, (byte)levelInfo.FogColor.Z); } else { FrameworkCore.Viewer.BasicFog = new RenderFog(); FrameworkCore.Viewer.BasicFog.enabled = false; } // Global lighting if (levelInfo.LightingEnable) { FrameworkCore.Viewer.BasicLighting = new RenderLighting(); FrameworkCore.Viewer.BasicLighting.enabled = true; FrameworkCore.Viewer.BasicLighting.ambientColor = new Color( (byte)levelInfo.LightingAmbientColor.X, (byte)levelInfo.LightingAmbientColor.Y, (byte)levelInfo.LightingAmbientColor.Z); FrameworkCore.Viewer.BasicLighting.diffuseColor = new Color( (byte)levelInfo.LightingDiffuseColor.X, (byte)levelInfo.LightingDiffuseColor.Y, (byte)levelInfo.LightingDiffuseColor.Z); FrameworkCore.Viewer.BasicLighting.specularColor = new Color( (byte)levelInfo.LightingSpecularColor.X, (byte)levelInfo.LightingSpecularColor.Y, (byte)levelInfo.LightingSpecularColor.Z); FrameworkCore.Viewer.BasicLighting.direction = levelInfo.LightingDirection; } else { FrameworkCore.Viewer.BasicLighting = new RenderLighting(); FrameworkCore.Viewer.BasicLighting.enabled = false; } // Create world if (this.levelInfo.WorldInLevel != null) { CreateWorld(ref this.levelInfo.WorldInLevel); } // Create particles CreateParticle(this.levelInfo.ParticleListFile); // Create player if (this.levelInfo.PlayerInLevel != null) { GamePlayer player = CreatePlayer(ref this.levelInfo.PlayerInLevel, this.SceneMechRoot); RobotGameGame.SinglePlayer = player; FrameworkCore.GameEventManager.TargetScene = player; } // Create all enemies in the level if (levelInfo.EnemyInLevelList != null) { for (int i = 0; i < levelInfo.EnemyInLevelList.Count; i++) { EnemyInLevel enemy = levelInfo.EnemyInLevelList[i]; CreateSpawnEnemy(ref enemy, this.SceneMechRoot); } } // Create all items in the level if (levelInfo.ItemInLevelList != null) { for (int i = 0; i < levelInfo.ItemInLevelList.Count; i++) { ItemInLevel item = levelInfo.ItemInLevelList[i]; CreateItemBox(ref item, this.SceneWorldRoot); } } // Create all weapons in the level if (levelInfo.WeaponInLevelList != null) { for (int i = 0; i < levelInfo.WeaponInLevelList.Count; i++) { CreateWeapon(levelInfo.WeaponInLevelList[i], SceneWorldRoot); } } // Entry collision of the units to layer in the level switch (Info.GamePlayType) { case GamePlayTypeId.StageClear: { GamePlayer player = SinglePlayer; // Entry collision of the player to layer in the level CollisionLayerFriendlyMech.AddCollide(player.Collide); CollisionLayerAllMech.AddCollide(player.Collide); // Entry collsion of each enemy to layer in the level for (int i = 0; i < EnemyCountInLevel; i++) { GameEnemy enemy = GetEnemyInLevel(i); CollisionLayerEnemyMech.AddCollide(enemy.Collide); CollisionLayerAllMech.AddCollide(enemy.Collide); } } break; case GamePlayTypeId.Versus: { } break; } // Entry collsion of items to layer in the level for (int i = 0; i < ItemCountInLevel; i++) { GameItemBox item = GetItemInLevel(i); CollisionLayerItems.AddCollide(item.Collide); } // Entry collsion of weapons to layer in the level for (int i = 0; i < WeaponCountInLevel; i++) { GameWeapon weapon = GetWeaponInLevel(i); CollisionLayerItems.AddCollide(weapon.Collide); } }
/// <summary> /// creates an enemy for level. /// reads an enemy information file(.spec) and configures the enemy class. /// The read enemy class is stored in the list. /// </summary> /// <param name="info">enemy information for level</param> /// <param name="sceneParent">3D scene parent node</param> protected void CreateSpawnEnemy(ref EnemyInLevel info, NodeBase sceneParent) { GameEnemy enemy = null; GameEnemySpec spec = LoadEnemySpec(ref info); // creates an enemy by unit type switch (spec.UnitClass) { case UnitClassId.Tank: enemy = new EnemyTank(ref spec); break; case UnitClassId.LightMech: case UnitClassId.HeavyMech: enemy = new EnemyMech(ref spec); break; case UnitClassId.Boss: enemy = new EnemyBoss(ref spec); break; default: throw new NotSupportedException( "Not supported unit type : " + spec.UnitType); } // sets the material RenderMaterial material = new RenderMaterial(); material.alpha = 1.0f; material.diffuseColor = new Color((byte)info.MaterialDiffuseColor.X, (byte)info.MaterialDiffuseColor.Y, (byte)info.MaterialDiffuseColor.Z); material.specularColor = new Color((byte)info.MaterialSpecularColor.X, (byte)info.MaterialSpecularColor.Y, (byte)info.MaterialSpecularColor.Z); material.emissiveColor = new Color((byte)info.MaterialEmissiveColor.X, (byte)info.MaterialEmissiveColor.Y, (byte)info.MaterialEmissiveColor.Z); material.specularPower = info.MaterialSpecularPower; material.vertexColorEnabled = false; material.preferPerPixelLighting = false; enemy.Material = material; enemy.ActiveFog = true; enemy.ActiveLighting = true; // adds this to the list. enemyList.Add(enemy); // entries this in parent scene node. sceneParent.AddChild(enemy); // sets to rotate axis. if (spec.UnitType == UnitTypeId.Tiger) { enemy.SetRootAxis( Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)) * Matrix.CreateRotationZ(MathHelper.ToRadians(90.0f))); } else { enemy.SetRootAxis(Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } // sets to stage spawn position. enemy.SpawnPoint = Matrix.CreateRotationY(MathHelper.ToRadians(info.SpawnAngle)) * Matrix.CreateTranslation(info.SpawnPoint); // activate draw culling. enemy.EnableCulling = true; // creates a collision data. { Vector3 centerPos = Vector3.Transform( new Vector3(0.0f, spec.MechRadius, 0.0f), Matrix.Invert(enemy.RootAxis)); CollideSphere collide = new CollideSphere(centerPos, spec.MechRadius); enemy.SetCollide(collide); } // creates a game event. switch (info.SpawnType) { case SpawnTypeId.Time: { FrameworkCore.GameEventManager.AddEvent( new GameTimeEvent(info.SpawnTime, enemy, false)); } break; case SpawnTypeId.Area: { FrameworkCore.GameEventManager.AddEvent( new GameAreaEvent(info.SpawnPoint, info.SpawnRadius, enemy, false)); } break; } // sets start A.I. enemy.SetStartAI(info.StartAi, info.StartAiTime); }