Example #1
0
 /// <summary>
 /// Inflicts damage.
 /// </summary>
 /// <param name="value">The amount of damage.</param>
 public void ReceiveDamage(int value)
 {
     if (value < 0)
     {
         throw new Exception("Not allowed");
     }
     GraphicalConsole.GetSingleton(game).WriteLine(string.Format("You got {0} Damage!", value), 1);
     if (shield > 0)
     {
         int shieldDamage = (int)(value * shieldDamageAbsorbtion);
         int newShield    = shield - shieldDamage;
         if (newShield < 0)
         {
             int remaining = (int)(-newShield / shieldDamageAbsorbtion);
             health   -= remaining;
             newShield = 0;
         }
         shield = newShield;
     }
     else
     {
         health -= value;    // no shield, apply pure damage
     }
     // handle health-state
     if (health <= 0)
     {
         Explode();
         health = 0;
     }
 }
Example #2
0
        /// <summary>
        /// Adds the state to the AI Machine
        /// </summary>
        /// <param name="state">The state.</param>
        public void AddState(IAIState state)
        {
            States.Add(state.Name, state);
            if (States.Count == 1)
            {
                currentState = state.Name;
                lastState    = state.Name;
            }

            state.Manager = this;

            if (DebugAI)
            {
                GraphicalConsole.GetSingleton(game).WriteLine(
                    string.Format("AI-DEBUG:    Begin {0}.OnInit()", state.Name), 0);
            }

            States[state.Name].OnInit(); // Call OnExit()

            if (DebugAI)
            {
                GraphicalConsole.GetSingleton(game).WriteLine(
                    string.Format("AI-DEBUG:    End {0}.OnInit()", state.Name), 0);
            }
        }
Example #3
0
 private void InfoMessage(string message)
 {
     if (ShowEnemyInfo)
     {
         GraphicalConsole.GetSingleton(game).WriteLine(String.Format("Enemy{0}: {1}", EnemyNr, message), 0);
     }
 }
Example #4
0
        private void ObjectTests()
        {
            // Items
            AddObject(new Item(game, "Health_Medium"));

            // static test

            /*Static static1 = new Static(game, "Rock");
             * static1.LocalPosition = new Vector3(50, -100, -1000);
             * AddObject(static1);
             *
             * Vector3[] positions = new Vector3[2];
             * Quaternion[] rotations = new Quaternion[2];
             * float[] scales = new float[2];
             * positions[0] = new Vector3(50, -100, -900);
             * positions[1] = new Vector3(50, -100, -1100);
             * rotations[0] = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), (float)Math.PI / 4);
             * rotations[1] = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), -(float)Math.PI / 4);
             * scales[0] = 0.5f;
             * scales[1] = 0.5f;
             * Statics statics1 = new Statics(game, 0, "Rocks", positions, rotations, scales, true);
             * AddObject(statics1);*/

            // debris test

            /*debris2 = new DebrisEmitter(game, "debrisTest", 50, 0.5f, 1.0f);
             * debris2.LocalPosition = new Vector3(50, 200, -1000);
             * debris2.Type = new DebrisEmitterTypeVolumeOOBB(game, new Vector3(100, 100, 200));
             * AddObject(debris2);
             * if (!Helper.Lock("Debris Test 2", TimeSpan.FromSeconds(15)))
             *  debris2.Emit(50);
             *
             * debris3 = new DebrisEmitter(game, "debrisTest", 20, 0.5f, 1.0f);
             * debris3.LocalPosition = new Vector3(-230, 0, -1000);
             * debris3.Type = new DebrisEmitterTypeCone(game, new Vector3(1, 0, 0), 10, 10, 50);
             * AddObject(debris3);
             * if (!Helper.Lock("Debris Test 3", TimeSpan.FromSeconds(15)))
             *  debris3.Emit(20);*/

            MovingPointLight light1 = new MovingPointLight(game, Color.Green, new Vector3(-100, 50, -400), new Vector3(150, 0, 0), Vector3.UnitY, 0.02f);

            AddPointLight(light1);
            components.Add(light1);
            MovingPointLight light2 = new MovingPointLight(game, new Color(150, 0, 0), new Vector3(100, 50, -400), new Vector3(-150, 0, 0), Vector3.UnitY, 0.02f);

            AddPointLight(light2);
            components.Add(light2);

            // physics test

            //            EnablePlayerPhysics();
            GraphicalConsole.GetSingleton(game).RegisterObjectFunction(this, "World", "EnablePlayerPhysics");

            if (game.Graphics.ShadowMappingSupported)
            {
                sky.Sunlight.ShadowMapLow.Scene.AddDrawable(canyon);
                sky.Sunlight.ShadowMapHigh.Scene.AddDrawable(player);
                sky.Sunlight.ShadowMapHigh.Scene.AddDrawable(canyon);
            }
        }
