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

            textureName = section["texture"];
            circlePos = section["position"].AsVector2();
            Radius = section["radius"];
            MaxTorque = section["torque"];

            var bodyDef = new BodyDef();
            bodyDef.type = BodyType.Dynamic;

            bodyDef.position = Game.level.ConvertToBox2D(circlePos);
            bodyDef.inertiaScale = section["inertiaScale"];
            bodyDef.linearDamping = section["linearDamping"];
            bodyDef.angularDamping = section["angularDamping"];

            bodyDef.userData = this;

            Body = Game.level.World.CreateBody(bodyDef);

            var shape = new CircleShape();
            shape._radius = Game.level.ConvertToBox2D(Radius);

            var fixture = new FixtureDef();
            fixture.restitution = section["restitution"];
            fixture.density = section["density"];
            fixture.shape = shape;
            fixture.friction = section["friction"];
            Body.CreateFixture(fixture);
        }
Exemplo n.º 2
0
        public static Element Create(Element parent, string name, ConfigSection section)
        {
            var typeName = (string)section["type"];

            Debug.Assert(typeName != "root");

            Element result;

            switch (typeName)
            {
                case "button":
                    result = new Button(parent.Game);
                    break;
                case "window":
                    result = new Window(parent.Game);
                    break;
                default:
                    throw new NotSupportedException(
                        string.Format("Unsupported Element type: {0}",
                                      typeName));
            }

            result.Type = typeName;
            result.Parent = parent;
            result.Name = name;
            result.Initialize(section);

            return result;
        }
Exemplo n.º 3
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            textureName = section["texture"];
            circlePos = section["position"].AsVector2();
            Radius = section["radius"];

            var bodyDescription = new scBodyDescription();
            bodyDescription.bodyType = scBodyType.Kinematic;

            bodyDescription.transform.position = circlePos;
            bodyDescription.inertiaScale = section["inertiaScale"];
            bodyDescription.linearDamping = section["linearDamping"];
            bodyDescription.angularDamping = section["angularDamping"];

            bodyDescription.userData = this;

            var shape = new scCircleShape();
            shape.radius = Radius;

            var bodyPartDescription = new scBodyPartDescription();
            bodyPartDescription.restitution = section["restitution"];
            bodyPartDescription.density = section["density"];
            bodyPartDescription.shape = shape;
            bodyPartDescription.friction = section["friction"];

            Body = Game.level.World.createBody(bodyDescription, bodyPartDescription);
            Body.owner = this;
        }
Exemplo n.º 4
0
        public void Create()
        {
            var section = new ConfigSection();

            Assert.AreEqual(0, section.Options.Count);

            section["TestOption1"] = ConfigOption.Create("hello");
            Assert.AreEqual(1, section.Options.Count);
            Assert.AreEqual<string>("hello", section["TestOption1"]);

            section["TestOption1"] = ConfigOption.Create("world");
            Assert.AreEqual(1, section.Options.Count);
            Assert.AreEqual<string>("world", section["TestOption1"]);
        }
