Beispiel #1
0
 public bool IsInside(Position2 point)
 {
     return(point.X >= this.TopLeft.X &&
            point.Y >= this.TopLeft.Y &&
            point.X < this.TopLeft.X + this.Size.X &&
            point.Y < this.TopLeft.Y + this.Size.Y);
 }
        public void GetPosition(object p)
        {
            switch (p.ToString())
            {
            case "1":
                Position1 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position1", Position1.ToString());
                break;

            case "2":
                Position2 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position2", Position2.ToString());
                break;

            case "3":
                Position3 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position3", Position3.ToString());
                break;

            case "4":
                Position4 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position4", Position4.ToString());
                break;

            case "5":
                Position5 = (double)ActPos1.Value;
                Inifile.INIWriteValue(iniPosition, "Axis1", "Position5", Position5.ToString());
                break;
            }
        }
Beispiel #3
0
        public Tile <TileInfo> GetTile(Position2 position)
        {
            var yf = position.Y.NumericValue * (1 / HexagonDistanceY) + 1 / 1.5f;
            var y  = Floor(yf);
            var xf = position.X.NumericValue * (1 / HexagonWidth) - y * 0.5f + 0.5f;
            var x  = Floor(xf);

            var xRemainder = (xf - x) - 0.5f;
            var yRemainder = (yf - y) * 1.5f;

            var tx = (int)x;
            var ty = (int)y;

            if (xRemainder > yRemainder)
            {
                tx++;
                ty--;
            }
            else if (-xRemainder > yRemainder)
            {
                ty--;
            }

            return(new Tile <TileInfo>(Tilemap, tx, ty));
        }
Beispiel #4
0
        public IEnumerable <Tile <TileInfo> > TilesIntersecting(Position2 center, Unit radius)
        {
            var r = radius.NumericValue;
            var rSquared = r * r;
            var centerV = center.NumericValue;
            var tl = centerV + new Vector2(-r);
            var br = centerV + new Vector2(r);
            int x0, x1, y0, y1;

            this.positionToTile(tl.X, tl.Y, out x0, out y0);
            this.positionToTile(br.X, br.Y, out x1, out y1);

            float tileCenterX0, tileCenterY;

            this.tileToCenterPosition(x0, y0, out tileCenterX0, out tileCenterY);

            var tileCenterX1 = tileCenterX0 + gridSize * (x1 - x0);

            for (var y = y0; y <= y1; y++)
            {
                var xStart      = x0;
                var tileCenterX = tileCenterX0;
                while (xStart <= x1)
                {
                    if (rectIntersectsCircle(
                            new Vector2(tileCenterX, tileCenterY),
                            new Vector2(gridSizeHalf, gridSizeHalf),
                            centerV, rSquared))
                    {
                        break;
                    }

                    tileCenterX += gridSize;
                    xStart      += 1;
                }

                var xEnd = x1;
                tileCenterX = tileCenterX1;
                while (xEnd > xStart)
                {
                    if (rectIntersectsCircle(
                            new Vector2(tileCenterX, tileCenterY),
                            new Vector2(gridSizeHalf, gridSizeHalf),
                            centerV, rSquared))
                    {
                        break;
                    }

                    tileCenterX -= gridSize;
                    xEnd        -= 1;
                }

                for (var x = xStart; x <= xEnd; x++)
                {
                    yield return(new Tile <TileInfo>(this.tilemap, x, y));
                }

                tileCenterY += gridSize;
            }
        }
Beispiel #5
0
 public Parameters(Id <IBody> id, Position2 position, Radius radius, float mass)
 {
     this.Id       = id;
     this.Position = position;
     this.Radius   = radius;
     this.Mass     = mass;
 }
 public CommandParameters(Id <FreeObject> id, Player player, Position2 position, Velocity2 velocity)
 {
     this.id       = id.Simple;
     this.playerId = player.ID.Simple;
     this.position = position;
     this.velocity = velocity;
 }