Example #5
0
 public void ZoomOut(float zoomLength)
 {
     if (LocalPosition.X != float.NaN)
     {
         LocalPosition -= this.Direction * zoomLength;
         GraphicalConsole.GetSingleton(game).WriteLine("Camera ZoomOut - Position:" + LocalPosition.ToString(), 0);
     }
 }
Example #6
0
 public void LoadLevel(string levelname)
 {
     if (File.Exists(string.Format("GameClasses\\World\\Levels\\{0}.csl", levelname)))
     {
         GameStates.SetStateGame(levelname);
     }
     else
     {
         GraphicalConsole.GetSingleton(this).WriteLine("Error: Level not found!", 0);
     }
 }
Example #7
0
 public static void SendMessage(string message, bool speak)
 {
     if (Game != null)
     {
         GraphicalConsole.GetSingleton(Game).WriteLine(message, 1);
     }
     if (speak)
     {
         Thread speakThread = new Thread(SpeakInternal);
         speakThread.Start(message);
     }
 }
Example #8
0
 /// <summary>
 /// Sets the secondary weapon.
 /// </summary>
 /// <param name="type">The type.</param>
 public void SetSecondaryWeapon(WeaponType type)
 {
     if (weapons.ContainsKey(type))
     {
         if (primaryWeapon != weapons[type])
         {
             secondaryWeapon = weapons[type];
         }
         else
         {
             GraphicalConsole.GetSingleton(game).WriteLine(
                 string.Format("Weapon not avaible: {0}.", type.ToString()), 0);
         }
     }
 }
Example #9
0
        public void ChangeState(string name)
        {
            if (!States.ContainsKey(name))
            {
                GraphicalConsole.GetSingleton(game).WriteLine("AI-ERROR:    Can't find state: " + name, 0);
                return;
            }
            if (DebugAI)
            {
                GraphicalConsole.GetSingleton(game).WriteLine(
                    string.Format("AI-DEBUG:    Begin {0}.OnExit()", currentState), 0);
            }

            States[currentState].OnExit(); // Call OnExit()

            if (DebugAI)
            {
                GraphicalConsole.GetSingleton(game).WriteLine(
                    string.Format("AI-DEBUG:    End {0}.OnExit()", currentState), 0);
            }


            if (DebugAI)
            {
                GraphicalConsole.GetSingleton(game).WriteLine(
                    string.Format("AI-DEBUG:    {0} ---> {1}", currentState, name), 0);
            }


            // Change States
            lastState    = currentState;
            currentState = name;


            if (DebugAI)
            {
                GraphicalConsole.GetSingleton(game).WriteLine(
                    string.Format("AI-DEBUG:    Begin {0}.OnEnter()", currentState), 0);
            }

            States[currentState].OnEnter(); // Call OnEnter()

            if (DebugAI)
            {
                GraphicalConsole.GetSingleton(game).WriteLine(
                    string.Format("AI-DEBUG:    End {0}.OnEnter()", currentState), 0);
            }
        }
Example #10
0
        public void UpdateAI(GameTime gameTime)
        {
            this.gameTime = gameTime;

            if (DebugAI)
            {
                GraphicalConsole.GetSingleton(game).WriteLine(
                    string.Format("AI-DEBUG:    Begin {0}.Update()", currentState), 0);
            }

            States[currentState].Update();

            if (DebugAI)
            {
                GraphicalConsole.GetSingleton(game).WriteLine(
                    string.Format("AI-DEBUG:    End {0}.Update()", currentState), 0);
            }
        }
