public override void OnAttached(AbstractEntity entity)
        {
            this.iceSpike  = entity as Entity;
            this.constants = Game.Instance.Simulation.EntityManager["player_constants"];
            this.templates = Game.Instance.ContentManager.Load <LevelData>("Level/Common/DynamicTemplates");

            entity.GetProperty <CollisionProperty>("collision").OnContact += IceSpikeCollisionHandler;

            string targetPlayerName = entity.GetString("target_player");

            if (targetPlayerName != "")
            {
                targetPlayer = Game.Instance.Simulation.EntityManager[targetPlayerName];
                Game.Instance.Simulation.EntityManager.EntityRemoved += OnEntityRemoved;
            }
            else
            {
                targetPlayer = null;
            }

            shootingPlayer = Game.Instance.Simulation.EntityManager[entity.GetString("player")];

            createdAt = Game.Instance.Simulation.Time.At;

            (entity as Entity).OnUpdate += OnUpdate;
        }
示例#2
0
        public override void OnAttached(
            AbstractEntity entity
            )
        {
            bool needAllContacts = entity.HasBool("need_all_contacts") && entity.GetBool("need_all_contacts");

            string modelName = entity.GetString(CommonNames.Mesh);

            VolumeCollection[] collisionVolumes = Game.Instance.ContentManager.Load <MagmaModel>(modelName).VolumeCollection;
            if (collisionVolumes == null)
            {
                throw new System.Exception(string.Format("model {0} has no collision volumes!", modelName));
            }

            if (entity.HasString("bv_type"))
            {
                string bv_type = entity.GetString("bv_type");
                if (bv_type == "cylinder")
                {
                    object[] bvCylinders = new object[collisionVolumes.Length];
                    for (int i = 0; i < collisionVolumes.Length; ++i)
                    {
                        bvCylinders[i] = collisionVolumes[i].GetVolume(VolumeType.Cylinder3);
                    }
                    Game.Instance.Simulation.CollisionManager.AddCylinderCollisionEntity(entity as Entity, this, bvCylinders, needAllContacts);
                }
                else if (bv_type == "alignedbox3tree")
                {
                    object[] bvTrees = new object[collisionVolumes.Length];
                    for (int i = 0; i < collisionVolumes.Length; ++i)
                    {
                        bvTrees[i] = collisionVolumes[i].GetVolume(VolumeType.AlignedBox3Tree);
                    }
                    Game.Instance.Simulation.CollisionManager.AddAlignedBox3TreeCollisionEntity(entity as Entity, this, bvTrees, needAllContacts);
                }
                else if (bv_type == "sphere")
                {
                    object[] bvSpheres = new object[collisionVolumes.Length];
                    for (int i = 0; i < collisionVolumes.Length; ++i)
                    {
                        bvSpheres[i] = collisionVolumes[i].GetVolume(VolumeType.Sphere3);
                    }
                    Game.Instance.Simulation.CollisionManager.AddSphereCollisionEntity(entity as Entity, this, bvSpheres, needAllContacts);
                }
                else if (bv_type == "alignedbox3")
                {
                    AlignedBox3[] bvBoxes = new AlignedBox3[collisionVolumes.Length];
                    for (int i = 0; i < collisionVolumes.Length; ++i)
                    {
                        bvBoxes[i] = (AlignedBox3)collisionVolumes[i].GetVolume(VolumeType.AlignedBox3);
                    }
                    throw new System.Exception("bounding boxes not yet supported!");
                }
            }
        }
示例#3
0
        public override void OnAttached(
            AbstractEntity entity
            )
        {
            decoration = entity as Entity;
            attachedTo = Game.Instance.Simulation.EntityManager[entity.GetString(CommonNames.AttachedTo)];

            Debug.Assert(decoration.HasString(CommonNames.AttachmentPoint), "must specify to which point this entity is to be attached");
            attachmentPointName = decoration.GetString(CommonNames.AttachmentPoint);

            Debug.Assert(attachedTo.HasVector3(attachmentPointName), "attachedTo must have the attachment point desired.");
            if (!attachedTo.HasVector3(attachmentPointName))
            {
                throw new Exception(string.Format("attachedTo {0} is missing the attachment point '{1}'", attachedTo.Name, attachmentPointName));
            }

            attachedTo.GetVector3Attribute(CommonNames.Position).ValueChanged += OnAttachedToPositionChanged;

            // initialize properties
            if (!decoration.HasAttribute(CommonNames.Position))
            {
                decoration.AddVector3Attribute(CommonNames.Position, Vector3.Zero);
            }

            Vector3 islandPos = attachedTo.GetVector3(CommonNames.Position);

            PositionOnIsland(ref islandPos);
        }
