// protected override void OnAttach() { base.OnAttach(); //World serialized data { if (World.Instance.GetCustomSerializationValue("remainingTimeForCreateEnemy") != null) { remainingTimeForCreateEnemy = (float)World.Instance.GetCustomSerializationValue( "remainingTimeForCreateEnemy"); } if (World.Instance.GetCustomSerializationValue("gameTime") != null) { gameTime = (float)World.Instance.GetCustomSerializationValue("gameTime"); } if (World.Instance.GetCustomSerializationValue("level") != null) { level = (int)World.Instance.GetCustomSerializationValue("level"); } if (World.Instance.GetCustomSerializationValue("remainingCount") != null) { remainingCount = (int)World.Instance.GetCustomSerializationValue("remainingCount"); } if (World.Instance.GetCustomSerializationValue("remainingCreateCount") != null) { remainingCreateCount = (int)World.Instance.GetCustomSerializationValue( "remainingCreateCount"); } if (World.Instance.GetCustomSerializationValue("createInterval") != null) { createInterval = (float)World.Instance.GetCustomSerializationValue( "createInterval"); } } GameGuiObject billboard = Entities.Instance.GetByName("HangingBillboard_Game") as GameGuiObject; billboard.Damage += GameBillboard_Damage; //find enemy spawn points foreach (Entity entity in Map.Instance.Children) { MapObject point = entity as MapObject; if (!string.IsNullOrEmpty(entity.GetTag("TextUserData"))) { if (point != null && point.Type.Name == "HelperPoint") { enemySpawnPoints.Add(point); } } } screenFont = FontManager.Instance.LoadFont("Default", .05f); if (level == 0) //for world serialization { level = 1; } //get turret start position Turret turret = (Turret)Entities.Instance.GetByName("Turret_Game"); if (turret != null) { turretCreatePosition = turret.Position; turretCreateRotation = turret.Rotation; } UpdateVictoryObjects(false); //for world serialization foreach (Entity entity in Map.Instance.Children) { if (entity.IsSetForDeletion) { continue; } Unit unit = entity as Unit; if (unit == null) { continue; } if (unit is PlayerCharacter) { continue; } if ((unit.Intellect as AI) != null || unit is Aircraft) { unit.ViewRadius = 300; unit.Destroying += EnemyUnitDestroying; unit.Tick += EnemyUnitTick; } } //for world serialization if (gameTime != 0) { MainPlayerUnitSubscribeToDestroying(); } //for world serialization if (gameTime >= 8) { GameMusic.MusicPlay("Sounds/Music/Action.ogg", true); } Map.Instance.Tick += Map_Tick; }
protected override void OnRender() { base.OnRender(); Camera camera = RendererWorld.Instance.DefaultCamera; GetNavigationSystem().DebugDrawNavMesh(camera); //path test { Vec3 offset = new Vec3(0, 0, .2f); if (pathTest) { camera.DebugGeometry.Color = new ColorValue(0, 0, 1); AddArrow(camera, startPosition + new Vec3(0, 0, 4), startPosition + offset, .07f, 1.2f); List <string> lines = new List <string>(); if (time < 0.001f) { lines.Add(string.Format("Time: <0.001 seconds")); } else { lines.Add(string.Format("Time: {0} seconds", time.ToString("F3"))); } //SodanKerjuu: we check if the path will lead us close enough to where we wanted bool futile = false; if (found) { if ((path[path.Length - 1] - endPosition).Length() > 1f) { futile = true; lines.Add("Path found, but didn't reach close enough to end point."); } else { lines.Add("Path found"); } } else { lines.Add("Path not found"); } //write out information if (found) { lines.Add(string.Format("Points: {0}", path.Length)); camera.DebugGeometry.Color = new ColorValue(0, 1, 0); for (int n = 1; n < path.Length; n++) { Vec3 from = path[n - 1] + offset; Vec3 to = path[n] + offset; AddThicknessLine(camera, from, to, .07f); camera.DebugGeometry.AddLine(from, to); } camera.DebugGeometry.Color = futile ? new ColorValue(1, 0, 0) : new ColorValue(1, 1, 0); foreach (Vec3 point in path) { AddSphere(camera, new Sphere(point + offset, .15f)); } } //show end position and arrow between start and end if (GetPositionByCursor(out endPosition)) { camera.DebugGeometry.Color = new ColorValue(1, 0, 0); AddArrow(camera, endPosition + new Vec3(0, 0, 4), endPosition + offset, .07f, 1.2f); } EngineApp.Instance.ScreenGuiRenderer.AddTextLines(lines, new Vec2(.05f, .075f), HorizontalAlign.Left, VerticalAlign.Top, 0, new ColorValue(1, 1, 1)); } else { //show end position and arrow between start and end Vec3 pos; if (GetPositionByCursor(out pos)) { camera.DebugGeometry.Color = new ColorValue(1, 0, 0); AddArrow(camera, pos + new Vec3(0, 0, 4), pos + offset, .07f, 1.2f); } } } //highlight cursor on object { MapObject mapObject = GetMapObjectByCursor(); if (mapObject != null) { camera.DebugGeometry.Color = new ColorValue(1, 1, 0); Box box = mapObject.GetBox(); box.Expand(.1f); camera.DebugGeometry.AddBox(box); } } //draw paths of units foreach (Entity entity in Map.Instance.Children) { Character character = entity as Character; if (character != null) { GameCharacterAI ai = character.Intellect as GameCharacterAI; if (ai != null) { ai.DebugDrawTasks(camera); ai.DebugDrawPath(camera); } } } UpdateHUD(); }