public Entity Create(string name, string teamName, uint team, Vector3 position, Vector3 velocity, Quaternion orientation, Vector3 angularVelocity, IReadOnlyList <Yolol.Grammar.AST.Program> programs)
        {
            var e = base.Create();

            e.GetProperty(PropertyNames.UniqueName) !.Value = name;
            e.GetProperty(PropertyNames.TeamName) !.Value   = teamName;
            e.GetProperty(PropertyNames.TeamOwner) !.Value  = team;

            e.GetProperty(PropertyNames.Position) !.Value        = position;
            e.GetProperty(PropertyNames.Velocity) !.Value        = velocity;
            e.GetProperty(PropertyNames.Orientation) !.Value     = orientation;
            e.GetProperty(PropertyNames.AngularVelocity) !.Value = angularVelocity;

            e.GetProperty(PropertyNames.YololContext) !.Value = new YololContext(programs);

            return(e);
        }
        public Entity Create(uint team, Vector3 position, Vector3 velocity, Quaternion orientation, Vector3 angularVelocity, Program program)
        {
            var e = base.Create();

            e.GetProperty(PropertyNames.UniqueName) !.Value = Guid.NewGuid().ToString();
            e.GetProperty(PropertyNames.TeamOwner) !.Value  = team;

            e.GetProperty(PropertyNames.Position) !.Value = position;
            e.GetProperty(PropertyNames.Velocity) !.Value = velocity;

            e.GetProperty(PropertyNames.Orientation) !.Value     = orientation;
            e.GetProperty(PropertyNames.AngularVelocity) !.Value = angularVelocity;

            e.GetProperty(PropertyNames.YololContext) !.Value = new YololContext(new[] { program });

            return(e);
        }
Beispiel #3
0
            public void Update(float elapsedTime, YololContext ctx, Scene scene)
            {
                // Change gun angles
                var tgtElevation = ctx.Get(_elevationName);

                _elevation.Value = MoveTo(_elevation.Value, YololValue.Number(tgtElevation.Value, MinElevation, MaxElevation), ElevationSpeed * elapsedTime);
                var tgtBearing = ctx.Get(_bearingName);

                _bearing.Value = MoveToAngle(_bearing.Value, YololValue.Number(tgtBearing.Value, 0, 360), BearingSpeed * elapsedTime);

                // Copy angles back to Yolol
                var actualElevation = ctx.Get(_actualElevationName);

                actualElevation.Value = (Number)_elevation.Value;
                var actualBearing = ctx.Get(_actualBearingName);

                actualBearing.Value = (Number)_bearing.Value;

                // Check if gun is ready
                var ready = ctx.Get(_gunReadyName);

                _cooldownTime -= elapsedTime;
                if (_cooldownTime <= 0)
                {
                    ready.Value = (Number)true;
                }

                // Fire gun
                var trigger = ctx.Get(_gunTriggerName);
                var t       = trigger.Value;

                if (_cooldownTime <= 0 && t.Type == Yolol.Execution.Type.Number && t.Number > (Number)0)
                {
                    trigger.Value = t - (Number)1;
                    _cooldownTime = CooldownTime;
                    ready.Value   = (Number)false;

                    // Work out what the fuse setting is for this gun and then spawn a shell
                    var fuseVar = ctx.Get(_gunFuseName);
                    var fuse    = Math.Clamp(fuseVar.Value.Type == Yolol.Execution.Type.Number ? (float)fuseVar.Value.Number : 0, MinFuse, MaxFuse);
                    scene.Add(_shellFactory.Create(fuse, _team.Value, _position.Value, _velocity.Value + GunDirection() * ShellSpeed));
                }
            }
        public static void SetConstants(YololContext ctx)
        {
            var fields = typeof(Constants).GetFields(BindingFlags.Public | BindingFlags.Static);

            foreach (var field in fields)
            {
                var variable = ctx.Get($":const_{field.Name}");

                var value = field.GetValue(null);

                if (field.FieldType == typeof(float))
                {
                    variable.Value = (Number)(float)value;
                }

                if (field.FieldType == typeof(string))
                {
                    variable.Value = (string)value;
                }
            }
        }