Ejemplo n.º 1
0
        public Roaches (GameState state, AIManager aiManager, RendererContext rendererContext)
        {
            RoachGameState = state;

            roachGroup = new RoachGroup (state.Scene);

            RoachEntity = EntityFactory.Instance.CreateWith("Roach." + InstanceCount++, state.MessageProxy,
                new[] { typeof (ArtificialIntelligenceComponent) },
                new[] { typeof (PhysicsSystem), typeof (RoachGroupSystem) });

            RoachEntity.GetComponent<RoachGroupComponent>().RoachGroup = roachGroup;

            RigidBody roachBody = new RigidBody (new CylinderShape (0.05f, 1));
            roachBody.AffectedByGravity = false;
            roachBody.AllowDeactivation = false;
            roachBody.Mass = 20;
            roachBody.Tag = roachGroup;
            RoachEntity.GetComponent<PhysicsComponent> ().RigidBody = roachBody;
            RoachEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            RoachEntity.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            state.PhysicsManager.World.AddBody (roachBody);

            RoachEntity.GetComponent<ArtificialIntelligenceComponent>().AIManager = aiManager;
            RoachEntity.GetComponent<ArtificialIntelligenceComponent>().ArtificialIntelligence =
                new RoachesAI (roachGroup, RoachEntity, state);
            aiManager.RegisterEntity (RoachEntity);
        }
Ejemplo n.º 2
0
 public void SwitchItemsToGameState(GameState source, GameState dest, FreezingArcher.Content.Game game)
 {
     foreach (ItemComponent ic in items.Values)
     {
         game.MoveEntityToGameState (ic.Entity, source, dest);
     }
 }
Ejemplo n.º 3
0
        public Passus (CompositorColorCorrectionNode colorCorrectionNode,
            GameState state, AIManager aiManager, RendererContext rendererContext)
        {
            passusEmitter = new PassusGhostParticleEmitter ();

            PassusGameState = state;

            particlePassus = new ParticleSceneObject (passusEmitter.ParticleCount);
            particlePassus.Priority = 7001;
            state.Scene.AddObject (particlePassus);
            passusEmitter.Init (particlePassus, rendererContext);

            PassusEntity = EntityFactory.Instance.CreateWith ("Passus." + InstanceCount++, state.MessageProxy,
                new[] { typeof (ArtificialIntelligenceComponent) },
                new[] { typeof (ParticleSystem), typeof (PhysicsSystem) });

            PassusEntity.GetComponent<ParticleComponent> ().Emitter = passusEmitter;
            PassusEntity.GetComponent<ParticleComponent> ().Particle = particlePassus;

            RigidBody passusBody = new RigidBody (new SphereShape (1.2f));
            passusBody.AffectedByGravity = false;
            passusBody.AllowDeactivation = false;
            passusBody.Mass = 20;
            PassusEntity.GetComponent<PhysicsComponent> ().RigidBody = passusBody;
            PassusEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            PassusEntity.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            state.PhysicsManager.World.AddBody (passusBody);

            var AIcomp = PassusEntity.GetComponent<ArtificialIntelligenceComponent>();
            AIcomp.AIManager = aiManager;
            AIcomp.ArtificialIntelligence = new PassusAI (PassusEntity, state, colorCorrectionNode);
            aiManager.RegisterEntity (PassusEntity);
        }
