Esempio n. 1
0
        public BaseBall getBaseBall()
        {
            times++;
            if (times < getCurrentChapterGenRate())
            {
                return(null);
            }
            times = 0;

            BaseBall gBall = null;


            int        sum   = 0;
            Random     r     = new Random();//随机数,用于随机取一个球
            List <int> rates = getCurrentChapter().rates;

            foreach (int each in rates)
            {
                sum += each;
            }

            int ran = r.Next(0, sum);

            int datVal = r.Next(3) == 1?-10:10;

            int a = 0;

            for (int i = 0; i < rates.Count; i++)
            {
                if (a <= ran && (a + rates[i]) >= ran)
                {
                    gBall = getCurrentChapter().ballsf[i].built(PlayerBall.getInstance().getVal() + r.Next(8) * datVal);
                    break;
                }
                a += rates[i];
            }



            gBall.setSpeed(getCurrentChapterSpeed());


            return(gBall);
        }
Esempio n. 2
0
        public Boolean checkBall(BaseBall ball)
        {
            if (ball is PlayerBall)
            {
                Vector2 oldPo = ball.getPosition();

                if (oldPo.X < 0)
                {
                    oldPo.X = wallRect.Width - ball.getRect().Width;
                }
                if (oldPo.Y < 0)
                {
                    oldPo.Y = 0;
                }
                if (oldPo.X > (wallRect.Width - ball.getRect().Width))
                {
                    oldPo.X = (ball.getRect().Width);
                }
                if (oldPo.Y > (wallRect.Height - ball.getRect().Height))
                {
                    oldPo.Y = (wallRect.Height - ball.getRect().Height);
                }


                ball.setPosition(oldPo);
                return(true);
            }
            else
            {
                Vector2 oldPo = ball.getPosition();

                if (oldPo.X < 0 || oldPo.Y < 0 || oldPo.X > wallRect.Width - ball.getRect().Width || oldPo.Y > wallRect.Height - ball.getRect().Height)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Esempio n. 3
0
 public Boolean impactBall(BaseBall ball)
 {
     return(impactInterface.impact(ball));
 }
Esempio n. 4
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here



            List <BaseBall> removeList = new List <BaseBall>();

            PlayerBall.getInstance().upDate(Game.Window.ClientBounds);

            ScoreBoard.getInstance().upDate();

            if (wallmg.checkBall(PlayerBall.getInstance()))
            {
                //越界要做的事情,默认把位置修改回
            }

            foreach (BaseBall ball in ballList)
            {
                ball.upDate(Game.Window.ClientBounds);


                if (ball.getRect().Intersects(PlayerBall.getInstance().getRect()))
                {
                    if (ball.impactBall(PlayerBall.getInstance()))
                    {
                        //小球被吃
                        removeList.Add(ball);
                    }
                    else
                    {
                        //被大的球吃到了
                        if (PlayerBall.getInstance().impactBall(ball))
                        {//交给player处理事件,返回true表示游戏结束
                         //玩家死亡
                        }
                        removeList.Add(ball);
                    }
                }


                if (!wallmg.checkBall(ball) && ball.isOutDo()) //检测超界,并且交给球处理超界事件
                {                                              //检测是否超出边界
                    removeList.Add(ball);
                }
            }

            foreach (BaseBall rball in  removeList)
            {
                ballList.Remove(rball);//删除超出边界的球
            }

            //交给关卡类 随机生成球
            BaseBall newball = Chapters.getInstance().getBaseBall();

            if (newball != null)
            {
                ballList.Add(newball);
            }

            Chapters.getInstance().check();

            base.Update(gameTime);
        }