Exemplo n.º 5
0
        public static GameObject Create(Game game, string gameObjectName, ConfigSection section)
        {
            var typeName = (string)section["type"];
            GameObject resultObject;

            switch (typeName)
            {
                case "square":
                    resultObject = new Square(game);
                    break;
                case "circle":
                    resultObject = new Circle(game);
                    break;
                case "platform":
                    resultObject = new PlatformObject(game);
                    break;
                case "trigger":
                    resultObject = new TriggerObject(game);
                    break;
                case "toggleButton":
                    resultObject = new ToggleButtonObject(game);
                    break;
                case "holdButton":
                    resultObject = new HoldButtonObject(game);
                    break;
                default:
                {
                    var message = new StringBuilder();
                    message.AppendFormat("Unsupported GameObject type: {0}", typeName);
                    throw new NotSupportedException(message.ToString());
                }
            }

            resultObject.Name = gameObjectName;
            resultObject.Initialize(section);

            Debug.Assert(resultObject.Body != null, "Game objects have to have a valid physics body after initialization.");

            return resultObject;
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public virtual void Initialize(ConfigSection section)
 {
     section.IfOptionExists("name", opt => Name = opt);
     section.IfOptionExists("drawOrder", opt => DrawOrder = opt);
 }
Exemplo n.º 8
0
 public void Initialize(ConfigSection section)
 {
     GlobalSettingsFileName = section["settings"];
     WaveBankFileName = section["waveBank"];
     SoundBankFileName = section["soundBank"];
 }
Exemplo n.º 9
0
 private void ParseSection(ref StringStream stream,
     out string out_sectionName,
     out ConfigSection out_section)
 {
     out_section = new ConfigSection();
     ParseSectionHeader(ref stream, out out_sectionName);
     ParseSectionBody(ref stream, ref out_section);
 }
Exemplo n.º 10
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            textureName = section["texture"];
            var pos = section["position"].AsVector2();
            SideLength = section["sideLength"];
            Speed = section["speed"];
            MaxSpeed = section["maxSpeed"];
            JumpImpulse = section["jumpImpulse"];
            JumpThreshold = section["jumpThreshold"];

            var bodyDef = new BodyDef();
            bodyDef.type = BodyType.Dynamic;

            bodyDef.angle = 0;
            bodyDef.position = Game.level.ConvertToBox2D(pos);
            bodyDef.inertiaScale = section["inertiaScale"];
            bodyDef.linearDamping = section["linearDamping"];
            bodyDef.angularDamping = section["angularDamping"];

            bodyDef.userData = this;

            Body = Game.level.World.CreateBody(bodyDef);

            var shape = new PolygonShape();
            var offset = SideLength / 2;
            shape.Set(new Vector2[]{
                Game.level.ConvertToBox2D(new Vector2(-offset, -offset)),
                Game.level.ConvertToBox2D(new Vector2(offset, -offset)),
                Game.level.ConvertToBox2D(new Vector2(offset, offset)),
                Game.level.ConvertToBox2D(new Vector2(-offset, offset))
                }
            , 4);

            var fixture = new FixtureDef();
            fixture.restitution = section["restitution"];
            fixture.density = section["density"];
            fixture.shape = shape;
            fixture.friction = section["friction"];
            Body.CreateFixture(fixture);
        }
Exemplo n.º 11
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            if (section.Options.ContainsKey("texture"))
            {
                _textureName = section["texture"];
            }

            var pos = section["position"].AsVector2();
            _dim = section["dimensions"].AsVector2();

            if (section.Options.ContainsKey("enterEvent"))
            {
                _enterEvent = section["enterEvent"];
            }

            if (section.Options.ContainsKey("leaveEvent"))
            {
                _leaveEvent = section["leaveEvent"];
            }

            if (section.Options.ContainsKey("enterEventData"))
            {
                _enterEventData = section["enterEventData"];
            }

            if (section.Options.ContainsKey("leaveEventData"))
            {
                _leaveEventData = section["leaveEventData"];
            }

            var bodyDescription = new scBodyDescription();
            bodyDescription.userData = this;
            var bodyPartDescription = new scBodyPartDescription();
            var shape = scRectangleShape.fromLocalPositionAndHalfExtents(Vector2.Zero, _dim / 2);
            bodyPartDescription.shape = shape;
            bodyPartDescription.isTrigger = true;
            bodyDescription.transform.position = pos;
            Body = Game.level.World.createBody(bodyDescription, bodyPartDescription);
            Body.owner = this;
        }
