Esempio n. 1
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            TextureOnName = section["textureOn"];
            TextureOffName = section["textureOff"];

            section.IfOptionExists("onActivate",
                opt => EventActivate = Game.Events[opt]);

            section.IfOptionExists("onActivateData",
                opt => EventActivateData = opt);
        }
Esempio n. 2
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            TextureName = section["texture"];
            _dimensions = section["dimensions"].AsVector2();
            section.IfOptionExists("toggleEvent",
                opt => Game.Events[opt].addListener(onToggleEvent));

            section.IfOptionExists("fadeTime", opt => FadeTime = opt);

            var stateName = section["state"];

            if (stateName == "active")
            {
                State.setActive();
                CurrentFadeTime = FadeTime;
            }
            else if (stateName == "inactive")
            {
                State.setInactive();
                CurrentFadeTime = 0.0f;
            }
            else
            {
                throw new ArgumentException("Unsupported GameObject state: " + stateName);
            }

            section.IfOptionExists("movementSpeed", opt => MovementSpeed = opt);

            section.IfOptionExists("toggleWaypointEvent", opt => Game.Events[opt].addListener(onToggleWaypointEvent));

            var bodyDescription = new scBodyDescription();
            bodyDescription.userData = this;
            var bodyPartDescription = new scBodyPartDescription();
            var shape = scRectangleShape.fromLocalPositionAndHalfExtents(Vector2.Zero, _dimensions / 2);
            bodyPartDescription.shape = shape;
            bodyDescription.transform.position = section["position"].AsVector2();
            Body = Game.level.World.createBody(bodyDescription, bodyPartDescription);
            Body.owner = this;

            section.IfOptionExists("waypointStart",
                opt => WaypointStart = opt.AsVector2(),
                () => WaypointStart = Pos);

            section.IfOptionExists("waypointEnd",
                opt => WaypointEnd = opt.AsVector2(),
                () => WaypointEnd = Pos);

            section.IfOptionExists("target",
                targetName =>
                {
                    if (targetName == "start")
                    {
                        _targetIndex.Value = 0;
                    }
                    else if (targetName == "end")
                    {
                        _targetIndex.Value = 1;
                    }
                    else
                    {
                        throw new ArgumentException("Unsupported target name: " + targetName);
                    }
                },
                () => _targetIndex.Value = 1);
        }
Esempio n. 3
0
 public virtual void Initialize(ConfigSection section)
 {
     section.IfOptionExists("name", opt => Name = opt);
     section.IfOptionExists("drawOrder", opt => DrawOrder = opt);
 }
Esempio n. 4
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            TextureName = section["texture"];
            _dimensions = section["dimensions"].AsVector2();
            section.IfOptionExists("toggleEvent",
                opt => Game.Events[opt].addListener(onToggleEvent));

            section.IfOptionExists("fadeTime", opt => FadeTime = opt);

            var stateName = section["state"];

            if (stateName == "active")
            {
                State.setActive();
                CurrentFadeTime = FadeTime;
            }
            else if (stateName == "inactive")
            {
                State.setInactive();
                CurrentFadeTime = 0.0f;
            }
            else
            {
                throw new ArgumentException("Unsupported GameObject state: " + stateName);
            }

            section.IfOptionExists("movementSpeed", opt => MovementSpeed = opt);

            section.IfOptionExists("toggleWaypointEvent", opt => Game.Events[opt].addListener(onToggleWaypointEvent));

            var bodyDef = new BodyDef();
            var fixtureDef = new FixtureDef();
            var shape = new PolygonShape();
            shape.SetAsBox(Game.level.ConvertToBox2D(Dimensions.X / 2), Game.level.ConvertToBox2D(Dimensions.Y / 2));
            fixtureDef.shape = shape;
            fixtureDef.userData = new LevelElementInfo() { type = LevelElementType.Ground };
            bodyDef.type = BodyType.Kinematic;
            bodyDef.position = Game.level.ConvertToBox2D(section["position"].AsVector2());
            bodyDef.active = State.IsActive;
            Body = Game.level.World.CreateBody(bodyDef);
            Body.CreateFixture(fixtureDef);

            section.IfOptionExists("waypointStart",
                opt => WaypointStart = opt.AsVector2(),
                () => WaypointStart = Pos);

            section.IfOptionExists("waypointEnd",
                opt => WaypointEnd = opt.AsVector2(),
                () => WaypointEnd = Pos);

            section.IfOptionExists("target",
                targetName =>
                {
                    if (targetName == "start")
                    {
                        _targetIndex.Value = 0;
                    }
                    else if (targetName == "end")
                    {
                        _targetIndex.Value = 1;
                    }
                    else
                    {
                        throw new ArgumentException("Unsupported target name: " + targetName);
                    }
                },
                () => _targetIndex.Value = 1);
        }