Exemple #1
0
        //------------------------------------------------------//

        private void timer1_Tick(object sender, EventArgs e)
        {
            var collisionStatus = CollisionStatus.contact(player, Block1);

            if (!collisionStatus.canIncX)
            {
                right = false;
            }

            if (!collisionStatus.canDecX)
            {
                left = false;
            }

            if (right == true)
            {
                player.Left += 5;
            }
            if (left == true)
            {
                player.Left -= 5;
            }

            if (jump == true)
            {
                //falling if the player has jumped before
                player.Top -= Force;
                Force      -= 5;
            }


            if (player.Top + player.Height >= screen.Height)
            {
                player.Top = screen.Height - player.Height; //Stop falling at bottom
                jump       = false;
            }
            else
            {
                player.Top += 5; //falling
            }
        }
Exemple #2
0
        public static CollisionStatus contact(System.Windows.Forms.PictureBox player, System.Windows.Forms.PictureBox thing2)
        {
            CollisionStatus result      = new CollisionStatus();
            bool            fullyLeft   = player.Left < thing2.Left && player.Right < thing2.Left;
            bool            fullyRight  = player.Left > thing2.Right && player.Right > thing2.Right;
            bool            fullyTop    = player.Top < thing2.Top && player.Bottom < thing2.Top;
            bool            fullyBottom = player.Top > thing2.Bottom && player.Bottom > thing2.Bottom;

            if (fullyLeft || fullyRight || fullyTop || fullyBottom)
            {
                return(result);
            }
            if (!fullyTop && !fullyBottom && player.Right >= thing2.Left)
            {
                result.canIncX = false;
            }

            if (!fullyTop && !fullyBottom && player.Left <= thing2.Right)
            {
                result.canDecX = false;
            }

            return(result);
        }