Example #11
0
        /// <summary>
        /// Assigns the weapon slot to the weapon defined by Weapontype type.
        /// Sets the specified position, rotation and scale
        /// </summary>
        /// <param name="type">The type.</param>
        private void AssignWeaponSlot(WeaponType type)
        {
            if (weaponHolder == null)
            {
                return;
            }

            // For rotating the weapons while aiming, we need a special Transformable that hold
            // the correct rotated weapon model.
            // With this, we are able to rotate the connector only.

            ITransformable weaponConnector = new Transformable(game);

            weaponConnector.Parent = weaponHolder;
            weapons[type].Parent   = weaponConnector;

            if (weaponHolder.WeaponSlots == null)
            {
                return;
            }

            bool success = false;

            foreach (WeaponSlot slot in weaponHolder.WeaponSlots)
            {
                if (slot.WeaponType == type)
                {
                    //Set start-location and rotation of each weapon on its specified slot.
                    weapons[type].LocalPosition = slot.Position;
                    weapons[type].LocalRotation =
                        Quaternion.CreateFromAxisAngle(slot.RotationAxis, slot.RotationAngle);
                    weapons[type].LocalScale = slot.Scaling;

                    success = true;
                    break;
                }
            }

            if (!success)
            {
                GraphicalConsole.GetSingleton(game).WriteLine("No WeaponSlot for weapon " + type + " in weapon holder " + weaponHolder.Name, 0);
            }
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CanyonShooterGame"/> class.
        /// </summary>
        public CanyonShooterGame(string[] args)
        {
            Args   = new Arguments(args);
            states = new GameStates(this, Components);
            config = new Config();
            graphicsDeviceManager = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);

            graphics          = new Graphics(this, graphicsDeviceManager);
            this.Window.Title = " CanyonShooter";

            Intercom.Game = this;

            #region Commandline Parameter Settings:

            #region Parameter: --setShaderModel

            if (Args["setShaderModel"] == "2")
            {
                graphics.ShaderModel3SupportedOverride = true;
            }
            #endregion

            #region Parameter: --debug

            if (Args["debug"] == "1")
            {
                debugMode = true;
            }
            #endregion

            #region Parameter: --multiThreaded
            // Physik Intialisierung

            /*if (Args["multiThreaded"] != null)
             * {
             *  if(Args["multiThreaded"] == "1")
             *      physics = new Physics(this, true);
             *  else
             *  {
             *      physics = new Physics(this, false);
             *      Components.Add(physics);
             *  }
             * }
             * else*/// automatically set threading-mode
            {
                /*if (Environment.ProcessorCount > 1)
                 * {
                 *  physics = new Physics(this, true);
                 * }
                 * else*/
                {
                    physics = new Physics(this, false);
                    Components.Add(physics);
                }
            }
            #endregion

            #region Parameter: --testAudio
            // Test Audio Framework *******************************
            if (Args["testAudio"] == "1")
            {
                TestAudioPlayback test1 = new TestAudioPlayback();
                test1.SetUp(this);
                test1.TestMinigunPlayback();
                test1.TearDown();

                TestAudio3D test2 = new TestAudio3D();
                test2.SetUp(this);
                test2.TestPlayback3D();
                test2.TearDown();
            }
            #endregion

            #endregion

            // Create sound system by M.Rodriguez
            sounds = new SoundSystem(this);

            // Set global volumes by M.Rodriguez
            sounds.EffectVolume = 1.0f;
            sounds.MusicVolume  = 0.3f;

            // Initialisieren der einzelnen Komponenten:
            input      = new Input(this);
            renderer   = new Renderer(this, Components);
            effects    = new EffectFactory(this);
            highscores = new Highscores(this);

            GraphicalConsole.GetSingleton(this).RegisterObjectProperty(graphics, "Graphics", "Fullscreen");

            GraphicalConsole.GetSingleton(this).RegisterObjectProperty(renderer, "Renderer", "DrawCollisionShapes");

            GraphicalConsole.GetSingleton(this).RegisterObjectFunction(Args, "Args", "ListParameters");
            if (Args["enable3DMouse"] == "1")
            {
                hasSpaceMouse = true;
                device        = new TDxInput.Device();
            }
            states.SetStateStart();

            // states.SetStateDebugMode();
        }
