public override void Draw(GameTime gameTime) { GraphicsDevice.Clear(r); String str; switch (Game1.gameState) { case 2: //玩家死亡 str = "you dead! \nyou get " + ScoreBoard.getInstance().addScore(0) + " !"; break; case 3: //通关 str = "you win! \nyou get " + ScoreBoard.getInstance().addScore(0) + " !"; Resourse.getInstance().victory.Play(); break; default: str = ""; break; } str += "\n\nEnter for Retry"; 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); }
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); }
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(); }
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; } }
/// <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); }