Example #1
0
        void GameStop(bool complete)
        {
            if (gameTime == 0)
            {
                return;
            }

            gameTime = 0;

            if (complete)
            {
                GameEngineApp.Instance.ControlManager.PlaySound("Sounds/Feedback/Complete.ogg");
                level++;
            }

            //Destroy all alive enemies
            ttt :;
            foreach (Entity entity in Map.Instance.Children)
            {
                if (entity.IsSetForDeletion)
                {
                    continue;
                }

                Unit unit = entity as Unit;
                if (unit == null)
                {
                    continue;
                }

                if ((unit.Intellect as AI) != null)
                {
                    unit.Die();
                    goto ttt;
                }
            }

            //restore default music
            if (GameMap.Instance != null)
            {
                GameMusic.MusicPlay(GameMap.Instance.GameMusic, true);
            }

            if (complete && level > 4)
            {
                UpdateVictoryObjects(true);
            }
        }
Example #2
0
        void Client_EntitySystemService_WorldCreateEnd(EntitySystemClientNetworkService sender)
        {
            //dynamic created map example
            if (string.IsNullOrEmpty(Map.Instance.VirtualFileName))
            {
                DynamicCreatedMapExample.Client_CreateEntities();
            }

            //play music
            if (GameMap.Instance != null)
            {
                GameMusic.MusicPlay(GameMap.Instance.GameMusic, true);
            }

            CreateGameWindowForMap();
        }
Example #3
0
        ///////////////////////////////////////////

        /// <summary>
        /// Creates a window of the main menu and creates the background world.
        /// </summary>
        protected override void OnAttach()
        {
            base.OnAttach();

            //create main menu window
            window = ControlDeclarationManager.Instance.CreateControl("Gui\\MainMenuWindow.gui");

            window.ColorMultiplier = new ColorValue(1, 1, 1, 0);
            Controls.Add(window);

            //no shader model 3 warning
            if (window.Controls["NoShaderModel3"] != null)
            {
                window.Controls["NoShaderModel3"].Visible = !RenderSystem.Instance.HasShaderModel3();
            }

            //button handlers
            ((EButton)window.Controls["Run"]).Click         += Run_Click;
            ((EButton)window.Controls["Multiplayer"]).Click += Multiplayer_Click;
            ((EButton)window.Controls["GuiTest"]).Click     += GuiTest_Click;

            //add version info control
            versionTextBox = new ETextBox();
            versionTextBox.TextHorizontalAlign = HorizontalAlign.Left;
            versionTextBox.TextVerticalAlign   = VerticalAlign.Bottom;
            versionTextBox.Text            = "Version " + EngineVersionInformation.Version;
            versionTextBox.ColorMultiplier = new ColorValue(1, 1, 1, 0);

            Controls.Add(versionTextBox);

            //play background music
            GameMusic.MusicPlay("Sounds\\Music\\MainMenu.ogg", true);

            //update sound listener
            SoundWorld.Instance.SetListener(new Vec3(1000, 1000, 1000),
                                            Vec3.Zero, new Vec3(1, 0, 0), new Vec3(0, 0, 1));

            //create the background world
            CreateMap();

            ResetTime();
        }
        /// <summary>
        /// Creates a window of the main menu and creates the background world.
        /// </summary>
        protected override void OnAttach()
        {
            instance = this;
            base.OnAttach();

            //for showBackgroundMap field.
            EngineApp.Instance.Config.RegisterClassParameters(GetType());

            //create main menu window
            window = ControlDeclarationManager.Instance.CreateControl("Gui\\MainMenuWindow.gui");

            window.ColorMultiplier = new ColorValue(1, 1, 1, 0);
            Controls.Add(window);

            //no shader model 3 warning
            if (window.Controls["NoShaderModel3"] != null)
            {
                window.Controls["NoShaderModel3"].Visible = !RenderSystem.Instance.HasShaderModel3();
            }

            //button handlers
            //if( window.Controls[ "Run" ] != null )
            //   ( (Button)window.Controls[ "Run" ] ).Click += Run_Click;
            if (window.Controls["Multiplayer"] != null)
            {
                ((Button)window.Controls["Multiplayer"]).Click += Multiplayer_Click;
            }
            if (window.Controls["Maps"] != null)
            {
                ((Button)window.Controls["Maps"]).Click += Maps_Click;
            }
            if (window.Controls["Maps2"] != null)
            {
                ((Button)window.Controls["Maps2"]).Click += Maps_Click;
            }
            if (window.Controls["LoadSave"] != null)
            {
                ((Button)window.Controls["LoadSave"]).Click += LoadSave_Click;
            }
            if (window.Controls["Options"] != null)
            {
                ((Button)window.Controls["Options"]).Click += Options_Click;
            }
            if (window.Controls["MultiView"] != null)
            {
                ((Button)window.Controls["MultiView"]).Click += MultiView_Click;
            }
            if (window.Controls["ProfilingTool"] != null)
            {
                ((Button)window.Controls["ProfilingTool"]).Click += ProfilingTool_Click;
            }
            if (window.Controls["GUISamples1"] != null)
            {
                ((Button)window.Controls["GUISamples1"]).Click += GUISamples1_Click;
            }
            if (window.Controls["GUISamples2"] != null)
            {
                ((Button)window.Controls["GUISamples2"]).Click += GUISamples2_Click;
            }
            if (window.Controls["GUISamples3"] != null)
            {
                ((Button)window.Controls["GUISamples3"]).Click += GUISamples3_Click;
            }
            if (window.Controls["About"] != null)
            {
                ((Button)window.Controls["About"]).Click += About_Click;
            }
            if (window.Controls["Exit"] != null)
            {
                ((Button)window.Controls["Exit"]).Click += Exit_Click;
            }

            ////add version info control
            //versionTextBox = new TextBox();
            //versionTextBox.TextHorizontalAlign = HorizontalAlign.Left;
            //versionTextBox.TextVerticalAlign = VerticalAlign.Bottom;
            //versionTextBox.Text = "Version " + EngineVersionInformation.Version;
            //versionTextBox.ColorMultiplier = new ColorValue( 1, 1, 1, 0 );
            //Controls.Add( versionTextBox );

            //showBackgroundMap check box
            CheckBox checkBox = (CheckBox)window.Controls["ShowBackgroundMap"];

            if (checkBox != null)
            {
                checkBox.Checked = showBackgroundMap;
                checkBox.Click  += checkBoxShowBackgroundMap_Click;
            }

            //play background music
            GameMusic.MusicPlay("Sounds\\Music\\MainMenu.ogg", true);

            //update sound listener
            SoundWorld.Instance.SetListener(new Vec3(1000, 1000, 1000),
                                            Vec3.Zero, new Vec3(1, 0, 0), new Vec3(0, 0, 1));

            //create the background world
            if (showBackgroundMap)
            {
                CreateMap();
            }

            ResetTime();
        }
