Example #1
0
 /// <summary>
 /// Creates the skybox.
 /// </summary>
 /// <param name="scene">Scene.</param>
 /// <param name="path">Path to skybox xml.</param>
 public static void CreateSkybox(CoreScene scene, Entity player,
     string path = "lib/Renderer/TestGraphics/Skybox/skybox.xml")
 {
     ModelSceneObject skyboxModel = new ModelSceneObject (path);
     skyboxModel.Priority = 0;
     skyboxModel.Scaling = 50.0f * Vector3.One;
     scene.AddObject (skyboxModel);
     skyboxModel.Model.EnableDepthTest = false;
     skyboxModel.NoLighting = true;
     player.GetComponent<SkyboxComponent> ().Skybox = skyboxModel;
 }
Example #2
0
        public RoachGroup (CoreScene scene)
        {
            Roaches = new ModelSceneObject[5];
            offset = new Vector3[Roaches.Length];

            for (int i = 0; i < Roaches.Length; i++)
            {
                Roaches[i] = new ModelSceneObject ("lib/Renderer/TestGraphics/Roach/roach.xml");
                scene.AddObject(Roaches[i]);
            }

            offset[0] = new Vector3(1 , 0, 1    ) / 10;
            offset[1] = new Vector3(-2, 0, 1    ) / 10;
            offset[2] = new Vector3(2 , 0, 0    ) / 10;
            offset[3] = new Vector3(0 , 0, 1    ) / 10;
            offset[4] = new Vector3(-2, 0, -1.5f) / 10;
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FreezingArcher.Game.ECSTest"/> class.
        /// </summary>
        /// <param name="messageProvider">The message provider for this instance.</param>
        /// <param name="scene">Scene.</param>
        public ECSTest (MessageProvider messageProvider, CoreScene scene)
        {
            Entity player = EntityFactory.Instance.CreateWith ("player", messageProvider, systems: new[] {
                typeof (MovementSystem),
                typeof (KeyboardControllerSystem),
                typeof (MouseControllerSystem)
            });

            scene.CameraManager.AddCamera (new BaseCamera (player, messageProvider), "player");

            Entity skybox = EntityFactory.Instance.CreateWith ("skybox", messageProvider, systems: new[] { typeof(ModelSystem) });
            ModelSceneObject skyboxModel = new ModelSceneObject ("lib/Renderer/TestGraphics/Skybox/skybox.xml");
            skybox.GetComponent<TransformComponent>().Scale = 100.0f * Vector3.One;
            scene.AddObject (skyboxModel);
            skyboxModel.WaitTillInitialized ();
            skyboxModel.Model.EnableDepthTest = false;
            skyboxModel.Model.EnableLighting = false;
            skybox.GetComponent<ModelComponent> ().Model = skyboxModel;
            // as we do not update skybox position the player is able to leave the skybox ... i dont wanna fix it cause its just a test...
        }
Example #4
0
        public Entity ProcessAndAddCell (MazeCell cell, Vector3 worldPosition, Vector2i gridPosition, uint sizex, uint sizey)
        {
            Entity entity = null;
            if (cell.MazeCellType == MazeCellType.Ground)
            {
                entity = EntityFactory.Instance.CreateWith ("ground" + gridPosition.X + "." + gridPosition.Y,
                    state.MessageProxy, systems: systems);
                var model = new ModelSceneObject ("lib/Renderer/TestGraphics/Ground/ground.xml");
                entity.GetComponent<ModelComponent>().Model = model;

                scnobjarr_ground.AddObject (model);
                //state.Scene.AddObject(model);

                var transform = entity.GetComponent<TransformComponent>();
                transform.Position = worldPosition;
                transform.Scale = scale;

                var body = new RigidBody (new BoxShape (2.0f * scale.X, 0.2f, 2.0f * scale.Y));
                body.Position = new JVector(transform.Position.X, transform.Position.Y - 0.1f, transform.Position.Z);
                body.Material.Restitution = -10;
                body.IsStatic = true;
                body.Tag = cell;

                entity.GetComponent<PhysicsComponent> ().RigidBody = body;
                entity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
                entity.GetComponent<PhysicsComponent> ().PhysicsApplying =
                    AffectedByPhysics.Orientation | AffectedByPhysics.Position;
                
                state.PhysicsManager.World.AddBody (body);

                if (cell.IsExit)
                {
                    var exitEntity = EntityFactory.Instance.CreateWith ("overworld_exit", state.MessageProxy,
                                         systems: systems);

                    var exitModel = new ModelSceneObject ("lib/Renderer/TestGraphics/OverworldExit/overworld_exit.xml");
                    exitEntity.GetComponent<ModelComponent> ().Model = exitModel;
                    state.Scene.AddObject (exitModel);

                    var exitTransform = exitEntity.GetComponent<TransformComponent> ();
                    exitTransform.Position = new Vector3 (worldPosition.X, -.5f, worldPosition.Z);
                    exitTransform.Scale = scale;

                    if (cell.Position.Y == 0)
                    {
                        exitTransform.Rotation = Quaternion.FromAxisAngle (Vector3.UnitY, MathHelper.ThreePiOver2);
                    }
                    else
                    if (cell.Position.X == (sizex - 1))
                    {
                        exitTransform.Rotation = Quaternion.FromAxisAngle (Vector3.UnitY, MathHelper.Pi);
                    }
                    else
                    if (cell.Position.Y == (sizey - 1))
                    {
                        exitTransform.Rotation = Quaternion.FromAxisAngle (Vector3.UnitY, MathHelper.PiOver2);
                    }

                    var exitBody = new RigidBody (new BoxShape (scale.X * 2, scale.Y * 4, scale.Z * 2));
                    exitBody.Position = exitTransform.Position.ToJitterVector () + JVector.Up * (scale.Y * 2);
                    exitBody.Orientation = JMatrix.CreateFromQuaternion (exitTransform.Rotation.ToJitterQuaternion ());
                    exitBody.Material.Restitution = -10;
                    exitBody.IsStatic = true;
                    exitBody.Tag = exitEntity;

                    exitEntity.GetComponent<PhysicsComponent> ().RigidBody = exitBody;
                    exitEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
                    exitEntity.GetComponent<PhysicsComponent> ().PhysicsApplying =
                        AffectedByPhysics.Orientation | AffectedByPhysics.Position;

                    state.PhysicsManager.World.AddBody (exitBody);

                    exitEntity.Suspend();
                }
                entity.Suspend();
            }
            else if (cell.MazeCellType == MazeCellType.Wall)
            {
                entity = EntityFactory.Instance.CreateWith ("wall" + gridPosition.X + "." + gridPosition.Y,
                    state.MessageProxy, new[] { typeof (HealthComponent), typeof(WallComponent) }, systems);
                var model = new ModelSceneObject ("lib/Renderer/TestGraphics/Wall/wall.xml");
                entity.GetComponent<ModelComponent>().Model = model;

                scnobjarr_wall.AddObject (model);
                //state.Scene.AddObject(model);

                var transform = entity.GetComponent<TransformComponent>();
                transform.Position = new Vector3 (worldPosition.X, -0.5f, worldPosition.Z);
                transform.Rotation = cell.Rotation;
                transform.Scale = scale;

                var body = new RigidBody (new BoxShape (scale.X * 2, scale.Y * 4, scale.Z * 2));
                body.Position = transform.Position.ToJitterVector () + JVector.Up * (scale.Y * 2);
                body.Material.Restitution = -10;
                body.IsStatic = true;
                body.Tag = entity;

                entity.GetComponent<PhysicsComponent> ().RigidBody = body;
                entity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
                entity.GetComponent<PhysicsComponent> ().PhysicsApplying =
                    AffectedByPhysics.Orientation | AffectedByPhysics.Position;

                entity.GetComponent<WallComponent>().IsEdge = cell.IsEdge;
                entity.GetComponent<WallComponent>().IsOverworld = true;

                state.PhysicsManager.World.AddBody (body);

                entity.Suspend();
            }

            return entity;
        }
Example #5
0
        public override SceneObject Clone()
        {
            ModelSceneObject msobj = new ModelSceneObject(ModelPath, false);

            //Delegate[] bla = this.SceneObjectChanged.GetInvocationList();

            //for (int i = 0; i < bla.Length; i++)
            //    msobj.SceneObjectChanged += bla[i];
                
            msobj.Scaling = this.Scaling;
            msobj.Rotation = this.Rotation;
            msobj.Position = this.Position;
            msobj.MyModel = this.MyModel;
            msobj.LoadModel = false;

            return msobj;
        }
Example #6
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;
        }