Exemplo n.º 12
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            var bodyDescription = new scBodyDescription();
            bodyDescription.bodyType = scBodyType.Static;
            bodyDescription.transform.position = section["position"].AsVector2();
            bodyDescription.userData = this;

            var bodyPartDescription = new scBodyPartDescription();
            bodyPartDescription.shape = new scCircleShape() { radius = section["proximityRadius"] };
            bodyPartDescription.isTrigger = true;
            bodyPartDescription.userData = this;

            Body = Game.level.World.createBody(bodyDescription, bodyPartDescription);

            Body.beginCollision += (other) => { if (other == Master.Body) IsMasterInProximity = true; };
            Body.endCollision += (other) => { if (other == Master.Body) IsMasterInProximity = false; };

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

            string masterName = section["master"];

            Master = Game.level.GetGameObject(masterName);

            var state = section["state"];

            if (state == "active")
            {
                InitialOnOffState.setActive();
            }
            else if (state == "inactive")
            {
                InitialOnOffState.setInactive();
            }
            else
            {
                throw new ArgumentException("Unsupported GameObject state: " + state);
            }

            OnOffState.Value = InitialOnOffState.Value;

            if (section.Options.ContainsKey("onButtonOn"))
            {
                OnEvent = Game.Events[section["onButtonOn"]];
            }

            if (section.Options.ContainsKey("onButtonOnData"))
            {
                OnEventData = section["onButtonOnData"];
            }

            if (section.Options.ContainsKey("onButtonOff"))
            {
                OffEvent = Game.Events[section["onButtonOff"]];
            }

            if (section.Options.ContainsKey("onButtonOffData"))
            {
                OffEventData = section["onButtonOffData"];
            }

            Game.Events["playerButtonPress"].addListener(OnPlayerButtonPress);
            Game.Events["playerButtonRelease"].addListener(OnPlayerButtonRelease);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            BackgroundTextureName = section["background"];
            var buttonsConfig = section["buttons"].AsConfigFile();
            foreach (var buttonSection in buttonsConfig.Sections)
            {
                if (buttonSection.Value == buttonsConfig.GlobalSection) { continue; }

                var button = Element.Create(this, buttonSection.Key, buttonSection.Value) as Button;
                Debug.Assert(button != null, "Invalid UI child type.");
                Buttons.Add(button);
            }

            Debug.Assert(Buttons.Count > 0, "A windows needs at least 1 button!");
            SelectedButtonIndex.UpperBound = Buttons.Count - 1;
            SelectedButtonIndex.Value = 0;

            foreach (var button in Buttons)
            {
                button.SetOnOff(false);
            }
            SelectedButton.ToggleOnOff();
        }
Exemplo n.º 15
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            TextureOnName = section["textureOn"];
            TextureOffName = section["textureOff"];
            Pos = section["position"].AsVector2();
            ProximityRadius = section["proximityRadius"];

            string masterName = section["master"];

            Master = Game.level.GetGameObject(masterName);

            var state = section["state"];

            if (state == "active")
            {
                InitialOnOffState.setActive();
            }
            else if (state == "inactive")
            {
                InitialOnOffState.setInactive();
            }
            else
            {
                throw new ArgumentException("Unsupported GameObject state: " + state);
            }

            OnOffState.Value = InitialOnOffState.Value;

            if (section.Options.ContainsKey("onButtonOn"))
            {
                OnEvent = Game.Events[section["onButtonOn"]];
            }

            if (section.Options.ContainsKey("onButtonOnData"))
            {
                OnEventData = section["onButtonOnData"];
            }

            if (section.Options.ContainsKey("onButtonOff"))
            {
                OffEvent = Game.Events[section["onButtonOff"]];
            }

            if (section.Options.ContainsKey("onButtonOffData"))
            {
                OffEventData = section["onButtonOffData"];
            }

            Game.Events["playerButtonPress"].addListener(OnPlayerButtonPress);
            Game.Events["playerButtonRelease"].addListener(OnPlayerButtonRelease);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            if (section.Options.ContainsKey("texture"))
            {
                _textureName = section["texture"];
            }

            var pos = section["position"].AsVector2();
            _dim = section["dimensions"].AsVector2();

            if (section.Options.ContainsKey("enterEvent"))
            {
                _enterEvent = section["enterEvent"];
            }

            if (section.Options.ContainsKey("leaveEvent"))
            {
                _leaveEvent = section["leaveEvent"];
            }

            if (section.Options.ContainsKey("enterEventData"))
            {
                _enterEventData = section["enterEventData"];
            }

            if (section.Options.ContainsKey("leaveEventData"))
            {
                _leaveEventData = section["leaveEventData"];
            }

            var bodyDef = new BodyDef();
            bodyDef.userData = this;
            var fixtureDef = new FixtureDef();
            var shape = new PolygonShape();
            shape.SetAsBox(Game.level.ConvertToBox2D(_dim.X / 2), Game.level.ConvertToBox2D(_dim.Y / 2));
            fixtureDef.shape = shape;
            fixtureDef.isSensor = true;
            fixtureDef.userData = new LevelElementInfo() { type = LevelElementType.Ground };
            bodyDef.position = Game.level.ConvertToBox2D(pos);
            Body = Game.level.World.CreateBody(bodyDef);
            Body.CreateFixture(fixtureDef);
        }
