Exemplo n.º 1
0
 public void playGame()
 {
     gameState = 1;//进入游戏状态
     Components.RemoveAt(0);
     Components.Add(gameComponent);
     Chapters.getInstance().init();
     ScoreBoard.getInstance().init();
     gameComponent.clear();
     PlayerBall.init(new Vector2(100, 100), 6, Resourse.getInstance().playerBallTexture, 50);
     bgm.Play();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }
            KeyboardState keystate = Keyboard.GetState();

            switch (gameState)
            {
            case 0:

                //如果在开始画面
                if (keystate.IsKeyDown(Keys.Enter))
                {
                    gameState = 1;    //进入游戏状态
                    Components.RemoveAt(0);
                    Components.Add(gameComponent);
                    PlayerBall.init(new Vector2(100, 100), 6, Resourse.getInstance().playerBallTexture, 50);
                }
                break;

            case 1:
                break;

            case 2:
            case 3:
                gameState = 0;
                Components.RemoveAt(0);
                Components.Add(startComponent);
                PlayerBall.init(new Vector2(100, 100), 6, Resourse.getInstance().playerBallTexture, 50);
                Chapters.getInstance().init();
                gameComponent.clear();
                break;
            }



            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Exemplo n.º 3
0
        public void onDraw(SpriteBatch sb)
        {
            sb.DrawString(
                font,
                "score:" + score.ToString() + " \n life:" + PlayerBall.getInstance().getLife().ToString(),
                Vector2.Zero,
                Color.White,
                0,
                Vector2.Zero,
                1,
                SpriteEffects.None,
                1);

            sb.DrawString(
                bigFont,
                Chapters.getInstance().getLevel() + "",
                new Vector2(WallManager.wallRect.Width / 2, WallManager.wallRect.Height / 2),
                Chapters.getInstance().getCurrentChapterColor(),
                0,
                Vector2.Zero,
                1,
                SpriteEffects.None,
                1);
        }
Exemplo 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);
        }