Example #7
0
        void AnimateMovement(WeightedNode<MazeCell, MazeCellEdgeWeight> groundNode,
            WeightedNode<MazeCell, MazeCellEdgeWeight> wallNode,
            WeightedNode<MazeCell, MazeCellEdgeWeight> connection)
        {
            var ground1 = Maze.entities[groundNode.Data.Position.X, groundNode.Data.Position.Y];
            var wall = Maze.entities[wallNode.Data.Position.X, wallNode.Data.Position.Y];

            var old_pos = ground1.GetComponent<TransformComponent>().Position;
            var wall_transform = wall.GetComponent<TransformComponent>();
            wall.GetComponent<WallComponent>().IsMoving = true;
            var new_ground_position = new Vector3 (wall_transform.Position.X, 0, wall_transform.Position.Z);

            var ground2 = EntityFactory.Instance.CreateWith ("ground_temp" + temp_counter++, GameState.MessageProxy,
                systems: new[] { typeof (ModelSystem), typeof (PhysicsSystem) });

            var ground2_model = new ModelSceneObject ("lib/Renderer/TestGraphics/Ground/ground.xml");
            ground2.GetComponent<ModelComponent>().Model = ground2_model;
            var transform = ground2.GetComponent<TransformComponent>();
            transform.Position = old_pos;
            transform.Scale = ground1.GetComponent<TransformComponent>().Scale;
            ground2_model.Position = transform.Position;
            var body = new RigidBody(new BoxShape (2.0f * transform.Scale.X, 0.2f, 2.0f * transform.Scale.Y));
            body.Position = transform.Position.ToJitterVector ();
            body.Material.Restitution = -10;
            body.IsStatic = true;
            ground2.GetComponent<PhysicsComponent>().RigidBody = body;
            ground2.GetComponent<PhysicsComponent>().World = GameState.PhysicsManager.World;
            ground2.GetComponent<PhysicsComponent>().PhysicsApplying =
                AffectedByPhysics.Orientation | AffectedByPhysics.Position;

            GameState.PhysicsManager.World.AddBody (body);
            GameState.Scene.AddObject(ground2_model);

            ground1.GetComponent<TransformComponent>().Position = new_ground_position;
            ground1.GetComponent<PhysicsComponent>().RigidBody.Position = new_ground_position.ToJitterVector();

            var position = old_pos;
            position = new Vector3 (position.X, -0.5f, position.Z);

            Maze.entities[wallNode.Data.Position.X, wallNode.Data.Position.Y] = ground1;
            Maze.entities[groundNode.Data.Position.X, groundNode.Data.Position.Y] = wall;

            var tmp_wall_position = Maze.entities[connection.Data.Position.X, connection.Data.Position.Y]
                .GetComponent<TransformComponent>().Position;
            tmp_wall_position = new Vector3 (tmp_wall_position.X, -0.5f, tmp_wall_position.Z);

            wall.WakeUp();

            MoveEntityTo (wall, tmp_wall_position, position, () => {
                GameState.Scene.RemoveObject(ground2_model);
                wall.GetComponent<WallComponent>().IsMoving = false;
                wall.Suspend();
                ground2.Destroy(); if(MessageCreated != null) MessageCreated(new EndWallMovementMessage(wall));
            });
        }
Example #8
0
 public override void Destroy()
 {
     Model.Dispose();
     Model = null;
     base.Destroy();
 }