コード例 #1
0
 public void SetPosition(PointF pos)
 {
     // fix float errors by rounding
     pos.X = (float)Math.Round(pos.X, 3);
     pos.Y = (float)Math.Round(pos.Y, 3);
     Position = pos;
 }
コード例 #2
0
        public void SetPositionWithValues()
        {
            var start = new PointF(0, 0);
            var end = new PointF(5.1f, 3.66f);

            Assert.AreEqual(start, _position.Position);
            _position.SetPosition(5.1f, 3.66f);
            Assert.AreEqual(end, _position.Position);
        }
コード例 #3
0
        public void Offset()
        {
            var start = new PointF(0, 0);
            var end = new PointF(5.1f, 3.66f);

            Assert.AreEqual(start, _position.Position);
            _position.Offset(2.4f, 1.92f);
            _position.Offset(2.7f, 1.74f);
            Assert.AreEqual(end.X, _position.Position.X, 0.00001);
            Assert.AreEqual(end.Y, _position.Position.Y, 0.00001);
        }
コード例 #4
0
        public override void BeginScroll(ScreenHandler next, PointF playerPos)
        {
            doorOne.SendMessage(new StateMessage(null, "Opening"));
            if (direction == Direction.Down) triggerSize = (int)(height - playerPos.Y);
            else if (direction == Direction.Left) triggerSize = (int)playerPos.X;
            else if (direction == Direction.Right) triggerSize = (int)(width - playerPos.X);
            else triggerSize = (int)playerPos.Y;

            base.BeginScroll(next, playerPos);

            if (doorTwo != null)
            {
                doorTwo.SendMessage(new StateMessage(null, "Open"));
            }
        }
コード例 #5
0
        public override bool Trigger(PointF position)
        {
            if (direction == Direction.Right || direction == Direction.Down)
            {
                if (JoinInfo.direction == JoinDirection.BackwardOnly) return false;
            }
            else if (JoinInfo.direction == JoinDirection.ForwardOnly) return false;

            return (doorOne.GetComponent<CollisionComponent>()).TouchedBy("Player");
        }
コード例 #6
0
ファイル: Math.cs プロジェクト: laazer/cs_megaman
 public void Offset(PointF pos)
 {
     this.Offset(pos.X, pos.Y);
 }
コード例 #7
0
ファイル: Math.cs プロジェクト: laazer/cs_megaman
 public bool Contains(PointF pt)
 {
     return this.Contains(pt.X, pt.Y);
 }
コード例 #8
0
ファイル: HitBox.cs プロジェクト: Tesserex/C--MegaMan-Engine
 public virtual RectangleF BoxAt(PointF offset, bool vflip)
 {
     if (vflip) return new RectangleF(box.X + offset.X, offset.Y - box.Y - box.Height, box.Width, box.Height);
     return new RectangleF(box.X + offset.X, box.Y + offset.Y, box.Width, box.Height);
 }
コード例 #9
0
 private void CheckEnvironmentTile(List<MapSquare> hitSquares, CollisionBox hitbox, RectangleF hitRect, MapSquare tile, ref PointF offset)
 {
     if (hitbox.EnvironmentCollisions(PositionSrc.Position, tile, ref offset))
     {
         hitSquares.Add(tile);
         if (hitbox.PushAway) PositionSrc.Offset(offset.X, offset.Y);
     }
     else if (hitRect.IntersectsWith(tile.BoundBox))
     {
         hitSquares.Add(tile);
     }
 }
