예제 #1
0
        public override void Draw(GameTime gameTime)
        {
            sb.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);


            sb.Draw(Resourse.getInstance().gameBackground.texture,
                    Vector2.Zero,
                    new Rectangle(0, 0,
                                  Resourse.getInstance().gameBackground.frameSize.X,
                                  Resourse.getInstance().gameBackground.frameSize.Y),
                    Color.White,
                    0,
                    Vector2.Zero,
                    1,
                    SpriteEffects.None,
                    0);



            PlayerBall.getInstance().Draw(sb);
            foreach (BaseBall ball in ballList)
            {
                ball.Draw(sb);
            }

            //计分板
            ScoreBoard.getInstance().onDraw(sb);
            sb.End();

            base.Draw(gameTime);
        }
예제 #2
0
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(r);
            Color  c = new Color(1, 1, 1);
            String str;

            switch (Game1.gameState)
            {
            case 2:
                //玩家死亡
                str = "you dead! \nyou get " + PlayerBall.getInstance().getVal() + " !";
                break;

            case 3:
                //通关
                str = "you win! \nyou get " + PlayerBall.getInstance().getVal() + " !";
                break;

            default:
                str = "";
                break;
            }

            sb.Begin();

            sb.DrawString(font, str, new Vector2(Game.Window.ClientBounds.Width / 2 - font.MeasureString(str).X / 2,
                                                 Game.Window.ClientBounds.Height / 2 - font.MeasureString(str).Y / 2), Color.Black);

            sb.End();
            base.Draw(gameTime);
        }
예제 #3
0
        protected override void LoadContent()
        {
            wallmg = new WallManager(Game.Window.ClientBounds);
            sb     = new SpriteBatch(Game.GraphicsDevice);
            PlayerBall.init(new Vector2(100, 100), 6, Resourse.getInstance().playerBallTexture, 50);

            base.LoadContent();
        }
예제 #4
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();
 }
예제 #5
0
        public void check()
        {
            PlayerBall player = PlayerBall.getInstance();

            if (player.getVal() >= getCurrentChapterPoint())
            {
                level++;
            }

            if (level == chapters.Count)
            {
                //TODO:游戏胜利
            }
        }
예제 #6
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);
        }
예제 #7
0
        public void check()
        {
            PlayerBall player = PlayerBall.getInstance();

            if (ScoreBoard.getInstance().addScore(0) >= getCurrentChapterPoint())
            {
                level++;
                Resourse.getInstance().levelUp.Play();
                if (level >= 2)
                {
                    PlayerBall.getInstance().addVal(-50, false);
                }
            }

            if (level == chapters.Count)
            {
                Game1.gameState = 3;
            }
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
0
 public static void init(Vector2 postion, int speed, Resourse.MyTexture myTexture, int val)
 {
     bb = new PlayerBall(postion, speed, myTexture, val);
     bb.setImpact(new PlayerImpact(bb));
     life = DEF_LIFE;
 }
예제 #11
0
 public static void init(Vector2 postion, int speed, Resourse.MyTexture myTexture, int val)
 {
     bb = new PlayerBall(postion, speed, myTexture, val);
     bb.setImpact(new PlayerImpact(bb));
     life = DEF_LIFE;
 }
예제 #12
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);
        }
예제 #13
0
 public void upDate()
 {
     score = PlayerBall.getInstance().getVal();
 }