Exemplo n.º 18
0
 public ConfigFile()
 {
     Sections = new Dictionary<string, ConfigSection>();
     GlobalSection = new ConfigSection();
     Sections.Add(GlobalSectionName, GlobalSection);
 }
Exemplo n.º 19
0
 private void ParseGlobalSection(ref StringStream stream,
     ref ConfigSection out_section)
 {
     ParseSectionBody(ref stream, ref out_section);
 }
Exemplo n.º 20
0
 public virtual void Initialize(ConfigSection section)
 {
     Position = section["position"].AsVector2();
     Dimensions = section["dimensions"].AsVector2();
 }
Exemplo n.º 21
0
        private void ParseSectionBody(ref StringStream stream,
            ref ConfigSection ref_section)
        {
            stream.Skip(WhiteSpaceNewline);
            while (true)
            {
                stream.Skip(WhiteSpace);
                if (stream.IsAtEndOfStream)
                {
                    break;
                }

                var currentChar = stream.PeekUnchecked();

                if (currentChar == SectionPrefix)
                {
                    break;
                }

                if (currentChar == CommentPrefix)
                {
                    string comment;
                    ParseComment(ref stream, out comment);
                    if (!string.IsNullOrEmpty(ref_section.Comment))
                    {
                        comment = Environment.NewLine + comment;
                    }
                    ref_section.Comment += comment;
                    continue;
                }

                string optionName;
                ConfigOption option;
                ParseOption(ref stream, out optionName, out option);
                ref_section[optionName] = option;
            }
        }
Exemplo n.º 22
0
        public override void Initialize(ConfigSection section)
        {
            base.Initialize(section);

            textureName = section["texture"];
            var position = section["position"].AsVector2();
            SideLength = section["sideLength"];
            Speed = section["speed"];
            MaxSpeed = section["maxSpeed"];
            JumpImpulse = section["jumpImpulse"];
            JumpThreshold = section["jumpThreshold"];

            var bodyDescription = new scBodyDescription();
            bodyDescription.bodyType = scBodyType.Kinematic;
            bodyDescription.transform.position = position;
            bodyDescription.inertiaScale = section["inertiaScale"];
            bodyDescription.linearDamping = section["linearDamping"];
            bodyDescription.angularDamping = section["angularDamping"];
            bodyDescription.userData = this;

            var bodyPartDescription = new scBodyPartDescription();

            bodyPartDescription.shape = scRectangleShape.fromHalfExtents(new Vector2(SideLength / 2));
            bodyPartDescription.friction = section["friction"];
            bodyPartDescription.restitution = section["restitution"];
            bodyPartDescription.density = section["density"];

            Body = Game.level.World.createBody(bodyDescription, bodyPartDescription);
            Body.owner = this;
        }