public override void Draw(SpriteBatch spriteBatch) { bool drawPlayer = true; if (Player.immune == true) { currentImmuneTime += mgameTime.ElapsedRealTime.Milliseconds; if (currentImmuneTime >= 50) { drawPlayer = false; } if (currentImmuneTime >= 100) { currentImmuneTime = 0; drawPlayer = true; } } foreach (Bullet aBullet in bulletSprites) { aBullet.Draw(spriteBatch); } if (drawPlayer == true) { base.Draw(spriteBatch); } if (playerState == PlayerState.EXPLODE) { explosionSprite.SpritePosition = this.SpritePosition + new Vector2(18,3); explosionSprite.PlayOnlyOnce = true; explosionSprite.Draw(spriteBatch); } else if (playerState == PlayerState.DIE) { life--; if (life > 0) { Visible = true; playerState = PlayerState.ALIVE; this.SpritePosition = new Vector2(PLAYER_X,PLAYER_Y); this.SpriteSourceRectangle = new Rectangle(0,0,(int)this.Width,(int)this.Height); explosionSprite = new AnimatedSprite(6,15); explosionSprite.Load(mContentManager, @"Textures\explo"); explosionSprite.SpriteSourceRectangle = new Rectangle(0, 0, 55, 52); explosionSprite.PlayOnlyOnce = true; } } for(int i=0;i<life;i++) { playerLife[i].Draw(spriteBatch); } }
/// <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); background = Content.Load<Texture2D>("background1"); background2 = Content.Load<Texture2D>("background2"); Constants.init(ref graphics, ref spriteBatch, Content); plrMap = new TextureMap(Content.Load<Texture2D>("playership1"), 1, 1); laserMap = new TextureMap(Content.Load<Texture2D>("laser1"), 1, 1); enemyMap = new TextureMap(Content.Load<Texture2D>("enemy1"), 1, 1); bossMap = new TextureMap(Content.Load<Texture2D>("boss1"), 1, 1); Constants.player = new Player(Constants.DEFAULT_POSITION, plrMap, laserMap); explosion = new AnimatedSprite(Content.Load<Texture2D>("explosion1"), 1, 10, 55); Constants.mAnimationManager.addAnimation(new Animation(explosion, new Vector2(200.0f, 200.0f))); bg2pos = new Vector2(0.0f, -800.0f); Constants.mMainGameScreen = new GameScreen(ref spriteBatch, ref Constants.player, enemyMap, laserMap, bossMap, "background1", "background2"); Constants.mSplashScreen = new SplashScreen("splashscreen1", ref spriteBatch, "Press Space To Begin"); Constants.mEndScreenLose = new SplashScreen("splashscreen3", ref spriteBatch, "Press Escape To Exit"); Constants.mEndScreenWin = new SplashScreen("splashscreen2", ref spriteBatch, "Press Escape To Exit"); Vector2 menuPos = new Vector2((graphics.PreferredBackBufferWidth / 2)-32.0f, (graphics.PreferredBackBufferHeight * 0.33f)); List<Button> btns = new List<Button>(); btns.Add(new Button(new TextureMap(Content.Load<Texture2D>("ButtonStart"), 1, 1), new Vector2(menuPos.X, menuPos.Y), this.startGame)); btns.Add(new Button(new TextureMap(Content.Load<Texture2D>("ButtonQuit"), 1, 1), new Vector2(menuPos.X, menuPos.Y + 36), this.Exit)); Constants.mMenuScreen = new MenuScreen(ref spriteBatch, btns); Constants.mScreenStack.push(Constants.mSplashScreen); mSoundMgr = new SoundManager(); // TODO: use this.Content to load your game content here }
public Animation(AnimatedSprite sprite, Vector2 loc) { Sprite = sprite; Location = loc; }