Ejemplo n.º 4
0
        public Caligo (GameState state, AIManager aiManager, RendererContext rendererContext,
            CompositorWarpingNode warpingNode)
        {
            caligoEmitter = new CaligoParticleEmitter ();
            particleCaligo = new ParticleSceneObject (caligoEmitter.ParticleCount);
            particleCaligo.Priority = 7000;
            state.Scene.AddObject (particleCaligo);
            caligoEmitter.Init (particleCaligo, rendererContext);

            CaligoGameState = state;

            CaligoEntity = EntityFactory.Instance.CreateWith ("Caligo." + InstanceCount++, state.MessageProxy,
                new[] { typeof (ArtificialIntelligenceComponent) },
                new[] { typeof (ParticleSystem), typeof (PhysicsSystem) });

            CaligoEntity.GetComponent<ParticleComponent> ().Emitter = caligoEmitter;
            CaligoEntity.GetComponent<ParticleComponent> ().Particle = particleCaligo;

            RigidBody caligoBody = new RigidBody (new SphereShape (1.2f));
            caligoBody.AffectedByGravity = false;
            caligoBody.AllowDeactivation = false;
            caligoBody.Mass = 20;
            CaligoEntity.GetComponent<PhysicsComponent> ().RigidBody = caligoBody;
            CaligoEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            CaligoEntity.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            state.PhysicsManager.World.AddBody (caligoBody);

            var AIcomp = CaligoEntity.GetComponent<ArtificialIntelligenceComponent>();
            AIcomp.AIManager = aiManager;
            AIcomp.ArtificialIntelligence = new CaligoAI (CaligoEntity, state, warpingNode);
            aiManager.RegisterEntity (CaligoEntity);
        }
Ejemplo n.º 5
0
        public FenFireAI (Entity entity, GameState state)
        {
            gameState = state;
            this.entity = entity;
            AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            Provider += this;
        }
Ejemplo n.º 6
0
        public ViridionAI (Entity entity, GameState state, CompositorColorCorrectionNode colorCorrectionNode)
        {
            this.colorCorrectionNode = colorCorrectionNode;
            this.entity = entity;
            gameState = state;
            AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            Provider += this;
        }
Ejemplo n.º 7
0
        public RoachesAI (RoachGroup roachGroup, Entity entity, GameState state)
        {
            this.roachGroup = roachGroup;
            this.entity = entity;
            this.state = state;
            AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            Provider += this;
        }
Ejemplo n.º 8
0
        public void SwitchGameState(GameState state)
        {
            GameState.MessageProxy.UnregisterMessageConsumer (this);
            GameState.MessageProxy.RemoveMessageCreator (this);

            GameState = state;

            GameState.MessageProxy.RegisterMessageConsumer(this);
            this.GameState.MessageProxy.AddMessageCreator (this);
        }
Ejemplo n.º 9
0
        public ScobisAI (ScobisSmokeParticleEmitter smokeParticleEmitter, Entity entity, GameState state)
        {
            this.smokeParticleEmitter = smokeParticleEmitter;
            this.entity = entity;
            this.state = state;
            AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            Provider += this;
        }
Ejemplo n.º 10
0
        public CaligoAI (Entity entity, GameState state, CompositorWarpingNode warpingNode)
        {
            this.entity = entity;
            this.state = state;
            this.warpingNode = warpingNode;
            this.AIcomp = entity.GetComponent<ArtificialIntelligenceComponent>();

            Provider = state.MessageProxy;
            this.Provider += this;
        }
Ejemplo n.º 11
0
        public MazeWallMover (Maze maze, Maze secondMaze, GameState state,
            Func<int, int, bool> containsPortal)
        {
            Maze = maze;
            SecondMaze = secondMaze;
            this.GameState = state;
            rand = new FastRandom(maze.Seed);
            this.containsPortal = containsPortal;

            ValidMessages = new[] { (int) MessageId.Update };

            this.GameState.MessageProxy.RegisterMessageConsumer(this);
            this.GameState.MessageProxy.AddMessageCreator (this);
        }
