Code/PhysicHelper.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FlappyBird.Code.Basic;

namespace FlappyBird.Code
{
    class PhysicHelper
    {
        public static bool IsHit(Shape shape1, Shape shape2)
        {
            int dec1 = Math.Abs(shape1.X - shape2.X);//取两者横坐标之差
            int width = shape1.X < shape2.X ? shape1.Width : shape2.Width;
            int dec2 = Math.Abs(shape1.Y - shape2.Y);
            int height = shape1.Y < shape2.Y ? shape1.Height : shape2.Height;
            if (dec1 < width && dec2 < height)
            {
                return true;//碰撞
            }
            
            return false;
        }

        public static bool IsHit(Bird bird, Map map)
        {
            foreach (var item in map.Pares)
            {
                if (IsHit(bird, item.UpPipe) || IsHit(bird, item.DownPipe))
                {
                    return true;
                }
            }
            if (bird.Y >= 533 - bird.Height)
            {
                return true;
            }
          
            return false;
        }

        /// <summary>
        /// 根据初速度和加速度以及时间间隔,得到位移量
        /// </summary>
        /// <param name="Vo">初速度 像素/秒</param>
        /// <param name="a">像素/平方秒</param>
        /// <returns></returns>
        public static double GetDistance(double Vo, double a, TimeSpan ts)
        {
            double sec = ts.TotalSeconds;
            return Vo * sec + 1.0 / 2.0 * a * sec * sec;
        }

        public static double GetVo(double Vo, double a, TimeSpan ts)
        {
            return Vo + a * ts.TotalSeconds;
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。