Example #13
0
        public void SetStateGame(string levelname)
        {
            if (score != null)
            {
                score.Reset();
            }
            score = null;

            game.Graphics.ShadowMappingSupportedOverride = !profil.CurrentProfil.Shadow;
            game.Graphics.AllowFogShaders = profil.CurrentProfil.Fog;

            Reset();


            components.Add(game.Physics);

            game.Input.MouseMovement = new Vector2(0, 0);

            hud = new Hud(game, "test");
            components.Add(hud);
            components.Add(GraphicalConsole.GetSingleton(game));
            GraphicalConsole.GetSingleton(game).RegisterObjectFunction(game, "Game", "Exit");
            GraphicalConsole.GetSingleton(game).RegisterObjectFunction(game.Input, "Input", "Bind");

            GraphicalConsole.GetSingleton(game).WriteLine(string.Format("Loading Level: {0}", levelname), 0);
            game.World = new World(game, levelname, components);

            components.Add(game.World);


            GraphicalConsole.GetSingleton(game).RegisterObjectFunction(game, "Game", "LoadLevel");


            Cheats cheats = new Cheats(game);

            components.Add(cheats);
            GraphicalConsole.GetSingleton(game).RegisterObjectProperty(cheats, "OneBananaProblem", "GodMode");
            score = new Score();

            // set post processing
            game.Renderer.PostProcessType = PostProcessType.BloomAndBlur;

            game.Renderer.Camera = game.World.Players[0].Camera;
            inputFocus           = game.World;
            if (welcomeSound == null)
            {
                welcomeSound = game.Sounds.CreateSound("Welcome");
            }
            welcomeSound.Play();
            game.Sounds.MusicBox(MusicBoxStatus.Play);

            TrafficLight trafficLight = new TrafficLight(game, TrafficLightGreenCallback);

            trafficLight.LocalPosition = game.World.Players[0].GlobalPosition + new Vector3(0, 130, -200);
            trafficLight.CanyonSegment = 0;
            game.World.AddObject(trafficLight);
            trafficLight.Start();
            //Gameplayed = true;

            // player shall wait until the trafficLight shows green
            game.World.Players[0].Enabled = false;
        }
