Exemplo n.º 1
0
        private void IsOnGround()
        {
            isOnGround = base.CollideCheck((int)GameTags.Solid, this.Position + Vector2.UnitY);

            if (isOnGround == false)
            {
                isOnGround = base.CollideCheck((int)GameTags.FallingPlatform, this.Position + Vector2.UnitY);
            }

            if (isOnGround == false && playerNextToLeft == false && playerNextToRight == false)
            {
                isOnGround = base.CollideCheck((int)GameTags.MovingPlatform, this.Position + Vector2.UnitY);
            }

            if (isOnGround == false)
            {
                isOnGround = base.CollideCheck((int)GameTags.MovingPlatformVert, this.Position - Vector2.UnitY);
            }

            if (isOnGround == false)
            {
                isOnGround = base.CollideCheck((int)GameTags.Enemy, this.Position + Vector2.UnitY);
            }

            using (List <Entity> .Enumerator enumerator = base.Scene[(int)GameTags.Oneway].GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Oneway one = (Oneway)enumerator.Current;
                    if (one.IsOnJumpThrough == true && isOnGround == false)
                    {
                        isOnGround = true;
                    }
                }
            }

            using (List <Entity> .Enumerator enumerator = base.Scene[(int)GameTags.MovingPlatformVert].GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    MovingPlatformVert one = (MovingPlatformVert)enumerator.Current;
                    if (one.IsPlayerOn == true && isOnGround == false)
                    {
                        isOnGround = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Version != 0)
            {
                hash ^= Version.GetHashCode();
            }
            if (SequenceID != 0)
            {
                hash ^= SequenceID.GetHashCode();
            }
            if (Oneway != false)
            {
                hash ^= Oneway.GetHashCode();
            }
            hash ^= metadata_.GetHashCode();
            hash ^= rawAny_.GetHashCode();
            if (ReservedInt1 != 0)
            {
                hash ^= ReservedInt1.GetHashCode();
            }
            if (ReservedInt2 != 0)
            {
                hash ^= ReservedInt2.GetHashCode();
            }
            if (ReservedStr1.Length != 0)
            {
                hash ^= ReservedStr1.GetHashCode();
            }
            if (ReservedStr2.Length != 0)
            {
                hash ^= ReservedStr2.GetHashCode();
            }
            if (ReservedBytes1.Length != 0)
            {
                hash ^= ReservedBytes1.GetHashCode();
            }
            if (ReservedBytes2.Length != 0)
            {
                hash ^= ReservedBytes2.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 3
0
        public ProfileResult Run(Context c, string behaviour, Dictionary <string, string> tags)
        {
            if (!Behaviours.ContainsKey(behaviour))
            {
                throw new ArgumentException(
                          $"Profile {Name} does not contain the behaviour {behaviour}\nTry one of {string.Join(",", Behaviours.Keys)}");
            }

            var parameters = new Dictionary <string, IExpression>();

            foreach (var(k, v) in DefaultParameters)
            {
                parameters[k.TrimStart('#')] = v;
            }

            foreach (var(k, v) in Behaviours[behaviour])
            {
                parameters[k.TrimStart('#')] = v;
            }

            c = c.WithParameters(parameters)
                .WithAspectName(this.Name);
            tags = new Dictionary <string, string>(tags);
            var canAccess = Access.Run(c, tags);

            tags["access"] = "" + canAccess;
            var speed = (double)Speed.Run(c, tags);

            tags["speed"] = "" + speed;
            var oneway = Oneway.Run(c, tags);

            tags["oneway"] = "" + oneway;

            c.AddFunction("speed", new AspectMetadata(new Constant(Typs.Double, speed),
                                                      "speed", "Actual speed of this function", "NA", "NA", "NA", true));
            c.AddFunction("oneway", new AspectMetadata(new Constant(Typs.String, oneway),
                                                       "oneway", "Actual direction of this function", "NA", "NA", "NA", true));
            c.AddFunction("access", new AspectMetadata(new Constant(Typs.String, canAccess),
                                                       "access", "Actual access of this function", "NA", "NA", "NA", true));


            var priority          = 0.0;
            var weightExplanation = new List <string>();

            foreach (var(paramName, expression) in Priority)
            {
                var aspectInfluence = (double)c.Parameters[paramName].Evaluate(c);
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (aspectInfluence == 0)
                {
                    continue;
                }


                var aspectWeightObj = new Apply(
                    Funcs.EitherFunc.Apply(Funcs.Id, Funcs.Const, expression)
                    , new Constant(tags)).Evaluate(c);

                double aspectWeight;
                switch (aspectWeightObj)
                {
                case bool b:
                    aspectWeight = b ? 1.0 : 0.0;
                    break;

                case double d:
                    aspectWeight = d;
                    break;

                case int j:
                    aspectWeight = j;
                    break;

                case string s:
                    if (s.Equals("yes"))
                    {
                        aspectWeight = 1.0;
                        break;
                    }
                    else if (s.Equals("no"))
                    {
                        aspectWeight = 0.0;
                        break;
                    }

                    throw new Exception($"Invalid value as result for {paramName}: got string {s}");

                default:
                    throw new Exception($"Invalid value as result for {paramName}: got object {aspectWeightObj}");
                }

                weightExplanation.Add($"({paramName} = {aspectInfluence}) * {aspectWeight}");
                priority += aspectInfluence * aspectWeight;
            }

            if (priority <= 0)
            {
                canAccess = "no";
            }

            return(new ProfileResult((string)canAccess, (string)oneway, speed, priority,
                                     string.Join("\n  ", weightExplanation)));
        }
Exemplo n.º 4
0
        public override void LoadContent()
        {
            base.LoadContent();

            Tile = new LevelTiler();

            levelData = Engine.Instance.Content.Load <LevelData>("TestLevel");
            Tile.LoadContent(levelData);

            collisionInfo = LevelTiler.TileConverison(Tile.CollisionLayer, 2);
            tiles         = new LevelTilesSolid(collisionInfo);
            this.Add(tiles);

            stopPointsInfo = LevelTiler.TileConverison(Tile.CollisionLayer, 4);
            stopPoints     = new LevelTilesStopPoints(stopPointsInfo);
            this.Add(stopPoints);

            Player = new Player(Tile.PlayerPosition[0]);
            this.Add(Player);
            Player.Added(this);

            onewayInfo = LevelTiler.TileConverison(Tile.CollisionLayer, 3);

            for (int i = 0; i < onewayInfo.GetLength(0); i++)
            {
                for (int j = 0; j < onewayInfo.GetLength(1); j++)
                {
                    bool tile = onewayInfo[i, j];
                    if (tile == false)
                    {
                        continue;
                    }

                    Vector2 position = new Vector2(i * TileInformation.TileWidth, j * TileInformation.TileHeight);
                    Oneway  platform = new Oneway(position);
                    this.Add(platform);
                    platform.Added(this);
                }
            }

            foreach (Entity entity in Tile.Entites)
            {
                if (entity.Type == "Enemy")
                {
                    BasicEnemy enemy = new BasicEnemy(entity.Position);
                    this.Add(enemy);
                    enemy.Added(this);
                }

                if (entity.Type == "FallingPlatform")
                {
                    FallingPlatform fallingPlatform = new FallingPlatform(entity.Position);
                    this.Add(fallingPlatform);
                    fallingPlatform.Added(this);
                }

                if (entity.Type == "MovingPlatform")
                {
                    MovingPlatform movingPlatform = new MovingPlatform(entity.Position);
                    this.Add(movingPlatform);
                    movingPlatform.Added(this);
                }

                if (entity.Type == "MovingPlatformVert")
                {
                    MovingPlatformVert movingPlatform = new MovingPlatformVert(entity.Position);
                    this.Add(movingPlatform);
                    movingPlatform.Added(this);
                }
            }
        }