コード例 #10
0
ファイル: CollisionBox.cs プロジェクト: laazer/cs_megaman
        // change those last bools into an enum or something else!
        public PointF GetIntersectionOffset(RectangleF tileBox, RectangleF boundBox, float approach_vx, float approach_vy, bool uponly, bool downonly)
        {
            float top = -1, bottom = -1, left = -1, right = -1;
            RectangleF intersection = RectangleF.Intersect(boundBox, tileBox);

            PointF offset = new PointF(0, 0);
            if (intersection.Width == 0 && intersection.Height == 0) return offset;

            if (Math.Abs(intersection.Bottom - boundBox.Bottom) < Const.PixelEpsilon) bottom = intersection.Height;
            if (Math.Abs(intersection.Top - boundBox.Top) < Const.PixelEpsilon) top = intersection.Height;

            if (Math.Abs(intersection.Right - boundBox.Right) < Const.PixelEpsilon) right = intersection.Width;
            if (Math.Abs(intersection.Left - boundBox.Left) < Const.PixelEpsilon) left = intersection.Width;

            if (top > 0 || bottom > 0 || left > 0 || right > 0)
            {
                bool vert = CollisionComponent.VerticalApproach(intersection, boundBox, approach_vx, approach_vy);

                if (vert)
                {
                    if (downonly)
                    {
                        if (approach_vy > 0 && boundBox.Bottom <= tileBox.Bottom)
                        {
                            offset.Y = -bottom;
                            return offset;
                        }
                        else return new PointF(0, 0);
                    }
                    else if (uponly)
                    {
                        if (approach_vy < 0 && boundBox.Top >= tileBox.Top)
                        {
                            offset.Y = top;
                            return offset;
                        }
                        else return new PointF(0, 0);
                    }

                    if (top >= 0) offset.Y = top;
                    if (bottom >= 0) offset.Y = -bottom;
                }
                else
                {
                    if (uponly || downonly) return new PointF(0, 0);
                    if (left >= 0)
                    {
                        if (approach_vx < 0) offset.X = left;
                    }
                    if (right >= 0)
                    {
                        if (approach_vx > 0) offset.X = -right;
                    }
                }
            }

            return offset;
        }
コード例 #11
0
ファイル: CollisionBox.cs プロジェクト: laazer/cs_megaman
        public bool EnvironmentCollisions(PointF position, IMapSquare square, ref PointF offset)
        {
            offset.X = 0;
            offset.Y = 0;
            // some optimizations
            RectangleF tileBox = square.BlockBox;
            if (box.Right + position.X < tileBox.Left) return false;
            if (box.Left + position.X > tileBox.Right) return false;
            RectangleF boundBox = BoxAt(position);

            return EnvironmentContact(square, tileBox, boundBox, out offset);
        }
コード例 #12
0
ファイル: CollisionBox.cs プロジェクト: laazer/cs_megaman
        public override RectangleF BoxAt(PointF offset, bool vflip)
        {
            float x = (parentComponent.MovementSrc != null && parentComponent.MovementSrc.Direction == Direction.Left) ? offset.X - box.X - box.Width : box.X + offset.X;

            if (vflip) return new RectangleF(x, offset.Y - box.Y - box.Height, box.Width, box.Height);
            return new RectangleF(x, box.Y + offset.Y, box.Width, box.Height);
        }
コード例 #13
0
ファイル: CollisionBox.cs プロジェクト: laazer/cs_megaman
        public RectangleF BoxAt(PointF offset)
        {
            float x = (parentComponent.MovementSrc != null && parentComponent.MovementSrc.Direction == Direction.Left) ? offset.X - box.X - box.Width : box.X + offset.X;

            if (parentComponent.Parent.IsGravitySensitive && parentComponent.Parent.Container.IsGravityFlipped) return new RectangleF(x, offset.Y - box.Y - box.Height, box.Width, box.Height);
            return new RectangleF(x, box.Y + offset.Y, box.Width, box.Height);
        }
コード例 #14
0
        public virtual bool Trigger(PointF position)
        {
            if (direction == Direction.Right || direction == Direction.Down)
            {
                if (JoinInfo.direction == JoinDirection.BackwardOnly) return false;
            }
            else if (JoinInfo.direction == JoinDirection.ForwardOnly) return false;

            return (position.X >= threshXmin && position.X <= threshXmax &&
                    position.Y >= threshYmin && position.Y <= threshYmax);
        }
コード例 #15
0
        public virtual void BeginScroll(ScreenHandler next, PointF playerPos)
        {
            scrollDist = 0;

            tickdist = (TriggerSize() + OffsetDist()) / ticks;

            this.nextHeight = next.Screen.PixelHeight;
            this.nextWidth = next.Screen.PixelWidth;

            if (direction == Direction.Down) NextScreenY = -height;
            else if (direction == Direction.Right) NextScreenX = -width;
            else if (direction == Direction.Left) NextScreenX = nextWidth;
            else if (direction == Direction.Up) NextScreenY = nextHeight;

            Calculate();
        }
