コード例 #1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            Random random = new Random();

            gamepad = GamePad.GetState(PlayerIndex.One);
            spriteBatch.Begin();
            switch (gameState)
            {
            case GameState.startScreen:
                spriteBatch.DrawString(fontSmall, "Press space to start", new Vector2(320 - 10 * 10, 240), Color.White);
                break;

            case GameState.menu:
                menu.Draw(spriteBatch, font, startedGame);
                break;

            case GameState.game:
                switch (level)
                {
                case 2:
                    for (int x = 0; x < 24 * 7; x++)
                    {
                        for (int y = 0; y < 24 * 5; y++)
                        {
                            spriteBatch.Draw(spritesheet, new Vector2(x * 24, y * 24), new Rectangle(551, 126, 24, 24), Color.White);
                        }
                    }
                    break;
                }
                foreach (backgroundObject bo in backgroundObjects)
                {
                    if (bo.type == "back")
                    {
                        bo.DrawSprite(spriteBatch, spritesheet);
                    }
                }
                foreach (projectile p in projectiles)
                {
                    p.DrawSprite(spriteBatch, spritesheet);
                }
                player.DrawSprite(spriteBatch, spritesheet);
                foreach (enemyProjectile ep in enemyProjectiles)
                {
                    ep.DrawSprite(spriteBatch, spritesheet);
                }
                foreach (enemy e in enemies)
                {
                    if (!e.rotated)
                    {
                        e.DrawSprite(spriteBatch, spritesheet);
                    }
                    else
                    {
                        e.DrawSprite(spriteBatch, spritesheet, 1.0f);
                    }
                }
                foreach (particle p in particles)
                {
                    p.DrawSprite(spriteBatch, spritesheet);
                }
                foreach (explosion ex in explosions)
                {
                    ex.DrawSprite(spriteBatch, spritesheet);
                }
                foreach (backgroundObject bo in backgroundObjects)
                {
                    if (bo.type == "fore")
                    {
                        bo.DrawSprite(spriteBatch, spritesheet, bo.zoom);
                    }
                }
                gui.drawGui(spriteBatch, fontSmall, spritesheet, healthbar, player, level);
                break;

            case GameState.howTo:
                if (gamepad.IsConnected)
                {
                    spriteBatch.DrawString(font, " Left joystick to move \n a to shoot \n b to use the special power \n start to pause and unpause \n \n Press a To Return", new Vector2(320 - 14 * 10, 220), Color.White);
                }
                else
                {
                    spriteBatch.DrawString(font, " W,A,S,D or the arrow keys to move \n Space to shoot \n Left shift to use the special power \n Escape to pause and unpause \n \n Press Space To Return", new Vector2(320 - 14 * 10, 220), Color.White);
                }
                break;
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
コード例 #2
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            Random random = new Random();

            gamepad = GamePad.GetState(PlayerIndex.One);
            spriteBatch.Begin();
            switch (gameState)
            {
            case GameState.startScreen:
                if (!gamepad.IsConnected)
                {
                    spriteBatch.DrawString(fontBmp, "PRESS SPACE TO START", new Vector2(320 - 10 * 20, 240), Color.White);
                }
                else
                {
                    spriteBatch.DrawString(fontBmp, "PRESS A TO START", new Vector2(320 - 10 * 20, 240), Color.White);
                }
                break;

            case GameState.menu:
                menu.Draw(spriteBatch, spritesheet, fontBmp, startedGame);
                break;

            case GameState.levelTransition:
                spriteBatch.Draw(levelCompleted, new Vector2(0, 0), Color.White);
                spriteBatch.DrawString(fontBmp, "Kills this level: " + player.kills.ToString(), new Vector2(20, 140), Color.White);
                spriteBatch.DrawString(fontBmp, "Score: " + player.score.ToString(), new Vector2(20, 240), Color.White);
                break;

            case GameState.game:
                foreach (backgroundObject bo in backgroundObjects)
                {
                    if (bo.type == "back")
                    {
                        bo.DrawSprite(spriteBatch, spritesheet);
                    }
                }
                foreach (projectile p in projectiles)
                {
                    p.DrawSprite(spriteBatch, spritesheet);
                }
                player.DrawSprite(spriteBatch, spritesheet);
                if (!player.vulnerable)
                {
                    spriteBatch.Draw(spritesheet, player.pos, new Rectangle(1, 26, 24, 24), Color.White);
                }
                foreach (enemyProjectile ep in enemyProjectiles)
                {
                    if (ep.type == 3)
                    {
                        ep.DrawSprite(spriteBatch, spritesheet, 1);
                    }
                    else
                    {
                        ep.DrawSprite(spriteBatch, spritesheet);
                    }
                }
                foreach (enemy e in enemies)
                {
                    if (!e.rotated)
                    {
                        e.DrawSprite(spriteBatch, spritesheet);
                    }
                    else
                    {
                        e.DrawSprite(spriteBatch, spritesheet, 1.0f);
                    }
                }
                foreach (boss b in bosses)
                {
                    b.DrawSprite(spriteBatch, spritesheet);
                }
                foreach (hitEffect he in hitEffects)
                {
                    he.DrawSprite(spriteBatch, spritesheet);
                }
                foreach (particle p in particles)
                {
                    p.DrawSprite(spriteBatch, spritesheet);
                }
                foreach (gib g in gibs)
                {
                    spriteBatch.Draw(spritesheet, g.pos, new Rectangle(g.imx, g.imy, g.width, g.height), Color.White, g.rotation, new Vector2(g.width / 2, g.height / 2), 1.0f, SpriteEffects.None, 0);
                }
                foreach (powerUp pu in powerUps)
                {
                    pu.DrawSprite(spriteBatch, spritesheet);
                }
                foreach (explosion ex in explosions)
                {
                    ex.DrawSprite(spriteBatch, spritesheet);
                }
                foreach (backgroundObject bo in backgroundObjects)
                {
                    if (bo.type == "fore")
                    {
                        bo.DrawSprite(spriteBatch, spritesheet, bo.zoom);
                    }
                }
                gui.drawGui(spriteBatch, fontSmall, spritesheet, healthbar, player, level);
                break;

            case GameState.howTo:
                if (gamepad.IsConnected)
                {
                    spriteBatch.Draw(spritesheet, new Vector2(30, 30), new Rectangle(26, 376, 15, 13), Color.White);
                    spriteBatch.DrawString(fontBmp, " Left joystick to move \n a to shoot \n b to use the special power \n start to pause and unpause and select to \n toggle fullscreen \n \n Press a To Return", new Vector2(320 - 14 * 22, 180), Color.White);
                }
                else
                {
                    spriteBatch.Draw(spritesheet, new Vector2(30, 30), new Rectangle(51, 376, 15, 7), Color.White);
                    spriteBatch.DrawString(fontBmp, " W,A,S,D or the arrow keys to move \n Space to shoot \n Left shift to use the special power \n Escape to pause and unpause and F1 to \n toggle fullscreen \n \n Press Space To Return", new Vector2(320 - 14 * 22, 180), Color.White);
                }
                break;

            case GameState.gameOver:
                spriteBatch.Draw(gameOver, new Vector2(0, 0), Color.White);
                break;
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }