예제 #1
0
파일: Battle2.cs 프로젝트: nubington/bill
        public override void Draw(SpriteBatch spriteBatch)
        {
            Game1.Game.DebugMonitor.AddLine(Bullet.Peanuts.Count + " peanuts.");
            Game1.Game.DebugMonitor.AddLine(Fireball.Fireballs.Count + " fireballs.");
            Game1.Game.DebugMonitor.AddLine(Laser2.Lasers.Count + " lasers.");
            Game1.Game.DebugMonitor.AddLine(MouseSeeker.MouseSeekers.Count + " mice.");

            GraphicsDevice.Clear(Color.Gray);

            // powerups
            foreach (PowerUp p in PowerUp.AlivePowerUps)
            {
                spriteBatch.Draw(p.Texture, p, Color.White);
            }

            // powerup time bars
            foreach (PowerUp p in PowerUp.AlivePowerUps)
            {
                spriteBatch.Draw(powerUpBarTexture, new Rectangle(p.X, p.Y + p.Height - p.Height / 15, (int)(p.Width * p.RemainingTimeAlive / p.AliveDuration), p.Height / 15), Color.White);
            }

            // alex
            // new Color(255, 255, 255, (byte)MathHelper.Clamp(100, 0, 255))
            spriteBatch.Draw(alex.Texture, alex, Color.White);

            // alex's peanut shield
            if (alex is AlexEnchanter && ((AlexEnchanter)alex).IsCastingPeanutShield || ((AlexEnchanter)alex).HasPeanutShield)
            {
                spriteBatch.Draw(((AlexEnchanter)alex).PeanutShield, ((AlexEnchanter)alex).PeanutShield, Color.White);
            }

            // isaac
            if (isaacHurtAnimation.IsRunning)
            {
                spriteBatch.Draw(isaacHurtAnimation, isaac, Color.White);
            }
            else
            {
                spriteBatch.Draw(isaac.Texture, isaac, Color.White);
            }

            // potions
            foreach (Potion p in Potion.Potions)
            {
                spriteBatch.Draw(p.Texture, p, Color.White);
            }

            // fireballs
            foreach (Fireball fireball in Fireball.Fireballs)
            {
                spriteBatch.Draw(fireball.Texture, new Rectangle((int)fireball.CenterPoint.X, (int)fireball.CenterPoint.Y, fireball.Width, fireball.Height), null, Color.White, fireball.Rotation, fireball.TextureCenterOrigin, SpriteEffects.None, 0f);
            }

            // lasers
            foreach (Laser2 laser in Laser2.Lasers)
            {
                laser.Draw(spriteBatch);
            }

            // mouse seekers
            SeekerSnake.DrawSeekerSnakes(spriteBatch);

            // staff
            if (alex is AlexEnchanter && ((AlexEnchanter)alex).IsUsingStaff)
            {
                BaseObject staff = ((AlexEnchanter)alex).MagicStaff;
                spriteBatch.Draw(staff.Texture, new Rectangle(staff.X, staff.Y, staff.Width, staff.Height), null, Color.White, staff.Rotation, new Vector2(0, staff.Texture.Height / 2), SpriteEffects.None, 0f);
            }

            // peanuts
            foreach (Bullet b in Bullet.Peanuts)
            {
                spriteBatch.Draw(b.Texture, new Rectangle((int)b.CenterPoint.X, (int)b.CenterPoint.Y, b.Width, b.Height), null, Color.White, b.Rotation, b.TextureCenterOrigin, SpriteEffects.None, 0f);
            }
            // shrinking peanuts
            foreach (Bullet b in shrinkingPeanuts)
            {
                spriteBatch.Draw(b.Texture, new Rectangle((int)b.CenterPoint.X, (int)b.CenterPoint.Y, b.Width, b.Height), null, Color.White, b.Rotation, b.TextureCenterOrigin, SpriteEffects.None, 0f);
            }
            // burning peanuts
            foreach (Bullet b in burningPeanuts)
            {
                spriteBatch.Draw(b.Texture, new Rectangle((int)b.CenterPoint.X, (int)b.CenterPoint.Y, b.Width, b.Height), null, Color.White, b.Rotation, b.TextureCenterOrigin, SpriteEffects.None, 0f);
            }

            // sledgehammer
            if (sledgeHammerInUse)
            {
                spriteBatch.Draw(sledgeHammer.Texture, new Rectangle((int)isaac.CenterPoint.X, (int)isaac.CenterPoint.Y, sledgeHammer.Width, sledgeHammer.Height), null, Color.White, sledgeHammer.Rotation, new Vector2(sledgeHammer.Texture.Width / 2, sledgeHammer.Texture.Height), SpriteEffects.None, 0f);
            }

            // hearts
            drawHearts(spriteBatch);

            // active powerup info
            int offset = HEARTHEIGHT + 10;

            foreach (PowerUp p in isaac.ActivePowerUps)
            {
                string msg = p.ToString();
                spriteBatch.DrawString(powerUpFont, msg, new Vector2(5, offset), Color.Black);
                offset += (int)powerUpFont.MeasureString(msg).Y;
            }

            // alex health bar
            int hpBarX     = Graphics.GraphicsDevice.Viewport.Width / 2 - alexHealthBar.Width / 2;
            int hpBarY     = 8;
            int borderSize = 2;

            spriteBatch.Draw(ColorTexture.Black, new Rectangle(hpBarX - borderSize, hpBarY - borderSize, alexHealthBar.Width + borderSize * 2, alexHealthBar.Height + borderSize * 2), Color.White);
            spriteBatch.Draw(ColorTexture.Gray, new Rectangle(hpBarX, hpBarY, alexHealthBar.Width, alexHealthBar.Height), Color.White);
            spriteBatch.Draw(ColorTexture.Red, new Rectangle(hpBarX, hpBarY, (alexHealthBar.Width * alex.HP / alex.MaxHP), alexHealthBar.Height), Color.White);
            //spriteBatch.Draw(HealthBar.Texture, new Rectangle(hpBarX, hpBarY, alexHealthBar.Width, alexHealthBar.Height), new Rectangle(0, 45, alexHealthBar.Width, 44), Color.Gray);
            //spriteBatch.Draw(HealthBar.Texture, new Rectangle(hpBarX, hpBarY, (alexHealthBar.Width * alex.HP / alex.MaxHP), alexHealthBar.Height), new Rectangle(0, 45, alexHealthBar.Width, 44), Color.Red);
            //spriteBatch.Draw(HealthBar.Texture, new Rectangle(hpBarX, hpBarY, alexHealthBar.Width, alexHealthBar.Height), new Rectangle(0, 0, HealthBar.Texture.Width, 44), Color.White);

            /*PrimitiveLine line = new PrimitiveLine(GraphicsDevice, 1);
             * line.AddVector(new Vector2(hpBarX, hpBarY + 1));
             * line.AddVector(new Vector2(hpBarX + alexHealthBar.Width, hpBarY + 1));
             * line.AddVector(new Vector2(hpBarX + alexHealthBar.Width, hpBarY + alexHealthBar.Height));
             * line.AddVector(new Vector2(hpBarX, hpBarY + alexHealthBar.Height));
             * line.AddVector(new Vector2(hpBarX, hpBarY + 1));
             * line.Colour = Color.Black;
             * line.Render(spriteBatch);*/

            //pause and fps count
            Vector2 pauseStringSize = pauseFont.MeasureString("PAUSED");

            if (paused)
            {
                spriteBatch.DrawString(pauseFont, "PAUSED", new Vector2(Graphics.GraphicsDevice.Viewport.Width / 2 - pauseStringSize.X / 2, Graphics.GraphicsDevice.Viewport.Height / 2 - pauseStringSize.Y / 2), Color.White);
            }
            else
            {
                frameCounter++;
            }
        }
예제 #2
0
파일: Battle2.cs 프로젝트: nubington/bill
        public override void Update(GameTime gameTime)
        {
            // check for exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                Game1.Game.Exit();
            }
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape))
            {
                cleanup();
                returnControl("title");
                return;
            }

            // mute check
            checkForMute();

            // pause check
            if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.P))
            {
                allowPause = true;
            }
            if (allowPause && Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.P))
            {
                paused    ^= true;
                allowPause = false;
                if (paused)
                {
                    //MediaPlayer.Pause();
                    MediaPlayer.Volume /= 4;
                    foreach (PowerUp p in PowerUp.AlivePowerUps)
                    {
                        p.AliveTimer.Stop();
                    }
                    foreach (PowerUp p in isaac.ActivePowerUps)
                    {
                        p.ActiveTimer.Stop();
                    }
                }
                else
                {
                    //MediaPlayer.Resume();
                    MediaPlayer.Volume *= 4;
                    foreach (PowerUp p in PowerUp.AlivePowerUps)
                    {
                        p.AliveTimer.Start();
                    }
                    foreach (PowerUp p in isaac.ActivePowerUps)
                    {
                        p.ActiveTimer.Start();
                    }
                }
            }
            if (paused)
            {
                return;
            }

            //show fps every 1 second
            fpsElapsedTime += gameTime.ElapsedGameTime;
            if (fpsElapsedTime > TimeSpan.FromSeconds(1))
            {
                Game1.Game.Window.Title = "FPS: " + frameCounter;
                fpsElapsedTime         -= TimeSpan.FromSeconds(1);
                frameCounter            = 0;
            }

            isaacHurtAnimation.Update();
            //isaacHurtMove(gameTime);

            spawnPotions(gameTime);
            moveIsaac(gameTime);
            Bullet.moveBullets(gameTime);
            rotatePeanuts(gameTime);
            Fireball.moveFireballs(gameTime);
            rotateFireballs(gameTime);
            Laser2.UpdateLasers(gameTime);
            SeekerSnake.UpdateSeekerSnakes(gameTime);

            checkForPowerUpSpawnExpire(gameTime);

            isaac.CalculateCorners();
            alex.CalculateCorners();
            foreach (Laser2 laser in Laser2.Lasers)
            {
                laser.CalculateCorners();
            }
            foreach (Bullet p in Bullet.Peanuts)
            {
                p.CalculateCorners();
            }

            checkForPowerUpAcquisition();
            acquirePotions();

            isaacShoot(gameTime);

            checkForPeanutHits();

            checkForSledgeHammerUse(gameTime);
            checkForSledgeHammerHits();

            if (checkForIsaacHurt())
            {
                isaacDeath();
                cleanup();
                returnControl("title");
                return;
            }

            if (alex.HP == 0)
            {
                cleanup();
                returnControl("postgame");
                return;
            }

            alex.Update(gameTime, isaac);

            updateHearts();
            shrinkPeanuts(gameTime);
            burnPeanuts(gameTime);
            moveBurningPeanuts(gameTime);

            updateSuperFireballLoopingSound();
        }