Ejemplo n.º 12
0
        public Viridion (GameState state, AIManager aiManager, RendererContext rendererContext,
            CompositorColorCorrectionNode colorCorrectionNode)
        {
            viridionEmitter = new ViridionParticleEmitter ();

            ViridionGameState = state;

            particleViridion = new ParticleSceneObject (viridionEmitter.ParticleCount);
            particleViridion.Priority = 7002;
            state.Scene.AddObject (particleViridion);
            viridionEmitter.Init (particleViridion, rendererContext);

            ViridionEntity = EntityFactory.Instance.CreateWith ("Viridion." + InstanceCount++, state.MessageProxy,
                new[] { typeof (ArtificialIntelligenceComponent) },
                new[] { typeof (ParticleSystem), typeof (PhysicsSystem), typeof(LightSystem) });

            ViridionEntity.GetComponent<ParticleComponent> ().Emitter = viridionEmitter;
            ViridionEntity.GetComponent<ParticleComponent> ().Particle = particleViridion;

            var light = ViridionEntity.GetComponent<LightComponent> ().Light;
            light = new FreezingArcher.Renderer.Scene.Light (FreezingArcher.Renderer.Scene.LightType.PointLight);
            light.On = true;
            light.Color = new FreezingArcher.Math.Color4 (0.6f, 0.6f, 0.6f, 1.0f);
            light.PointLightLinearAttenuation = 0.4f;
            light.PointLightConstantAttenuation = 0.7f;
            light.PointLightExponentialAttenuation = 0.008f;

            ViridionEntity.GetComponent<LightComponent> ().Light = light;

            state.Scene.AddLight (light);

            RigidBody ghostBody = new RigidBody (new SphereShape (1.2f));
            ghostBody.AffectedByGravity = false;
            ghostBody.AllowDeactivation = false;
            ghostBody.Mass = 20;
            ViridionEntity.GetComponent<PhysicsComponent> ().RigidBody = ghostBody;
            ViridionEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            ViridionEntity.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            state.PhysicsManager.World.AddBody (ghostBody);

            ViridionEntity.GetComponent<ArtificialIntelligenceComponent>().AIManager = aiManager;
            ViridionEntity.GetComponent<ArtificialIntelligenceComponent>().ArtificialIntelligence =
                new ViridionAI (ViridionEntity, state, colorCorrectionNode);
            aiManager.RegisterEntity (ViridionEntity);
        }
Ejemplo n.º 13
0
        public FenFire (GameState state, AIManager aiManager, RendererContext rendererContext)
        {
            ghostEmitter = new FenFireParticleEmitter ();

            particleGhost = new ParticleSceneObject (ghostEmitter.ParticleCount);
            particleGhost.Priority = 7092;
            state.Scene.AddObject (particleGhost);
            ghostEmitter.Init (particleGhost, rendererContext);

            GhostGameState = state;

            GhostEntity = EntityFactory.Instance.CreateWith ("FenFire." + InstanceCount++, state.MessageProxy,
                new[] { typeof (ArtificialIntelligenceComponent) },
                new[] { typeof (ParticleSystem), typeof (PhysicsSystem), typeof(LightSystem) });

            GhostEntity.GetComponent<ParticleComponent> ().Emitter = ghostEmitter;
            GhostEntity.GetComponent<ParticleComponent> ().Particle = particleGhost;

            var light = GhostEntity.GetComponent<LightComponent> ().Light;
            light = new FreezingArcher.Renderer.Scene.Light (FreezingArcher.Renderer.Scene.LightType.PointLight);
            light.On = true;
            light.Color = new FreezingArcher.Math.Color4 (0.0f, 0.0f, 0.6f, 1.0f);
            light.PointLightLinearAttenuation = 0.4f;
            light.PointLightConstantAttenuation = 0.7f;
            light.PointLightExponentialAttenuation = 0.008f;

            GhostEntity.GetComponent<LightComponent> ().Light = light;

            state.Scene.AddLight (light);

            RigidBody ghostBody = new RigidBody (new SphereShape (0.4f));
            ghostBody.AffectedByGravity = false;
            ghostBody.AllowDeactivation = false;
            ghostBody.Mass = 20;
            GhostEntity.GetComponent<PhysicsComponent> ().RigidBody = ghostBody;
            GhostEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            GhostEntity.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            state.PhysicsManager.World.AddBody (ghostBody);

            GhostEntity.GetComponent<ArtificialIntelligenceComponent>().AIManager = aiManager;
            GhostEntity.GetComponent<ArtificialIntelligenceComponent>().ArtificialIntelligence =
                new FenFireAI (GhostEntity, state);
            aiManager.RegisterEntity (GhostEntity);
        }
