Beispiel #1
0
        public void drawHud()
        {
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate,
                              SaveStateMode.SaveState, Matrix.Identity);
            spriteBatch.GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
            spriteBatch.GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
            spriteBatch.GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point;

            Vector2 upPos = new Vector2(10, 10);

            for (int i = 0; i < player.getHP() / 10; i++)
            {
                spriteBatch.Draw(HPBoxSprite, upPos, Color.White);
                upPos.X += 10;
            }

            upPos.Y += 10;
            upPos.X  = 0;

            Color playerC = Color.White;

            if (player.getBombCooldown() > 0)
            {
                playerC = Color.Black;
            }
            spriteBatch.Draw(playerSprite, upPos, playerC);
            upPos.X += playerSprite.Width;

            string lives = " x" + player.getLives();

            //spriteBatch.DrawString(font, health, new Vector2(0, 0), Color.Yellow);
            if (player.getLives() >= 0)
            {
                spriteBatch.DrawString(font, lives, upPos, Color.Yellow);
            }

            float eggSize = hollowEggSprite.Width + 5;

            upPos = new Vector2(graphics.GraphicsDevice.Viewport.Width - eggSize,
                                graphics.GraphicsDevice.Viewport.Height - eggSize);
            for (int i = 0; i < characterManager.getEggNum(); i++)
            {
                spriteBatch.Draw(hollowEggSprite, upPos, Color.White);
                upPos.X -= eggSize;
            }
            for (int i = 0; i < player.getEggs(); i++)
            {
                spriteBatch.Draw(eggSprite, upPos, Color.White);
                upPos.X -= eggSize;
            }

            string pointString = "" + points;

            upPos = new Vector2(graphics.GraphicsDevice.Viewport.Width - (font.MeasureString(pointString).X) - 10,
                                (font.MeasureString(pointString).Y / 2.0f));
            spriteBatch.DrawString(font, pointString, upPos, Color.Yellow);

            string[] mainText = null;
            if (levelManager.getCurrentLevel() == 0)
            {
                mainText = intro;
                Vector2 pos;
                string  g     = "PLANET EARTH IS BLUE";
                float   scale = 3.0f;
                pos.X = (graphics.GraphicsDevice.Viewport.Width / 2.0f) - (font.MeasureString(g).X / 2.0f * scale);
                pos.Y = 100;
                spriteBatch.DrawString(font, g, pos, Color.Blue, 0.0f, new Vector2(0.0f, 0.0f), scale, SpriteEffects.None, 0.0f);
            }
            else if (levelManager.getCurrentLevel() == 6)
            {
                mainText = end;
            }

            if (mainText != null)
            {
                Vector2 pos = new Vector2(0.0f, 400.0f);

                for (int i = 0; i < mainText.Length; i++)
                {
                    Color col = Color.Yellow;
                    if (mainText[i].CompareTo("-alone-") == 0)
                    {
                        col = Color.Blue;
                    }
                    float scale = 1.0f;
                    pos.X = (graphics.GraphicsDevice.Viewport.Width / 2.0f) - (font.MeasureString(mainText[i]).X / 2.0f * scale);
                    spriteBatch.DrawString(font, mainText[i], pos, col, 0.0f, new Vector2(0.0f, 0.0f), scale, SpriteEffects.None, 0.0f);
                    pos.Y += font.MeasureString(mainText[i]).Y * 1.1f;
                }
            }
            if (gameOver)
            {
                Vector2 pos;
                string  g     = "GAME OVER";
                float   scale = 2.0f;
                pos.X = (graphics.GraphicsDevice.Viewport.Width / 2.0f) - (font.MeasureString(g).X / 2.0f * scale);
                pos.Y = (graphics.GraphicsDevice.Viewport.Height / 2.0f) - (font.MeasureString(g).Y / 2.0f * scale);
                spriteBatch.DrawString(font, g, pos, Color.Red, 0.0f, new Vector2(0.0f, 0.0f), scale, SpriteEffects.None, 0.0f);
            }

            spriteBatch.End();
        }