Example #14
0
        /// <summary>
        ///		Called by the base engine class when its safe to update and render the scene.
        /// </summary>
        protected override void Update()
        {
            // Ignore everything else if we are not running a game.
            if (_gameName == "")
            {
                return;
            }

            //System.Console.WriteLine("Collective Time("+EntityNode.CollectiveCalls+" calls): "+EntityNode.CollectiveTime);
            //EntityNode.CollectiveTime = 0.0f;
            //EntityNode.CollectiveCalls = 0;
            //EntityNode.CollectiveTimer.Restart();

            // Time to load a map?
            if (_mapLoadPending == true)
            {
                // Pump out a MapFinish event.
                EventManager.FireEvent(new Event("map_finish", this, null));

                // Allow the processes some time to be notified of closing events.
                //EventManager.ProcessEvents();
                //ProcessManager.RunProcesses(1);

                // Tell the scripts that we are now loading the new map (so they can show a loadings screen).
                _gameScriptProcess.Process.InvokeFunction("OnLoadingBegin", true, true);

                // Don't want to render the scene graph as its currently being loaded >.<.
                bool priorSceneGraphRender = true;
                if (_isServer == false)
                {
                    priorSceneGraphRender       = _window.RenderSceneGraph;
                    _window.RenderLoadingScreen = true;
                    _window.RenderSceneGraph    = false;
                }

                // Keep track of time :).
                HighPreformanceTimer loadTimer = new HighPreformanceTimer();

                // Get starting memory.
                long startingMemory = GC.GetTotalMemory(true);

                if (GraphicsManager.ThreadSafe == false)
                {
                    // Load the new map.
                    DebugLogger.WriteLog("Loading map from " + _mapLoadFile + " " + (_mapLoadPassword != "" ? " with password " + _mapLoadPassword : "") + ".");
                    LoadMapThread();
                }
                else
                {
                    // Load the new map.
                    DebugLogger.WriteLog("Loading map from " + _mapLoadFile + " " + (_mapLoadPassword != "" ? " with password " + _mapLoadPassword : "") + ".");
                    Thread thread = new Thread(LoadMapThread);
                    thread.Priority = ThreadPriority.Highest;
                    // Thread.CurrentThread.Priority = ThreadPriority.Lowest;
                    thread.IsBackground = true;
                    thread.Start();

                    // Ech, there has to be a better way than this. I hate thread safety >.>.
                    HighPreformanceTimer timer = new HighPreformanceTimer();
                    while (thread != null && thread.IsAlive == true)
                    {
                        // Track frame stats.
                        TrackFrameStatsBegin();

                        // Update the process.
                        //timer = new HighPreformanceTimer();
                        //_gameScriptProcess.Run(_deltaTime);
                        //_processProcessingDuration = (float)timer.DurationMillisecond;

                        // Update the graphical console.
                        if (_isServer == false)
                        {
                            GraphicalConsole.Update(1.0f);
                        }

                        // Tell the window to render
                        if (_isServer == false)
                        {
                            timer.Restart();
                            GraphicsCanvas.RenderAll();
                            _window.Render();
                            _renderingDuration = (float)timer.DurationMillisecond;
                        }

                        // Update network.
                        NetworkManager.Poll();

                        // Process application level events.
                        timer.Restart();
                        Application.DoEvents();
                        _applicationProcessingDuration = (float)timer.DurationMillisecond;

                        // Track frame stats.
                        TrackFrameStatsFinish();
                    }
                }

                // Invoke OnCreate events of scripted entities.
                foreach (SceneNode node in _map.SceneGraph.EnumerateNodes())
                {
                    if (node != null && node is ScriptedEntityNode && node.IsPersistent == false)
                    {
                        ((ScriptedEntityNode)node).ScriptProcess[0].InvokeFunction("OnCreate", true, false);
                    }
                }

                // Run the collision manager quickly so that we can sort out any unplesent problems.
                CollisionManager.ProcessCollisions();

                //Thread.CurrentThread.Priority = ThreadPriority.Normal;

                // We can render again! Oh holy days!
                if (_isServer == false)
                {
                    _window.RenderLoadingScreen = false;
                    _window.RenderSceneGraph    = priorSceneGraphRender;
                }

                // Remove any old resource from the cache that haven't been used for 5 maps :P.
                ResourceManager.CollectGarbage(3);

                // Free up some space.
                GC.Collect();

                // And we are done!
                DebugLogger.WriteLog("Map loaded successfully in " + loadTimer.DurationMillisecond + "ms, " + (((GC.GetTotalMemory(false) - startingMemory) / 1024.0f) / 1024.0f) + "mb allocated during loading.");

                // Yay, loaded!
                _mapLoadPending = false;

                // Reset the delta time!
                _forcedDeltaTimeThisFrame = 1.0f;
            }
        }
Example #15
0
 public void clear(object[] arguments)
 {
     GraphicalConsole.Clear();
 }