コード例 #16
0
ファイル: CollisionBox.cs プロジェクト: laazer/cs_megaman
        private bool EnvironmentContact(IMapSquare square, RectangleF tileBox, RectangleF boundBox, out PointF offset)
        {
            // can't use intersection, use epsilon
            offset = PointF.Empty;
            if (tileBox.Top < boundBox.Top)
            {
                if (tileBox.Bottom - boundBox.Top + Const.PixelEpsilon <= 0) return false;
            }
            else
            {
                if (boundBox.Bottom - tileBox.Top + Const.PixelEpsilon <= 0) return false;
            }
            if (tileBox.Left < boundBox.Left)
            {
                if (tileBox.Right - boundBox.Left + Const.PixelEpsilon <= 0) return false;
            }
            else
            {
                if (boundBox.Right - tileBox.Left + Const.PixelEpsilon <= 0) return false;
            }

            bool down = (!parentComponent.Parent.Container.IsGravityFlipped && square.Properties.Climbable);
            bool up = (parentComponent.Parent.Container.IsGravityFlipped && square.Properties.Climbable);

            if (parentComponent.MovementSrc != null) offset = GetIntersectionOffset(tileBox, boundBox, parentComponent.MovementSrc.VelocityX, parentComponent.MovementSrc.VelocityY, up, down);
            else offset = GetIntersectionOffset(tileBox, boundBox, 0, 0, up, down);

            // Quicksand sinking property tells us not to push the hitbox outward
            if (square.Properties.Sinking > 0)
            {
                // don't clip left or right at all
                offset.X = 0;

                if (parentComponent.Parent.Container.IsGravityFlipped)
                {
                    // don't clip them downward out of the collision
                    if (offset.Y > 0)
                    {
                        offset.Y = 0;
                    }
                }
                else
                {
                    // don't clip them upward out of the collision
                    if (offset.Y < 0)
                    {
                        offset.Y = 0;
                    }
                }
            }

            return true;
        }
コード例 #17
0
 public void Offset(float x, float y)
 {
     Position = new PointF(Position.X + x, Position.Y + y);
 }
コード例 #18
0
ファイル: ScreenHandler.cs プロジェクト: laazer/cs_megaman
        public void Draw(GameRenderEventArgs renderArgs, PointF playerPos, float adj_x = 0, float adj_y = 0, float off_x = 0, float off_y = 0)
        {
            int width = Screen.PixelWidth;
            int height = Screen.PixelHeight;

            if (!isAutoscrolling)
            {
                OffsetX = OffsetY = 0;

                centerX = playerPos.X + adj_x;
                centerY = playerPos.Y + adj_y;

                if (centerX > Game.CurrentGame.PixelsAcross / 2)
                {
                    OffsetX = centerX - Game.CurrentGame.PixelsAcross / 2;
                    if (OffsetX > width - Game.CurrentGame.PixelsAcross)
                        OffsetX = width - Game.CurrentGame.PixelsAcross;
                }

                if (centerY > Game.CurrentGame.PixelsDown / 2)
                {
                    OffsetY = centerY - Game.CurrentGame.PixelsDown / 2;
                    if (OffsetY > height - Game.CurrentGame.PixelsDown)
                        OffsetY = height - Game.CurrentGame.PixelsDown;
                    if (OffsetY < 0) OffsetY = 0;
                }

                OffsetX += off_x;
                OffsetY += off_y;
            }

            foreach (var layer in this.layers)
            {
                layer.Draw(renderArgs, this.Screen.PixelWidth);
            }
        }
コード例 #19
0
        private void CheckEnvironment(List<MapSquare> hitSquares, CollisionBox hitbox)
        {
            PointF offset = new PointF(0, 0);
            RectangleF hitRect = hitbox.BoxAt(PositionSrc.Position);

            // this bounds checking prevents needlessly checking collisions way too far away
            // it's a very effective optimization (brings busy time from ~60% down to 45%!)
            int size = Parent.Screen.TileSize;

            for (float y = hitRect.Top - size; y < hitRect.Bottom; y += size)
            {
                for (float x = hitRect.Left - size; x < hitRect.Right; x += size)
                {
                    var tile = Parent.Screen.SquareAt(x, y);
                    if (tile == null) continue;

                    CheckEnvironmentTile(hitSquares, hitbox, hitRect, tile, ref offset);
                }

                var rightEdge = Parent.Screen.SquareAt(hitRect.Right, y);
                if (rightEdge != null)
                {
                    CheckEnvironmentTile(hitSquares, hitbox, hitRect, rightEdge, ref offset);
                }
            }

            for (float x = hitRect.Left - size; x < hitRect.Right; x += size)
            {
                var tile = Parent.Screen.SquareAt(x, hitRect.Bottom);
                if (tile == null) continue;

                CheckEnvironmentTile(hitSquares, hitbox, hitRect, tile, ref offset);
            }

            var lastCorner = Parent.Screen.SquareAt(hitRect.Right, hitRect.Bottom);
            if (lastCorner != null)
            {
                CheckEnvironmentTile(hitSquares, hitbox, hitRect, lastCorner, ref offset);
            }
        }