Beispiel #2
0
        public void update(GameTime gameTime)
        {
            player.update(gameTime);
            foreach (Character enemy in enemies)
            {
                enemy.update(gameTime);
                if (!enemy.isAlive())
                {
                    removedEnemies.Add(enemy);
                    if (enemy.getType() == 3)
                    {
                        addExplosion(enemy.getPos(), enemy.getVel() / 5.0f, 4.0f, Color.OrangeRed);
                        soundManager.bossDeath();
                        Game1.points += 1000;
                    }
                    else
                    {
                        addExplosion(enemy.getPos(), enemy.getVel() / 5.0f, 0.7f, Color.White);
                        soundManager.enemyDeath();
                        Game1.points += 250 + (enemy.getType() * 50);
                    }
                }
            }
            foreach (Bullet bullet in enemyBullets)
            {
                bullet.update(gameTime);
                if (!bullet.isAlive())
                {
                    removedEnemyBullets.Add(bullet);
                }
            }
            foreach (Bullet bullet in playerBullets)
            {
                bullet.update(gameTime);
                if (!bullet.isAlive())
                {
                    removedPlayerBullets.Add(bullet);
                }
            }
            foreach (Character egg in eggs)
            {
                egg.update(gameTime);
                egg.rotate(-0.001f);
                if (!egg.isAlive())
                {
                    removedEggs.Add(egg);
                }
            }
            foreach (Bullet eff in effects)
            {
                eff.update(gameTime);
                if (!eff.isAlive())
                {
                    removedEffects.Add(eff);
                }
            }

            // check player shots
            foreach (Bullet bullet in playerBullets)
            {
                foreach (Character enemy in enemies)
                {
                    if (bullet.isAlive() &&
                        bullet.getLifetime() > bullet.getLifetimeThreshold() / 2 &&
                        bullet.getBoundingBox().Intersects(enemy.getBoundingBox()))
                    {
                        // check stay, so we only check bombs every bombCounter frames
                        if (!bullet.isStay() || bombCounter == 0)
                        {
                            enemy.hit(bullet.getDamage());
                            addSparks(enemy.getPos(), enemy.getVel());
                            if (!bullet.isStay())
                            {
                                bullet.kill();
                            }
                            soundManager.enemyHit();
                        }
                    }
                }
            }

            // check enemy shots
            if (player.isAlive())
            {
                foreach (Bullet bullet in enemyBullets)
                {
                    if (bullet.isAlive() &&
                        bullet.getLifetime() > bullet.getLifetimeThreshold() / 2 &&
                        bullet.getBoundingBox().Intersects(player.getBoundingBox()))
                    {
                        player.hit(bullet.getDamage());
                        addSparks(player.getPos(), player.getVel());
                        bullet.kill();
                        soundManager.playerHit();
                    }
                }
            }

            // check eggs
            foreach (Character egg in eggs)
            {
                if (egg.isAlive() && egg.getBoundingBox().Intersects(player.getBoundingBox()))
                {
                    egg.kill();
                    player.incHP(40);
                    player.incEggs();
                    soundManager.egg();
                    Game1.points += 250;
                }
            }

            foreach (Bullet b in removedPlayerBullets)
            {
                playerBullets.Remove(b);
            }
            foreach (Bullet b in removedEnemyBullets)
            {
                enemyBullets.Remove(b);
            }
            foreach (Character b in removedEnemies)
            {
                enemies.Remove(b);
            }
            foreach (Character e in removedEggs)
            {
                eggs.Remove(e);
            }
            foreach (Bullet e in removedEffects)
            {
                effects.Remove(e);
            }

            // death handling
            if (!player.isAlive())
            {
                // after the wait
                if (deathTimer == 0)
                {
                    player.revive();
                    deathTimer = deathTimerMax;
                    player.setPos(new Vector2(0.0f, 0.0f));
                    cam.setPos(new Vector2(0.0f, 0.0f));
                    if (player.getLives() < 0)
                    {
                        levelManager.initLevel(0);
                        player.setLives(3);
                    }
                }
                // meaning, just died
                else
                {
                    if (deathTimer == deathTimerMax)
                    {
                        addExplosion(player.getPos(), player.getVel() / 5.0f, 0.5f, Color.Yellow);
                        soundManager.playerDeath();
                        player.decLives();
                        if (player.getLives() < 0)
                        {
                            Game1.instance.setGameOver(true);
                        }
                    }
                    deathTimer--;
                }
            }
        }