示例#1
0
        //

        protected override void OnAttach()
        {
            base.OnAttach();

            //World serialization. Need to add the support of load/save feature in Game.exe.
            {
                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);

            //World serialization. Need to add the support of load/save feature in Game.exe.
            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.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;
        }
示例#2
0
        void Map_Tick(Entity entity)
        {
            //Game tick
            if (gameTime != 0)
            {
                gameTime += Entity.TickDelta;

                //Pre start
                if (gameTime >= 2 && gameTime < 2 + Entity.TickDelta * 1.5)
                {
                    GameEngineApp.Instance.ControlManager.PlaySound("Sounds/Feedback/Three.ogg");
                }
                if (gameTime >= 4 && gameTime < 4 + Entity.TickDelta * 1.5)
                {
                    GameEngineApp.Instance.ControlManager.PlaySound("Sounds/Feedback/Two.ogg");
                }
                if (gameTime >= 6 && gameTime < 6 + Entity.TickDelta * 1.5)
                {
                    GameEngineApp.Instance.ControlManager.PlaySound("Sounds/Feedback/One.ogg");
                }
                if (gameTime >= 8 && gameTime < 8 + Entity.TickDelta * 1.5)
                {
                    GameEngineApp.Instance.ControlManager.PlaySound("Sounds/Feedback/Fight.ogg");
                }

                if (gameTime >= 8)
                {
                    GameMusic.MusicPlay("Sounds/Music/Action.ogg", true);
                }

                //Create enemies
                if (gameTime > 10 && remainingCreateCount != 0)
                {
                    remainingTimeForCreateEnemy -= Entity.TickDelta;

                    if (remainingTimeForCreateEnemy <= 0)
                    {
                        remainingTimeForCreateEnemy = createInterval;
                        if (CreateEnemy())
                        {
                            remainingCreateCount--;
                        }
                    }
                }
            }

            //Update billboard text
            {
                string mainText = "";
                string downText = "";

                if (gameTime < 8)
                {
                    if (gameTime == 0)
                    {
                        if (level <= 4)
                        {
                            mainText = string.Format("Level {0}", level);
                            downText = "Fire here to start";
                        }
                        else
                        {
                            mainText = "Victory";
                            downText = "Congratulations :)";
                        }
                    }
                    else
                    {
                        mainText = "Prepare";
                        downText = "for battle";
                    }
                }
                else
                {
                    mainText = remainingCount.ToString();
                    downText = string.Format("Level {0}", level);
                }

                GameGuiObject billboard = (GameGuiObject)Entities.Instance.GetByName("HangingBillboard_Game");
                billboard.MainControl.Controls["MainText"].Text = mainText;
                billboard.MainControl.Controls["DownText"].Text = downText;
            }

            //Recreate Turret
            if (Entities.Instance.GetByName("Turret_Game") == null && gameTime == 0)
            {
                Turret turret = (Turret)Entities.Instance.Create("Turret", Map.Instance);
                turret.Name     = "Turret_Game";
                turret.Position = turretCreatePosition;
                turret.Rotation = turretCreateRotation;
                turret.PostCreate();
            }
        }