Ejemplo n.º 14
0
        public Inventory(MessageProvider messageProvider, GameState state, Entity player, Vector2i size, byte barSize)
        {
            Size = size;
            messageProvider += this;
            this.messageProvider = messageProvider;
            this.player = player;
            gameState = state;
            storage = new int?[Size.X, Size.Y];

            if (barSize < 1 || barSize > 10)
            {
                Logger.Log.AddLogEntry(LogLevel.Error, "Inventory",
                    "Inventory bar size must be between 1 and 10 but is {0}!", barSize);
                return;
            }

            inventoryBar = new int?[barSize];
        }
Ejemplo n.º 15
0
        public Scobis (GameState state, AIManager aiManager, RendererContext rendererContext)
        {
            paremitter = new ScobisParticleEmitter ();
            particleEye1 = new ParticleSceneObject (paremitter.RedEye1.ParticleCount);
            particleEye2 = new ParticleSceneObject (paremitter.RedEye2.ParticleCount);
            particleSmoke = new ParticleSceneObject (paremitter.Smoke.ParticleCount);
            particleEye1.Priority = 5999;
            particleEye2.Priority = 5999;
            particleSmoke.Priority = 6000;

            ScobisGameState = state;

            state.Scene.AddObject (particleEye1);
            state.Scene.AddObject (particleEye2);
            state.Scene.AddObject (particleSmoke);

            particle = new ParticleSceneObject (paremitter.ParticleCount);
            particle.Priority = 5998;
            state.Scene.AddObject (particle);

            paremitter.Init (particle, particleEye1, particleEye2, particleSmoke, rendererContext);

            ScobisEntity = EntityFactory.Instance.CreateWith ("Scobis." + InstanceCount++, state.MessageProxy,
                new[] { typeof (ArtificialIntelligenceComponent) },
                new[] { typeof (ParticleSystem), typeof (PhysicsSystem) });

            ScobisEntity.GetComponent<ParticleComponent> ().Emitter = paremitter;
            ScobisEntity.GetComponent<ParticleComponent> ().Particle = particle;
            RigidBody scobisBody = new RigidBody (new SphereShape (0.3f));
            scobisBody.AffectedByGravity = false;
            scobisBody.AllowDeactivation = false;
            scobisBody.Mass = 20;
            ScobisEntity.GetComponent<PhysicsComponent> ().RigidBody = scobisBody;
            ScobisEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            ScobisEntity.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            state.PhysicsManager.World.AddBody (scobisBody);

            var AIcomp = ScobisEntity.GetComponent<ArtificialIntelligenceComponent>();
            AIcomp.AIManager = aiManager;
            AIcomp.ArtificialIntelligence = new ScobisAI (paremitter.Smoke, ScobisEntity, state);
            AIcomp.MaximumEntityDistance = 30;
            aiManager.RegisterEntity (ScobisEntity);
        }
Ejemplo n.º 16
0
        public void Init (GameState state)
        {
            this.state = state;

            scnobjarr_wall = new SceneObjectArray ("ModelSceneObject_lib/Renderer/TestGraphics/Wall/wall.xml");
            scnobjarr_wall.LayoutLocationOffset = 10;
            state.Scene.AddObject (scnobjarr_wall);

            scnobjarr_ground = new SceneObjectArray ("ModelSceneObject_lib/Renderer/TestGraphics/Ground/ground.xml");
            scnobjarr_ground.LayoutLocationOffset = 10;
            state.Scene.AddObject (scnobjarr_ground);

            scnobjarr_wall.BeginPrepare ();
            scnobjarr_ground.BeginPrepare ();

            systems = new[] { typeof (ModelSystem), typeof (PhysicsSystem) };

            scale = new Vector3 (4, 4, 4);
        }
