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); }
protected override void LoadContent() { sb = new SpriteBatch(Game.GraphicsDevice); font = Resourse.getInstance().startFont; base.LoadContent(); }
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); }
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(); }
protected override void LoadContent() { sb = new SpriteBatch(Game.GraphicsDevice); font = Resourse.getInstance().startFont; stringRect = new Rectangle((int)(Game.Window.ClientBounds.Width / 2 - font.MeasureString(str).X / 2), (int)(Game.Window.ClientBounds.Height / 2 - font.MeasureString(str).Y / 2), (int)(font.MeasureString(str).X), (int)(font.MeasureString(str).Y)); }
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(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); ScoreBoard.init(Resourse.getInstance().scoreFont, Resourse.getInstance().bigFont); bgm = Resourse.getInstance().bgm.CreateInstance(); base.LoadContent(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here startComponent = new StartComponent(this); gameComponent = new MyGameComponent(this); endComponent = new EndComponent(this); Components.Add(startComponent); Resourse.init(Content); //初始化全局纹理类 ,应该放在LoadContent里,但测试的时候发现会空指针,应该是先执行了 Components的LoadContent,才会这样 this.IsMouseVisible = true; base.Initialize(); }
public static void init(ContentManager cm) { instance = new Resourse( cm.Load <Texture2D>(@"Images\\bg"), cm.Load <Texture2D>(@"Images\\ball"), cm.Load <Texture2D>(@"Images\\player"), cm.Load <SpriteFont>(@"Fonts\\BigFont"), cm.Load <SpriteFont>(@"Fonts\\ScoreFont"), cm.Load <SpriteFont>(@"Fonts\\StartFont"), cm.Load <SoundEffect>(@"Sound\\eat"), cm.Load <SoundEffect>(@"Sound\\dead"), cm.Load <SoundEffect>(@"Sound\\end"), cm.Load <SoundEffect>(@"Sound\\bgm"), cm.Load <SoundEffect>(@"Sound\\levelUp"), cm.Load <SoundEffect>(@"Sound\\victory") ); }
public void dead() { //死亡 life--; if (life <= 0) { Game1.gameState = 2; Resourse.getInstance().endSound.Play();//播放死亡音效 return; } Resourse.getInstance().deadSound.Play(); val = 50; postion.X = WallManager.wallRect.Height / 2; postion.Y = WallManager.wallRect.Width / 2; ((PlayerImpact)impactInterface).detaTime = 1; }
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 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); }
public void initFactory() { //初始化工厂 //f1 生产随机位置和随机方向的鱼,吃掉后加分 f1 = new BallFactory(Resourse.getInstance().baseBallTexture, Color.White, "", "RandomRoad"); //f2 生产幕布式的鱼,吃掉后加分 f2 = new BallFactory(Resourse.getInstance().baseBallTexture, Color.White, "", "LinerRoad"); //f3 生产冲锋式的鱼,会向玩家冲去,吃掉后加分 f3 = new BallFactory(Resourse.getInstance().baseBallTexture, Color.White, "", "Rush"); //f4 生产随机位置和随机方向的鱼,吃掉后减分 f4 = new BallFactory(Resourse.getInstance().baseBallTexture, Color.White, "SubImpact", "RandomRoad"); //f5 生产幕布式的鱼,吃掉后减分 f5 = new BallFactory(Resourse.getInstance().baseBallTexture, Color.White, "SubImpact", "LinerRoad"); //f6 生产冲锋式的鱼,会向玩家冲去,吃掉后减分 f6 = new BallFactory(Resourse.getInstance().baseBallTexture, Color.White, "SubImpact", "Rush"); }
public override void addVal(int add, bool isSound = true) { if (isSound == false) { base.addVal(add); } else { if (add > 0) { Resourse.getInstance().eat.Play(); } else { Resourse.getInstance().deadSound.Play(); } base.addVal(add); } if (val <= 0) { dead(); } }
public static void init(Texture2D bg, Texture2D t1, Texture2D t2) { instance = new Resourse(bg, t1, t2); }
public static void init(Texture2D bg,Texture2D t1, Texture2D t2) { instance = new Resourse(bg,t1,t2); }
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; }
private PlayerBall(Vector2 postion, int speed, Resourse.MyTexture myTexture,int val) : base(Color.White,postion,speed, myTexture,val) { }