示例#4
0
        public override void OnAttached(
            AbstractEntity entity
            )
        {
            this.powerup   = entity as Entity;
            this.constants = Game.Instance.Simulation.EntityManager["powerup_constants"];
            this.island    = Game.Instance.Simulation.EntityManager[entity.GetString("island_reference")];

            rand = new Random(island.GetHashCode());

            // initialize properties
            Debug.Assert(this.powerup.HasVector3("relative_position"), "must have a relative translation attribute");
            if (!this.powerup.HasAttribute(CommonNames.Position))
            {
                this.powerup.AddVector3Attribute(CommonNames.Position, Vector3.Zero);
            }

            Debug.Assert(powerup.HasBool("fixed"));

            // get position on surface
            powerup.AddFloatAttribute("surface_offset", 0f);
            CalculateSurfaceOffset();
            Vector3 islandPos = island.GetVector3(CommonNames.Position);

            PositionOnIsland(ref islandPos);

            // add timeout respawn attribute
            this.powerup.AddFloatAttribute("respawn_at", 0);

            // register handlers
            this.island.GetVector3Attribute(CommonNames.Position).ValueChanged += OnIslandPositionChanged;
            entity.GetProperty <CollisionProperty>("collision").OnContact      += PowerupCollisionHandler;

            powerup.OnUpdate += OnUpdate;
        }
        public override void OnAttached(AbstractEntity light)
        {
            this.light  = light as Entity;
            this.island = Game.Instance.Simulation.EntityManager[light.GetString("island")];

            // register island change handler
            island.GetVector3Attribute(CommonNames.Position).ValueChanged += OnIslandPositionChanged;

            positionOffset = light.GetVector3(CommonNames.Position) - island.GetVector3(CommonNames.Position);

//            (light as Entity).Update += OnUpdate;
        }
        public override void OnAttached(AbstractEntity entity)
        {
            base.OnAttached(entity);

            if (!entity.HasAttribute("pillar"))
            {
                entity.AddStringAttribute("pillar", "");
                AssignPillar(entity as Entity);
            }
            else
            {
                pillar = Game.Instance.Simulation.EntityManager[entity.GetString("pillar")];

                // get radius
                Vector3 radiusV = (island.GetVector3(CommonNames.Position) - pillar.GetVector3(CommonNames.Position));
                radiusV.Y = 0;
                radius    = radiusV.Length();
            }
        }
示例#7
0
        public override void OnAttached(AbstractEntity entity)
        {
            Debug.Assert(entity.HasAttribute(CommonNames.Kind) && entity.GetString(CommonNames.Kind) == "player");

            base.OnAttached(entity);

            Entity playerConstants = Game.Instance.Simulation.EntityManager["player_constants"];

            if (entity.HasString(CommonNames.PlayerName))
            {
                entity.GetStringAttribute(CommonNames.PlayerName).ValueChanged += PlayerNameChanged;
            }
            if (entity.HasInt(CommonNames.GamePadIndex))
            {
                entity.GetIntAttribute(CommonNames.GamePadIndex).ValueChanged += GamePadIndexChanged;
            }
            if (entity.HasFloat(CommonNames.Health))
            {
                entity.GetFloatAttribute(CommonNames.Health).ValueChanged += HealthChanged;
            }
            if (playerConstants.HasFloat(CommonNames.MaxHealth))
            {
                playerConstants.GetFloatAttribute(CommonNames.MaxHealth).ValueChanged += MaxHealthChanged;
            }
            if (entity.HasFloat(CommonNames.Energy))
            {
                entity.GetFloatAttribute(CommonNames.Energy).ValueChanged += EnergyChanged;
            }
            if (playerConstants.HasFloat(CommonNames.MaxEnergy))
            {
                playerConstants.GetFloatAttribute(CommonNames.MaxEnergy).ValueChanged += MaxEnergyChanged;
            }
            if (entity.HasInt(CommonNames.Frozen))
            {
                entity.GetIntAttribute(CommonNames.Frozen).ValueChanged += FrozenChanged;
            }
            entity.GetIntAttribute(CommonNames.Lives).ValueChanged += LivesChanged;

            Game.Instance.Simulation.CurrentUpdateQueue.AddUpdate(new AddRenderableUpdate((Renderable)Updatable));
        }