Inheritance: Entity, IHasModel
Exemplo n.º 1
0
        public static Entity Clone(Entity entity)
        {
            Entity clone = null;

            if (entity is StaticModelEntity)
            {
                StaticModelEntity modelentity = entity as StaticModelEntity;
                clone = new StaticModelEntity(modelentity.GetModel());
            }

            if (entity is WallModelEntity)
            {
                WallModelEntity wallentity = entity as WallModelEntity;
                clone = new WallModelEntity(wallentity.GetModel());
            }

            if (entity is AnimatedModelEntity)
            {
                AnimatedModelEntity modelentity = entity as AnimatedModelEntity;
                clone = new AnimatedModelEntity(modelentity.GetModel());
            }

            if (entity is Billboard)
            {
                Billboard billboard = entity as Billboard;
                clone = new Billboard(billboard.region);
            }

            if (clone != null)
            {
                CopyFrom(entity, clone);
            }

            return(clone);
        }
Exemplo n.º 2
0
        public static Entity Clone(Entity entity)
        {
            Entity clone = null;

            if (entity is StaticModelEntity)
            {
                StaticModelEntity modelentity = entity as StaticModelEntity;
                clone = new StaticModelEntity(modelentity.GetModel());
            }

            if (entity is WallModelEntity)
            {
                WallModelEntity wallentity = entity as WallModelEntity;
                clone = new WallModelEntity(wallentity.GetModel());
            }

            if (entity is AnimatedModelEntity)
            {
                AnimatedModelEntity modelentity = entity as AnimatedModelEntity;
                clone = new AnimatedModelEntity(modelentity.GetModel());
            }

            if (entity is Billboard)
            {
                Billboard billboard = entity as Billboard;
                clone = new Billboard(billboard.region);
            }

            if (clone != null)
                CopyFrom(entity, clone);

            return clone;
        }
Exemplo n.º 3
0
        public void Load()
        {
            entities.Clear();

            XmlLevel xmllevel = XmlHelper.Load(id);
            List<XmlEntity> xmlentities = xmllevel.entities;

            for (int i = 0; i < xmlentities.Count; i++)
            {
                XmlEntity xmlentity = xmlentities[i];
                Entity entity = null;

                if (xmlentity.type == "static_model")
                {
                    Model model = (Model)Resources.GetObject(xmlentity.asset);
                    entity = new StaticModelEntity(model);
                }

                if (xmlentity.type == "animated_model")
                {
                    Model model = (Model)Resources.GetObject(xmlentity.asset);
                    entity = new AnimatedModelEntity(model);
                }

                if (xmlentity.type == "wall_model")
                {
                    Model model = (Model)Resources.GetObject(xmlentity.asset);
                    entity = new WallModelEntity(model);
                }

                if (xmlentity.type == "billboard")
                {
                    Texture2D texture = (Texture2D)Resources.GetObject(xmlentity.asset);
                    entity = new Billboard(texture);
                    ((Billboard)entity).color = xmlentity.color;
                }

                if (entity == null)
                    continue;

                entity.position = xmlentity.position;
                entity.rotation = xmlentity.rotation;
                entity.size = xmlentity.size;

                Add(entity);
            }
        }
Exemplo n.º 4
0
        public void Update(double elapsed)
        {
            camera.Update(elapsed);
            player.Update(elapsed);
            //level.Update(elapsed);

            // get camera ray
            Vector3 direction = camera.target - camera.position;
            direction.Normalize();
            Ray camera_ray = new Ray(camera.position, direction);

            bool unrestricted = player is UnrestrictedPlayer;

            // move camera in and out
            if (input.IsDown(Buttons.DPadDown))
                player.position.Z += (float)elapsed * 50;
            if (input.IsDown(Buttons.DPadUp))
                player.position.Z -= (float)elapsed * 50;

            // switch layers
            if (input.IsPressed(Buttons.RightShoulder))
                curr_depth_index++;
            curr_depth_index %= depth_values.Length;

            // get next asset
            if (input.IsPressed(Buttons.LeftShoulder))
            {
                object asset = asset_list[curr_asset_index];
                curr_entity = CreateFromAsset(asset);

                curr_asset_index++;
            }
            curr_asset_index %= asset_list.Count;

            if (curr_entity != null)
            {
                // randomize rotation
                if (input.IsPressed(Buttons.Y))
                {
                    curr_entity.rotation.X = (float)rand.NextDouble() * MathHelper.TwoPi;
                    curr_entity.rotation.Y = (float)rand.NextDouble() * MathHelper.TwoPi;
                    curr_entity.rotation.Z = (float)rand.NextDouble() * MathHelper.TwoPi;
                }

                // rotate
                if (!unrestricted)
                {
                    curr_entity.rotation.X += (float)(input.RightThumbStick.Y * elapsed);
                    curr_entity.rotation.Z += (float)(input.RightThumbStick.X * elapsed);
                }

                // scale
                curr_entity.size *= 1 + (float)(input.RightTrigger * elapsed);
                curr_entity.size *= 1 - (float)(input.LeftTrigger * elapsed);

                // position
                Vector3 position = player.position;
                Plane p = new Plane(0, 0, -1, depth_values[curr_depth_index]);
                float? distance = camera_ray.Intersects(p);
                if (distance != null)
                    position = camera.position + camera_ray.Direction * (float)distance;

                curr_entity.position.X = position.X;
                curr_entity.position.Y = position.Y;
                curr_entity.position.Z = depth_values[curr_depth_index];

                if(curr_entity is AnimatedModelEntity)
                    curr_entity.Update(elapsed);

                // place entity
                if (input.IsPressed(Buttons.A))
                {
                    Entity clone;

                    if (use_walls && curr_entity is StaticModelEntity)
                    {
                        clone = new WallModelEntity((curr_entity as IHasModel).GetModel());
                        Entity.CopyFrom(curr_entity, clone);
                    }
                    else
                    {
                        clone = Entity.Clone(curr_entity);
                    }

                    level.Add(clone);
                }
            }
            else
            {
                if (input.IsPressed(Buttons.A))
                {
                    curr_entity = level.GetEntityAt(camera_ray, depth_values[curr_depth_index]);

                    if (curr_entity != null)
                        level.Remove(curr_entity);
                }
            }

            if (input.IsPressed(Buttons.B))
            {
                curr_entity = null;
            }

            if (input.IsPressed(Buttons.X))
            {
                use_walls = !use_walls;
            }
        }