Ejemplo n.º 17
0
 public Inventory(MessageProvider messageProvider, GameState state, Entity player, int sizeX, int sizeY, byte barSize)
     : this(messageProvider, state, player, new Vector2i(sizeX, sizeY), barSize)
 {
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Generate this instance.
        /// </summary>
        public void Generate(Action<float, string> progressUpdate, Action postGenerateHook = null, GameState state = null)
        {
            if (!IsInitialized)
            {
                Logger.Log.AddLogEntry(LogLevel.Error, "Maze", "Cannot generate maze as it is not initialized!");
                return;
            }

            if (IsGenerated)
            {
                Logger.Log.AddLogEntry(LogLevel.Warning, "Maze", "The maze has already been generated!");
                return;
            }

            if (generateMazeDelegate != null)
            {
                IsGenerated = true;

                var generationThread = new Thread(() => 
                {
                    progressUpdate(0, "Generating maze...");

                    bool proxy = false;
                    if (!state.MessageProxy.Running)
                    {
                        proxy = true;
                        state.MessageProxy.StartProcessing();
                    }
                    
                    generateMazeDelegate (ref graph, ref rand, MaximumContinuousPathLength, Turbulence);

                    progressUpdate(0.25f, "Adding maze to scene...");

                    if (state != null)
                        AddToGameState (state, progressUpdate);

                    progressUpdate(0, "Running post generation hooks...");
                    CalculatePathToExit ();

                    if (proxy)
                    {
                        Thread.Sleep (1000); // we don't wanna loose messages here :)
                        state.MessageProxy.StopProcessing();
                    }

                    if (postGenerateHook != null)
                        postGenerateHook();

                    progressUpdate(0, "Finished!");

                    HasFinished = true;
                    AIManager.StartThinking ();
                });
                generationThread.Start ();
            }
            else
            {
                Logger.Log.AddLogEntry (LogLevel.Error, "Maze", "Failed to generate maze as the generator is null!");
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Adds to scene.
        /// </summary>
        /// <param name="state">The game state the maze should be added to.</param>
        public void AddToGameState(GameState state, Action<float, string> progressUpdate)
        {
            if (!IsInitialized)
            {
                Logger.Log.AddLogEntry(LogLevel.Error, "Maze", "Cannot add maze to scene as the maze is not initialized!");
                return;
            }

            if (addMazeToGameStateDelegate != null)
            {
                addMazeToGameStateDelegate(audio, graph, state.MessageProxy, entities, ref playerPosition, state, rand, theme,
                    Scale, (uint) Size.X, (uint)Size.Y, Offset.X, Offset.Y, progressUpdate);
            }
            else
            {
                Logger.Log.AddLogEntry(LogLevel.Error, "Maze", "Cannot add maze to scene as scene adder is null!");
            }
        }
Ejemplo n.º 20
0
 public InventoryGUI (Application application, GameState state, Entity player, MessageProvider messageProvider,
     CompositorWarpingNode warpingNode)
 {
     this.application = application;
     this.player = player;
     this.MessageProvider = messageProvider;
     this.GameState = state;
     this.warpingNode = warpingNode;
     ValidMessages = new[] {
         (int) MessageId.WindowResize,
         (int) MessageId.UpdateLocale,
         (int) MessageId.Input,
         (int) MessageId.Update,
         (int) MessageId.ActiveInventoryBarItemChanged
     };
     messageProvider += this;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Moves an entity from one game state to antother.
        /// </summary>
        /// <param name="entity">Entity.</param>
        /// <param name="source">Source.</param>
        /// <param name="destination">Destination.</param>
        public void MoveEntityToGameState(Entity entity, GameState source, GameState destination)
        {
            if (entity.HasComponent<ModelComponent>())
            {
                var model = entity.GetComponent<ModelComponent>().Model;
                source.Scene.RemoveObject(model);
                destination.Scene.AddObject(model);
            }

            if (entity.HasComponent<SkyboxComponent>())
            {
                var model = entity.GetComponent<SkyboxComponent>().Skybox;
                source.Scene.RemoveObject(model);
                destination.Scene.AddObject(model);
            }

            if (entity.HasComponent<PhysicsComponent> ())
            {
                var rigidBody = entity.GetComponent<PhysicsComponent> ().RigidBody;
                source.PhysicsManager.World.RemoveBody (rigidBody);
                destination.PhysicsManager.World.AddBody (rigidBody);
            }

            if (entity.HasComponent<LightComponent> ())
            {
                var light = entity.GetComponent<LightComponent> ().Light;
                source.Scene.RemoveLight (light);
                destination.Scene.AddLight (light);
            }

            entity.SwitchMessageProvider(source.MessageProxy, destination.MessageProxy);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Adds the state of the game.
        /// </summary>
        /// <returns><c>true</c>, if game state was added, <c>false</c> otherwise.</returns>
        /// <param name="gameState">Game state.</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        public bool AddGameState(GameState gameState, IEnumerable<Tuple<string, GameStateTransition>> from = null,
            IEnumerable<Tuple<string, GameStateTransition>> to = null)
        {
            if (from == null && to == null)
            {
                GameStateGraph.AddNode(gameState);
            }
            else if (from == null && to != null)
            {
                var outgoing = new List<Pair<DirectedWeightedNode<GameState, GameStateTransition>, GameStateTransition>>();
                foreach (var t in to)
                {
                    var node = GameStateGraph.Nodes.FirstOrDefault(n => n.Data.Name == t.Item1);
                    if (node != null)
                    {
                        var trans = t.Item2 ?? GameStateTransition.DefaultTransition;
                        outgoing.Add(
                            new Pair<DirectedWeightedNode<GameState, GameStateTransition>, GameStateTransition>(
                                node, trans));
                    }
                }

                GameStateGraph.AddNode(gameState, outgoing);
            }
            else if (from != null && to == null)
            {
                var incoming = new List<Pair<DirectedWeightedNode<GameState, GameStateTransition>, GameStateTransition>>();
                foreach (var t in from)
                {
                    var node = GameStateGraph.Nodes.FirstOrDefault(n => n.Data.Name == t.Item1);

                    if (node != null)
                    {
                        var trans = t.Item2 ?? GameStateTransition.DefaultTransition;
                        incoming.Add(
                            new Pair<DirectedWeightedNode<GameState, GameStateTransition>, GameStateTransition>(
                                node, trans));
                    }
                }

                GameStateGraph.AddNode(gameState, null, incoming);
            }
            else if (from != null && to != null)
            {
                var outgoing = new List<Pair<DirectedWeightedNode<GameState, GameStateTransition>, GameStateTransition>>();
                foreach (var t in to)
                {
                    var node = GameStateGraph.Nodes.FirstOrDefault(n => n.Data.Name == t.Item1);
                    if (node != null)
                    {
                        var trans = t.Item2 ?? GameStateTransition.DefaultTransition;
                        outgoing.Add(
                            new Pair<DirectedWeightedNode<GameState, GameStateTransition>, GameStateTransition>(
                                node, trans));
                    }
                }

                var incoming = new List<Pair<DirectedWeightedNode<GameState, GameStateTransition>, GameStateTransition>>();
                foreach (var t in from)
                {
                    var node = GameStateGraph.Nodes.FirstOrDefault(n => n.Data.Name == t.Item1);

                    if (node != null)
                    {
                        var trans = t.Item2 ?? GameStateTransition.DefaultTransition;
                        incoming.Add(
                            new Pair<DirectedWeightedNode<GameState, GameStateTransition>, GameStateTransition>(
                                node, trans));
                    }
                }

                GameStateGraph.AddNode(gameState, outgoing, incoming);
            }
            else
            {
                Logger.Log.AddLogEntry(LogLevel.Severe, ClassName, Status.UnreachableLineReached);
                return false;
            }

            return true;
        }
Ejemplo n.º 23
0
        public void SwitchGameState(GameState source, GameState dest, FreezingArcher.Content.Game game)
        {
            GameState = dest;

            inventory.SwitchItemsToGameState (source, dest, game);
        }
Ejemplo n.º 24
0
        void AddAudio(GameState state)
        {
            //Load walking sound
            Audio.Source src = application.AudioManager.GetSource("footstep_SoundSource");

            if (src == null)
            {
                application.AudioManager.LoadSound ("footstep_Sound", "Content/Audio/footstep.ogg");
                src = application.AudioManager.CreateSource ("footstep_SoundSource", "footstep_Sound");
            }

            src.Gain = 0.5f;
            src.Loop = false;

            state.AudioContext.RegisterSoundPlaybackOnMessage (MessageId.PlayerMove,
                new SoundSourceDescription (src, SoundAction.Play, Player));

            state.AudioContext.RegisterSoundPlaybackOnMessage (MessageId.PlayerRun,
                new SoundSourceDescription (src, SoundAction.Stop, Player));

            //Load running sound
            src = application.AudioManager.GetSource("footstep_run_SoundSource");

            if (src == null)
            {
                application.AudioManager.LoadSound ("footstep_run_Sound", "Content/Audio/footstep_run.ogg");
                src = application.AudioManager.CreateSource ("footstep_run_SoundSource", "footstep_run_Sound");
            }

            src.Loop = false;
            src.Gain = 0.5f;

            state.AudioContext.RegisterSoundPlaybackOnMessage (MessageId.PlayerRun, 
                new SoundSourceDescription (src, SoundAction.Play, Player));

            state.AudioContext.RegisterSoundPlaybackOnMessage (MessageId.PlayerMove,
                new SoundSourceDescription (src, SoundAction.Stop, Player));

            //Load jump sound
            src = application.AudioManager.GetSource("player_jump_SoundSource");

            if (src == null)
            {
                application.AudioManager.LoadSound ("player_jump_Sound", "Content/Audio/player_jumped.ogg");
                src = application.AudioManager.CreateSource ("player_jump_SoundSource", "player_jump_Sound");
            }

            src.Gain = 0.5f;
            src.Loop = false;

            state.AudioContext.RegisterSoundPlaybackOnMessage (MessageId.PlayerJump,
                new SoundSourceDescription (src, SoundAction.Play, Player));

            //Set listener Position from PlayerPosition
            TransformComponent tfc = Player.GetComponent<TransformComponent>();
            tfc.OnPositionChanged += (Vector3 obj) => application.AudioManager.Listener.Position = obj;

            //Item collect sound
            src = application.AudioManager.GetSource("item_collected_SoundSource");

            if (src == null)
            {
                application.AudioManager.LoadSound ("item_collected_Sound", "Content/Audio/item_collected.ogg");
                src = application.AudioManager.CreateSource ("item_collected_SoundSource", "item_collected_Sound");
            }

            src.Gain = 0.25f;
            src.Loop = false;

            state.AudioContext.RegisterSoundPlaybackOnMessage(MessageId.ItemCollected,
                new SoundSourceDescription(src, SoundAction.Play, Player));

            //Item dropped sound
            src = application.AudioManager.GetSource("item_dropped_SoundSource");

            if (src == null)
            {
                application.AudioManager.LoadSound ("item_dropped_Sound", "Content/Audio/item_dropped.ogg");
                src = application.AudioManager.CreateSource ("item_dropped_SoundSource", "item_dropped_Sound");
            }

            src.Gain = 0.5f;
            src.Loop = false;

            state.AudioContext.RegisterSoundPlaybackOnMessage(MessageId.ItemDropped,
                new SoundSourceDescription(src, SoundAction.Play, Player));

            //Wall moving sound
            src = application.AudioManager.GetSource("moving_wall_SoundSource");

            if (state.Name != "maze_underworld")
            {
                if (src == null)
                {
                    application.AudioManager.LoadSound ("moving_wall_Sound", "Content/Audio/moving_wall.ogg");
                    src = application.AudioManager.CreateSource ("moving_wall_SoundSource", "moving_wall_Sound");
                }

                src.Gain = 0.5f;
                src.Loop = false;
            }
            else
            {
                src = application.AudioManager.GetSource ("moving_wall_wood_SoundSource");

                if (src == null)
                {
                    //application.AudioManager.LoadSound ("moving_wall_Sound", "Content/Audio/moving_wall.ogg");
                    application.AudioManager.LoadSound ("moving_wall_wood_Sound", "Content/Audio/moving_wall_wood.ogg");

                    src = application.AudioManager.CreateSource ("moving_wall_wood_SoundSource", "moving_wall_wood_Sound");
                }

                src.Gain = 0.5f;
                src.Loop = false;
            }

            state.AudioContext.RegisterSoundPlaybackOnMessage(MessageId.BeginWallMovement,
                new SoundSourceDescription(src, SoundAction.Play));

            //Stop wall moving sound on stop
            state.AudioContext.RegisterSoundPlaybackOnMessage (MessageId.EndWallMovement,
                new SoundSourceDescription (src, SoundAction.Stop));
        }
Ejemplo n.º 25
0
        public static ItemComponent CreateNewItem(MessageProvider messageProvider, GameState state,
            string name, string imageLocation, string description,
            string modelPath, Vector2i size, Vector3 offset, Quaternion rotation, Shape shape, ItemLocation location,
            AttackClass attackClasses, ItemUsage itemUsages, Protection protection, Material physicsMaterial,
            float mass, float healthDelta, float usageDeltaPerUsage, float attackStrength, float throwPower, float usage)
        {
            var entity = EntityFactory.Instance.CreateWith(name, messageProvider,
                systems: new[] { typeof(ItemSystem), typeof(ModelSystem), typeof(PhysicsSystem) });

            var item = entity.GetComponent<ItemComponent>();
            item.ImageLocation = imageLocation;
            item.Description = description;
            item.Size = size;
            item.Location = location;
            item.AttackClasses = attackClasses;
            item.ItemUsages = itemUsages;
            item.Protection = protection;
            item.HealthDelta = healthDelta;
            item.AttackStrength = attackStrength;
            item.ThrowPower = throwPower;
            item.Usage = usage;
            item.UsageDeltaPerUsage = usageDeltaPerUsage;
            item.Mass = mass;
            item.PhysicsMaterial = physicsMaterial;
            item.PositionOffset = offset;
            item.Rotation = rotation;
            item.ItemUsageHandler = new MazeItemUseHandler();

            var model = new ModelSceneObject(modelPath);
            model.Enabled = true;
            state.Scene.AddObject(model);
            entity.GetComponent<ModelComponent>().Model = model;

            var transform = entity.GetComponent<TransformComponent>();
            var physics = entity.GetComponent<PhysicsComponent> ();

            if (shape == null)
            {
                List<JVector> vertices = new List<JVector>();
                model.Model.Meshes[0].Vertices.ForEach(x => vertices.Add(x.ToJitterVector()));

                List<TriangleVertexIndices> indices = new List<TriangleVertexIndices>();

                for(int i = 0; i < model.Model.Meshes[0].Indices.Length; i+= 3)
                {
                    int i0 = model.Model.Meshes[0].Indices[i+0];
                    int i1 = model.Model.Meshes[0].Indices[i+1];
                    int i2 = model.Model.Meshes[0].Indices[i+2];

                    indices.Add(new TriangleVertexIndices(i0, i1, i2));
                }

                shape = new TriangleMeshShape(new Octree(vertices, indices));
            }

            var body = new RigidBody(shape);
            body.Position = transform.Position.ToJitterVector ();
            if (mass >= 0)
                body.Mass = mass;
            body.Material = physicsMaterial;
            body.AllowDeactivation = true;
            body.Tag = entity;

            state.PhysicsManager.World.AddBody(body);
            physics.RigidBody = body;
            physics.World = state.PhysicsManager.World;
            physics.PhysicsApplying = AffectedByPhysics.Orientation | AffectedByPhysics.Position;
            physics.RigidBody.IsStatic = false;
            physics.RigidBody.IsActive = false;
            physics.RigidBody.Position = transform.Position.ToJitterVector();
            model.Position = transform.Position;

            return item;
        }