Example #5
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;
        }
Example #6
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();
            }
        }
Example #7
0
        public bool ServerOrSingle_MapLoad(string fileName, WorldType worldType,
                                           bool noChangeWindows)
        {
            GameNetworkServer server = GameNetworkServer.Instance;

            EControl mapLoadingWindow = null;

            //show map loading window
            if (!noChangeWindows)
            {
                mapLoadingWindow = ControlDeclarationManager.Instance.CreateControl(
                    "Gui\\MapLoadingWindow.gui");
                if (mapLoadingWindow != null)
                {
                    mapLoadingWindow.Text = fileName;
                    controlManager.Controls.Add(mapLoadingWindow);
                }
                RenderScene();
            }

            DeleteAllGameWindows();

            MapSystemWorld.MapDestroy();

            //create world if need
            if (World.Instance == null || World.Instance.Type != worldType)
            {
                WorldSimulationTypes worldSimulationType;
                EntitySystemWorld.NetworkingInterface networkingInterface = null;

                if (server != null)
                {
                    worldSimulationType = WorldSimulationTypes.ServerAndClient;
                    networkingInterface = server.EntitySystemService.NetworkingInterface;
                }
                else
                {
                    worldSimulationType = WorldSimulationTypes.Single;
                }

                if (!EntitySystemWorld.Instance.WorldCreate(worldSimulationType, worldType,
                                                            networkingInterface))
                {
                    Log.Fatal("GameEngineApp: MapLoad: EntitySystemWorld.WorldCreate failed.");
                }
            }

            //Subcribe to callbacks during map loading. We will render scene from callback.
            LongOperationCallbackManager.Subscribe(LongOperationCallbackManager_LoadingCallback,
                                                   mapLoadingWindow);

            //load map
            if (!MapSystemWorld.MapLoad(fileName))
            {
                if (mapLoadingWindow != null)
                {
                    mapLoadingWindow.SetShouldDetach();
                }

                LongOperationCallbackManager.Unsubscribe();

                return(false);
            }

            //inform clients about world created
            if (server != null)
            {
                server.EntitySystemService.InformClientsAfterWorldCreated();
            }

            //Simulate physics for 5 seconds. That the physics has fallen asleep.
            if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle())
            {
                SimulatePhysicsForLoadedMap(5);
            }

            //Update shadow settings. This operation can be slow because need update all
            //shaders if shadow technique changed.
            Map.Instance.UpdateSceneManagerShadowSettings();

            fullscreenFadingRemainingFrames = 35;

            LongOperationCallbackManager.Unsubscribe();

            //Error
            foreach (EControl control in controlManager.Controls)
            {
                if (control is MessageBoxWindow && !control.IsShouldDetach())
                {
                    return(false);
                }
            }

            if (!noChangeWindows)
            {
                CreateGameWindowForMap();
            }

            //play music
            if (!noChangeWindows)
            {
                if (GameMap.Instance != null)
                {
                    GameMusic.MusicPlay(GameMap.Instance.GameMusic, true);
                }
            }

            EntitySystemWorld.Instance.ResetExecutedTime();

            return(true);
        }