Beispiel #7
0
        public override void Update(TimeSpan t)
        {
            this.game.CollisionHandler.HandleCollision(this);

            if (this.Deleted)
            {
                return;
            }

            var acceleration = Vector2.Zero;

            foreach (var body in this.game.Bodies)
            {
                var shape = body.Shape;

                var difference = shape.Center - this.position;

                var distanceSquared = difference.LengthSquared;

                var a = Constants.G * body.Mass / distanceSquared.NumericValue;

                var dirNormal = difference.Direction.Vector;

                acceleration += dirNormal * a;
            }

            this.velocity += new Velocity2(acceleration * (float)t.NumericValue);

            this.position += this.velocity * t;
        }
Beispiel #8
0
 public bool IsInside(Position2 point)
 {
     return point.X >= this.TopLeft.X
         && point.Y >= this.TopLeft.Y
         && point.X < this.TopLeft.X + this.Size.X
         && point.Y < this.TopLeft.Y + this.Size.Y;
 }
Beispiel #9
0
        private void shootTarget()
        {
            target.Damage(Damage);

            laserTargetPoint   = target.Position;
            laserTargetEndTime = Building.Game.Time + new TimeSpan(0.1);
        }
Beispiel #10
0
            public override PositionedFootprint GetPositionedFootprint(Level level, Position2 position)
            {
                var currentTile   = level.GetTile(position);
                var tileCenter    = level.GetPosition(currentTile);
                var direction2    = (position - tileCenter).Direction;
                var directionEnum = (direction2 - 30.Degrees()).Hexagonal();

                switch (directionEnum)
                {
                case Direction.Left:
                    return(new PositionedFootprint(level, Footprint.TriangleDown, currentTile.Neighbour(Direction.Left)));

                case Direction.DownLeft:
                    return(new PositionedFootprint(level, Footprint.TriangleUp, currentTile.Neighbour(Direction.DownLeft)));

                case Direction.DownRight:
                    return(new PositionedFootprint(level, Footprint.TriangleDown, currentTile));

                case Direction.Right:
                    return(new PositionedFootprint(level, Footprint.TriangleUp, currentTile));

                case Direction.UpRight:
                    return(new PositionedFootprint(level, Footprint.TriangleDown, currentTile.Neighbour(Direction.UpLeft)));

                case Direction.UpLeft:
                    return(new PositionedFootprint(level, Footprint.TriangleUp, currentTile.Neighbour(Direction.Left)));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
Beispiel #11
0
 public HitResult(Position2 point, Direction2 normal, float rayFactor, bool fromInside)
 {
     this.Point = point;
     this.Normal = normal;
     this.RayFactor = rayFactor;
     this.FromInside = fromInside;
 }
Beispiel #12
0
            public HitResult?Update(GameState game, TimeSpan time)
            {
                var vDelta = this.velocity * time;

                var hitResult = new Ray(this.position, vDelta)
                                .Shoot(game, true, this.collideWithProjectileColliders);

                var f = hitResult.HasValue ? hitResult.Value.RayFactor : 1;

                var zDelta = this.vz * time;

                var z = this.z + zDelta;

                if (z < 0.U())
                {
                    f         = this.z / zDelta;
                    z         = 0.U();
                    hitResult = new HitResult(this.position + vDelta * f, Direction2.Zero, f, false);
                }

                this.position += vDelta * f;
                this.z         = z;

                this.vz += game.Gravity * time;

                return(hitResult);
            }
Beispiel #13
0
        public void MultiTransform()
        {
            var c = new DataCube2 <int, int, int>();

            c.Set(0, 0, 1);
            c.Set(0, 1, 10);
            c.Set(1, 0, 100);
            c.Set(1, 1, 1000);

            // Transforms each position to all "lower" positions.
            var transformed = c.MultiTransform(
                p =>
            {
                var range1 = Enumerable.Range(0, p.ProductValue1 + 1);
                var range2 = Enumerable.Range(0, p.ProductValue2 + 1);
                return(range1.SelectMany(r1 => range2.Select(r2 => Position2.Create(r1, r2))));
            },
                (a, b) => a + b
                );

            Assert.Equal(1111, transformed.Get(0, 0).Get());
            Assert.Equal(1010, transformed.Get(0, 1).Get());
            Assert.Equal(1100, transformed.Get(1, 0).Get());
            Assert.Equal(1000, transformed.Get(1, 1).Get());
        }
Beispiel #14
0
 public HitResult(Position2 point, Direction2 normal, float rayFactor, bool fromInside)
 {
     this.Point      = point;
     this.Normal     = normal;
     this.RayFactor  = rayFactor;
     this.FromInside = fromInside;
 }
Beispiel #15
0
        public FreeObject(GameState game, Id <FreeObject> id, Position2 position, Velocity2 velocity)
            : base(game, id)
        {
            this.position = position;
            this.velocity = velocity;

            game.ContinuousSynchronizer.Sync(this);
        }
Beispiel #16
0
        public Building(GameState game, Position2 topLeft, Difference2 size)
            : base(game)
        {
            this.TopLeft = topLeft;
            this.Size = size;

            this.listAs<Building>();
        }
Beispiel #17
0
    public static long Solve2(string[] lines)
    {
        Position2 pos = lines
                        .Select(Parse)
                        .Aggregate(new Position2(0, 0, 0), (acc, inst) => acc.Move(inst));

        return(pos.X * pos.Y);
    }
Beispiel #18
0
 public FixedBody(GameState game, Id <IBody> id, Position2 center, Radius radius, float mass, Color color)
     : base(game, id)
 {
     this.center = center;
     this.radius = radius;
     this.mass   = mass;
     this.color  = color;
 }
Beispiel #19
0
 public TurretData(Position2 pos)
 {
     position     = pos;
     shotDelay    = 1F;
     startupDelay = 0F;
     shotSpeed    = 1F;
     constantFire = true;
 }
Beispiel #20
0
 public PortalData(Position2 pos, int id)
 {
     portalID       = id = -1;
     linkedPortalID = -1;
     portalType     = Portal.PortalType.oneway;
     position       = pos;
     active         = true;
 }
 /// <summary>
 /// Makes the contents of this message dump to a easy to understand string
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(string.Format(
                "{0} - {1:1;0;0}{2:1;0;0}",
                ErrorCode,
                Position1.GetHashCode(),
                Position2.GetHashCode()));
 }
Beispiel #22
0
        public override void Update(TimeSpan elapsedTime)
        {
            this.goalPoint = this.controller.Control();

            updateMovement(elapsedTime);

            this.eventListenerTileManager.Update();
        }
Beispiel #23
0
        public RandomAgent(GameState game)
            : base(game, new Position2(StaticRandom.Float(-1, 1) * roomWidth, StaticRandom.Float(-1, 1) * roomHeight))
        {
            this.goal         = this.position;
            this.jitteredGoal = this.goal;

            this.nextMoveTime = this.game.Time + new TimeSpan(StaticRandom.Double(0, 10));
        }
Beispiel #24
0
 protected override void ProcessInputs(out bool processAllOutputs)
 {
     //we know both inputs are filled if this is called
     data = new Position2((float)inX.GetData(), (float)inY.GetData());
     outputs[0].SetData(data.ToVector());
     hasProcessedThisFrame = true;
     processAllOutputs     = true;
 }
Beispiel #25
0
 protected GameEvent(Position2 position, Unit visibleRadius, Unit audibleRadius)
 {
     this.Position         = position;
     this.VisibleRadius    = visibleRadius;
     this.AudibleRadius    = audibleRadius;
     this.MaxRadius        = visibleRadius > audibleRadius ? visibleRadius : audibleRadius;
     this.maxRadiusSquared = this.MaxRadius.Squared;
 }
Beispiel #26
0
 public Data(Position2 p, Velocity2 v, Unit z, Speed vz, bool collideWithProjectileColliders)
 {
     this.position = p;
     this.velocity = v;
     this.z = z;
     this.vz = vz;
     this.collideWithProjectileColliders = collideWithProjectileColliders;
 }
Beispiel #27
0
 public CollidingParticle(GameState game,
                          Position2 position, Velocity2 velocity,
                          Unit z, Speed vz,
                          bool collideWithProjectileColliders)
     : base(game)
 {
     this.data = new Data(position, velocity, z, vz, collideWithProjectileColliders);
 }
Beispiel #28
0
 public CollidingParticle(GameState game,
     Position2 position, Velocity2 velocity,
     Unit z, Speed vz,
     bool collideWithProjectileColliders)
     : base(game)
 {
     this.data = new Data(position, velocity, z, vz, collideWithProjectileColliders);
 }
Beispiel #29
0
 public Data(Position2 p, Velocity2 v, Unit z, Speed vz, bool collideWithProjectileColliders)
 {
     this.position = p;
     this.velocity = v;
     this.z        = z;
     this.vz       = vz;
     this.collideWithProjectileColliders = collideWithProjectileColliders;
 }
Beispiel #30
0
        public Building(GameState game, Position2 topLeft, Difference2 size)
            : base(game)
        {
            this.TopLeft = topLeft;
            this.Size    = size;

            this.listAs <Building>();
        }
Beispiel #31
0
        public override void Update(TimeSpan elapsedTime)
        {
            this.goalPoint = this.controller.Control();

            updateMovement(elapsedTime);

            this.eventListenerTileManager.Update();
        }
Beispiel #32
0
        public Agent(GameState game, Position2 position, string id = null)
            : base(game)
        {
            this.position = position;
            this.goal     = position;
            this.id       = id;

            System.Console.WriteLine($"spawning agent '{id}'");
        }
Beispiel #33
0
        private Vector2 pointToUV2(Position2 point)
        {
            var diff = (point - this.uvBase2).NumericValue;

            var u = Vector2.Dot(diff, this.uDiff2.NumericValue);
            var v = Vector2.Dot(diff, this.vDiff2.NumericValue);

            return(new Vector2(u, v));
        }
Beispiel #34
0
        //public NavMeshAABB AABB1 { get; set; }
        //public NavMeshAABB AABB2 { get; set; }

        public override string ToString()
        {
            return(Unknown_00h.ToString() + ", " +
                   Position1.ToString() + ", " + Position2.ToString() + ", " +
                   Unknown_10h.ToString() + ", " + Unknown_12h.ToString() + ", " +
                   Unknown_14h.ToString() + ", " + Unknown_16h.ToString() + ", " +
                   Unknown_18h.ToString() + ", " + Unknown_1Ah.ToString());
            //AABB1.ToString() + ", " + AABB2.ToString();
        }
 internal ConstructionDto(Construction construction)
 {
     TypeId = construction.Type.Id;
     Id     = construction.Id;
     Center = construction.Center;
     Items  = construction.Items
              .Select(pair => new ItemBunchDto(pair.Value))
              .ToList();
 }
Beispiel #36
0
        public CCPoint GetWorldPosition(float hexRadius, float hexMargin)
        {
            var p1     = Position1.GetWorldPosition(hexRadius, hexMargin);
            var p2     = Position2.GetWorldPosition(hexRadius, hexMargin);
            var p3     = Position3.GetWorldPosition(hexRadius, hexMargin);
            var result = (p1 + p2 + p3) / 3;

            return(result);
        }
Beispiel #37
0
 public Tile<TileInfo> this[Position2 point]
 {
     get
     {
         var p = point.NumericValue;
         int ty, tx;
         this.positionToTile(p.X, p.Y, out tx, out ty);
         return new Tile<TileInfo>(this.tilemap, tx, ty);
     }
 }
Beispiel #38
0
        private NavLink(NavQuad from, NavQuad to, Position2 point0, Position2 point1)
        {
            this.From = from;
            this.To = to;

            this.P0 = point0;
            this.P1 = point1;

            this.Distance = (from.Center - to.Center).Length;
        }
Beispiel #39
0
 public Ray(Position2 start, Difference2 direction)
 {
     this.Start = start;
     this.Direction = direction;
 }
Beispiel #40
0
        public IEnumerable<Tile<TileInfo>> TilesIntersecting(Position2 center, Unit radius)
        {
            var r = radius.NumericValue;
            var rSquared = r * r;
            var centerV = center.NumericValue;
            var tl = centerV + new Vector2(-r);
            var br = centerV + new Vector2(r);
            int x0, x1, y0, y1;
            this.positionToTile(tl.X, tl.Y, out x0, out y0);
            this.positionToTile(br.X, br.Y, out x1, out y1);

            float tileCenterX0, tileCenterY;

            this.tileToCenterPosition(x0, y0, out tileCenterX0, out tileCenterY);

            var tileCenterX1 = tileCenterX0 + gridSize * (x1 - x0);

            for (var y = y0; y <= y1; y++)
            {
                var xStart = x0;
                var tileCenterX = tileCenterX0;
                while (xStart <= x1)
                {
                    if (rectIntersectsCircle(
                        new Vector2(tileCenterX, tileCenterY),
                        new Vector2(gridSizeHalf, gridSizeHalf),
                        centerV, rSquared))
                    {
                        break;
                    }

                    tileCenterX += gridSize;
                    xStart += 1;
                }

                var xEnd = x1;
                tileCenterX = tileCenterX1;
                while (xEnd > xStart)
                {
                    if (rectIntersectsCircle(
                        new Vector2(tileCenterX, tileCenterY),
                        new Vector2(gridSizeHalf, gridSizeHalf),
                        centerV, rSquared))
                    {
                        break;
                    }

                    tileCenterX -= gridSize;
                    xEnd -= 1;
                }

                for (var x = xStart; x <= xEnd; x++)
                {
                    yield return new Tile<TileInfo>(this.tilemap, x, y);
                }

                tileCenterY += gridSize;
            }
        }
Beispiel #41
0
 public IEnumerable<Tile<TileInfo>> TilesIntersecting(Position2 point, Difference2 size)
 {
     return this.TilesIn(this.RectangleIntersecting(point, size));
 }
Beispiel #42
0
        public TileRectangle RectangleIntersecting(Position2 point, Difference2 size)
        {
            var tl = point.NumericValue;
            var br = tl + size.NumericValue;
            int x0, x1, y0, y1;
            this.positionToTile(tl.X, tl.Y, out x0, out y0);
            this.positionToTile(br.X, br.Y, out x1, out y1);

            return new TileRectangle(x0, y0, x1, y1);
        }
Beispiel #43
0
 public Intersection(Position2 position)
 {
     this.Position = position;
     this.Streets = this.streets.AsReadOnly();
 }
 public Projectile(GameState game, Id<FreeObject> id, Player owner,
     Position2 position, Velocity2 velocity)
     : base(game, id, position, velocity)
 {
     this.owner = owner;
 }
 private SingleParameters(Id<FreeObject> id, Position2 position, Velocity2 velocity)
 {
     this.id = id.Simple;
     this.position = position;
     this.velocity = velocity;
 }
Beispiel #46
0
            public HitResult? Update(GameState game, TimeSpan time)
            {
                var vDelta = this.velocity * time;

                var hitResult = new Ray(this.position, vDelta)
                    .Shoot(game, true, this.collideWithProjectileColliders);

                var f = hitResult.HasValue ? hitResult.Value.RayFactor : 1;

                var zDelta = this.vz * time;

                var z = this.z + zDelta;
                if (z < 0.U())
                {
                    f = this.z / zDelta;
                    z = 0.U();
                    hitResult = new HitResult(this.position + vDelta * f, Direction2.Zero, f, false);
                }

                this.position += vDelta * f;
                this.z = z;

                this.vz += game.Gravity * time;

                return hitResult;
            }
Beispiel #47
0
 public void SetPosition(Position2 position)
 {
     this.Position = position;
     this.update();
 }
Beispiel #48
0
 public CentiPathPart(Position2 position, CentiPathPart previous)
     : this(position, (position - previous.Position).Length)
 {
 }
Beispiel #49
0
        private void updateMovement(TimeSpan elapsedTime)
        {
            var maxMoveThisFrame = new Speed(2) * elapsedTime;

            var differenceToGoal = this.goalPoint - this.Position;
            var distanceToGoal = differenceToGoal.Length;

            if (distanceToGoal < maxMoveThisFrame)
            {
                this.Position = this.goalPoint;
            }
            else
            {
                this.Position += differenceToGoal / distanceToGoal * maxMoveThisFrame;
            }
        }
Beispiel #50
0
 public void SetPosition(Position2 position)
 {
     this.ensureInitilizing();
     this.Position = position;
 }
Beispiel #51
0
 public static void CreatePair(NavQuad quad1, NavQuad quad2, Position2 point0, Position2 point1)
 {
     quad1.Add(new NavLink(quad1, quad2, point0, point1));
     quad2.Add(new NavLink(quad2, quad1, point0, point1));
 }
Beispiel #52
0
 public CentiPathPart(Position2 position, Unit distanceToPrevious)
 {
     this.Position = position;
     this.DistanceToPrevious = distanceToPrevious;
 }