Example #16
0
        /// <summary>
        ///     Renders the game in all its glory!
        /// </summary>
        public void Render()
        {
            /* GraphicsManager.BeginScene();
             * GraphicsManager.ClearRenderState();
             * GraphicsManager.Viewport = new Rectangle(0, 0, GraphicsManager.Resolution[0], GraphicsManager.Resolution[1]);
             * GraphicsManager.ClearColor = unchecked((int)0xFFFF0000);
             * GraphicsManager.ClearScene();
             *
             * GraphicsManager.VertexColors[0] = unchecked((int)0xFFFFFFFF);
             * GraphicsManager.VertexColors[1] = unchecked((int)0xFF00FF00);
             * GraphicsManager.VertexColors[2] = unchecked((int)0xFFFF00FF);
             * GraphicsManager.VertexColors[3] = unchecked((int)0xFF0000FF);
             * GraphicsManager.RenderRectangle(5, 5, 0, 16, 16, true);
             * GraphicsManager.RenderRectangle(5, 37, 0, 16, 16, false);
             *
             * GraphicsManager.RenderOval(37, 5, 0, 16, 16, true);
             * GraphicsManager.RenderOval(37, 37, 0, 16, 16, false);
             *
             * GraphicsManager.RenderLine(74, 5, 0, 74 + 16, 5 + 16, 0);
             * GraphicsManager.RenderLine(74, 37, 0, 74 + 16, 37 + 16, 0);
             *
             * GraphicsManager.FinishScene();
             * GraphicsManager.PresentScene();
             *
             * return;*/
            //HighPreformanceTimer timer = new HighPreformanceTimer();

            // Don't try and render if we don't have a loading function.
            if (_renderLoadingScreen == true && (Fusion.GlobalInstance.GameScriptProcess == null || Fusion.GlobalInstance.GameScriptProcess.Process == null || Fusion.GlobalInstance.GameScriptProcess.Process.SymbolExists("OnLoadingRender") == false))
            {
                return;
            }

            // Begin rendering.
            GraphicsManager.PushRenderState();
            GraphicsManager.BeginScene();
            GraphicsManager.ClearRenderState();
            // GraphicsManager.ClearColor = unchecked((int)0xFFFF0000);
            GraphicsManager.ClearScene();
            GraphicsManager.Viewport = new Rectangle(0, 0, GraphicsManager.Resolution[0], GraphicsManager.Resolution[1]);

            if (_renderThisFrame == true)
            {
                // Render the current scene graph.
                if (_renderSceneGraph == true)
                {
                    GraphicsManager.PushRenderState();
                    Engine.GlobalInstance.Map.SceneGraph.Render();
                    GraphicsManager.PopRenderState();
                }

                // Do we have a game script render function?
                if (_gameScriptRenderFunction != null)
                {
                    GraphicsManager.PushRenderState();
                    Fusion.GlobalInstance.GameScriptProcess.Process[0].InvokeFunction(_gameScriptRenderFunction, true, true, true);
                    GraphicsManager.PopRenderState();
                }

                // Do we have a map script render function?
                if (_mapScriptRenderFunction != null)
                {
                    GraphicsManager.PushRenderState();
                    Fusion.GlobalInstance.MapScriptProcess.Process[0].InvokeFunction(_mapScriptRenderFunction, true, true, true);
                    GraphicsManager.PopRenderState();
                }
            }
            else
            {
                _renderThisFrame = true;
            }

            // Render the loading screen if we have been asked to.
            if (_renderLoadingScreen == true && Fusion.GlobalInstance.GameScriptProcess != null && Fusion.GlobalInstance.GameScriptProcess.Process != null && Fusion.GlobalInstance.GameScriptProcess.Process.SymbolExists("OnLoadingRender"))
            {
                GraphicsManager.PushRenderState();
                Fusion.GlobalInstance.GameScriptProcess.Process[0].InvokeFunction("OnLoadingRender", true, true, true);
                GraphicsManager.PopRenderState();
            }

            // Tell plugins to render.
            Plugin.CallPluginMethod("Render");

            // Render the console.
            GraphicsManager.Resolution       = new int[] { ClientSize.Width, ClientSize.Height };
            GraphicsManager.ResolutionOffset = new float[] { 0, 0 };
            GraphicsManager.ResolutionScale  = new float[] { 1.0f, 1.0f };
            GraphicalConsole.Render();

            GraphicsManager.FinishScene();
            GraphicsManager.PresentScene();
            GraphicsManager.PopRenderState();
            //System.Console.WriteLine("R: " + (float)timer.DurationMillisecond);
            //System.Console.WriteLine("Spent " + Graphics.Image._tileTime);
            //Graphics.Image._tileTime = 0;
        }