Example #8
0
        protected override bool OnCreate()
        {
            instance = this;

            ChangeToBetterDefaultSettings();

            if (!base.OnCreate())
            {
                return(false);
            }

            SoundVolume = soundVolume;
            MusicVolume = musicVolume;

            controlManager = new ScreenControlManager(ScreenGuiRenderer);
            if (!ControlsWorld.Init())
            {
                return(false);
            }

            _ShowSystemCursor = _ShowSystemCursor;
            _DrawFPS          = _DrawFPS;
            MaterialScheme    = materialScheme;

            Log.Handlers.InfoHandler    += Log_Handlers_InfoHandler;
            Log.Handlers.WarningHandler += Log_Handlers_WarningHandler;
            Log.Handlers.ErrorHandler   += Log_Handlers_ErrorHandler;
            Log.Handlers.FatalHandler   += Log_Handlers_FatalHandler;

            //Camera
            Camera camera = RendererWorld.Instance.DefaultCamera;

            camera.NearClipDistance = .1f;
            camera.FarClipDistance  = 1000.0f;
            camera.FixedUp          = Vec3.ZAxis;
            camera.Fov      = 90;
            camera.Position = new Vec3(-10, -10, 10);
            camera.LookAt(new Vec3(0, 0, 0));

            EControl programLoadingWindow = ControlDeclarationManager.Instance.CreateControl(
                "Gui\\ProgramLoadingWindow.gui");

            if (programLoadingWindow != null)
            {
                controlManager.Controls.Add(programLoadingWindow);
            }

            //Subcribe to callbacks during engine loading. We will render scene from callback.
            LongOperationCallbackManager.Subscribe(LongOperationCallbackManager_LoadingCallback,
                                                   programLoadingWindow);

            if (!HighLevelMaterialManager.Instance.LoadAllMaterials())
            {
                LongOperationCallbackManager.Unsubscribe();
                return(true);
            }

            RenderScene();

            //Game controls
            GameControlsManager.Init();

            //EntitySystem
            if (!EntitySystemWorld.Init(new EntitySystemWorld()))
            {
                LongOperationCallbackManager.Unsubscribe();
                return(true);
            }

            LongOperationCallbackManager.Unsubscribe();

            //close loading window.
            if (programLoadingWindow != null)
            {
                programLoadingWindow.SetShouldDetach();
            }

            string mapName = "";

            if (autorunMapName != "" && autorunMapName.Length > 2)
            {
                mapName = autorunMapName;
                if (!mapName.Contains("\\") && !mapName.Contains("/"))
                {
                    mapName = "Maps/" + mapName + "/Map.map";
                }
            }

            if (!WebPlayerMode)
            {
                string[] commandLineArgs = Environment.GetCommandLineArgs();
                if (commandLineArgs.Length > 1)
                {
                    string name = commandLineArgs[1];
                    if (name[0] == '\"' && name[name.Length - 1] == '\"')
                    {
                        name = name.Substring(1, name.Length - 2);
                    }
                    name = name.Replace('/', '\\');

                    string dataDirectory = VirtualFileSystem.ResourceDirectoryPath;
                    dataDirectory = dataDirectory.Replace('/', '\\');

                    if (name.Length > dataDirectory.Length)
                    {
                        if (string.Compare(name.Substring(0, dataDirectory.Length), dataDirectory, true) == 0)
                        {
                            name = name.Substring(dataDirectory.Length + 1);
                        }
                    }

                    mapName = name;
                }
            }

            if (mapName != "")
            {
                if (!ServerOrSingle_MapLoad(mapName, EntitySystemWorld.Instance.DefaultWorldType, false))
                {
                    //Error
                    foreach (EControl control in controlManager.Controls)
                    {
                        if (control is MessageBoxWindow && !control.IsShouldDetach())
                        {
                            return(true);
                        }
                    }

                    GameMusic.MusicPlay("Sounds\\Music\\MainMenu.ogg", true);
                    controlManager.Controls.Add(new EngineLogoWindow());
                }
            }
            else
            {
                GameMusic.MusicPlay("Sounds\\Music\\MainMenu.ogg", true);
                controlManager.Controls.Add(new EngineLogoWindow());
            }

            //showDebugInformation console command
            if (EngineConsole.Instance != null)
            {
                EngineConsole.Instance.AddCommand("showDebugInformationWindow",
                                                  ConsoleCommand_ShowDebugInformationWindow);
            }

            //example of custom input device
            //ExampleCustomInputDevice.InitDevice();

            return(true);
        }
Example #9
0
        public bool WorldLoad(string fileName)
        {
            EControl worldLoadingWindow = null;

            //world loading window
            {
                worldLoadingWindow = ControlDeclarationManager.Instance.CreateControl(
                    "Gui\\WorldLoadingWindow.gui");
                if (worldLoadingWindow != null)
                {
                    worldLoadingWindow.Text = fileName;
                    controlManager.Controls.Add(worldLoadingWindow);
                }
                RenderScene();
            }

            DeleteAllGameWindows();

            //Subcribe to callbacks during engine loading. We will render scene from callback.
            LongOperationCallbackManager.Subscribe(LongOperationCallbackManager_LoadingCallback,
                                                   worldLoadingWindow);

            if (!MapSystemWorld.WorldLoad(WorldSimulationTypes.Single, fileName))
            {
                if (worldLoadingWindow != null)
                {
                    worldLoadingWindow.SetShouldDetach();
                }

                LongOperationCallbackManager.Unsubscribe();

                return(false);
            }

            //Update shadow settings. This operation can be slow because need update all
            //shaders if shadow technique changed.
            Map.Instance.UpdateSceneManagerShadowSettings();

            fullscreenFadingRemainingFrames = 35;

            LongOperationCallbackManager.Unsubscribe();

            //Error
            foreach (EControl control in controlManager.Controls)
            {
                if (control is MessageBoxWindow && !control.IsShouldDetach())
                {
                    return(false);
                }
            }

            //create game window
            CreateGameWindowForMap();

            //play music
            if (GameMap.Instance != null)
            {
                GameMusic.MusicPlay(GameMap.Instance.GameMusic, true);
            }

            return(true);
        }
        public static bool ServerOrSingle_MapCreate()
        {
            GameNetworkServer server = GameNetworkServer.Instance;

            Control mapLoadingWindow = null;

            //show map loading window
            mapLoadingWindow = ControlDeclarationManager.Instance.CreateControl("Gui\\MapLoadingWindow.gui");
            if (mapLoadingWindow != null)
            {
                mapLoadingWindow.Text = "Procedural map creation";
                GameEngineApp.Instance.ControlManager.Controls.Add(mapLoadingWindow);
            }

            //delete all GameWindow's
            GameEngineApp.Instance.DeleteAllGameWindows();

            MapSystemWorld.MapDestroy();

            EngineApp.Instance.RenderScene();

            //create world if need
            WorldType worldType = EntitySystemWorld.Instance.DefaultWorldType;

            if (World.Instance == null || World.Instance.Type != worldType)
            {
                WorldSimulationTypes worldSimulationType;
                EntitySystemWorld.NetworkingInterface networkingInterface = null;

                if (server != null)
                {
                    worldSimulationType = WorldSimulationTypes.ServerAndClient;
                    networkingInterface = server.EntitySystemService.NetworkingInterface;
                }
                else
                {
                    worldSimulationType = WorldSimulationTypes.Single;
                }

                if (!EntitySystemWorld.Instance.WorldCreate(worldSimulationType, worldType, networkingInterface))
                {
                    Log.Fatal("ExampleOfProceduralMapCreation: ServerOrSingle_MapCreate: EntitySystemWorld.Instance.WorldCreate failed.");
                }
            }

            //create map
            GameMapType gameMapType = EntityTypes.Instance.GetByName("GameMap") as GameMapType;

            if (gameMapType == null)
            {
                Log.Fatal("ExampleOfProceduralMapCreation: ServerOrSingle_MapCreate: \"GameMap\" type is not defined.");
            }
            GameMap gameMap = (GameMap)Entities.Instance.Create(gameMapType, World.Instance);

            gameMap.ShadowFarDistance = 60;
            gameMap.ShadowColor       = new ColorValue(.5f, .5f, .5f);

            //create MapObjects
            ServerOrSingle_CreateEntities();

            //post create map
            gameMap.PostCreate();

            //inform clients about world created
            if (server != null)
            {
                server.EntitySystemService.WorldWasCreated();
            }

            //Error
            foreach (Control control in GameEngineApp.Instance.ControlManager.Controls)
            {
                if (control is MessageBoxWindow && !control.IsShouldDetach())
                {
                    return(false);
                }
            }

            GameEngineApp.Instance.CreateGameWindowForMap();

            //play music
            if (GameMap.Instance != null)
            {
                GameMusic.MusicPlay(GameMap.Instance.GameMusic, true);
            }

            return(true);
        }