Esempio n. 1
0
        protected void facePlayer()
        {
            float   r;
            Player  player    = characterManager.getPlayer();
            Vector2 playerVec = (player.getPos() - pos) + (player.getVel() * 70.0f);

            r = (float)Math.Atan((double)(playerVec.Y / playerVec.X)) + (float)Math.PI / 2;
            if (playerVec.X < -0.01f)
            {
                r = (float)Math.PI + r;
            }
            else
            {
                r = (2.0f * (float)Math.PI) + r;
            }
            //rotate((rotation - r)/20.0f);
            //setRotation(r + (((float)Game1.random.NextDouble() * (float)Math.PI / 16) - (float)Math.PI / 8));
            setRotation(r);
            //rotation = r;
            //destRotation = r;

            if (chase)
            {
                float   dist      = Vector2.Distance(player.getPos(), pos);
                Vector2 followVel = playerVec / 40.0f * dist / 1000.0f;
                if (followVel.X > maxVel)
                {
                    followVel.X = maxVel;
                }
                if (followVel.Y > maxVel)
                {
                    followVel.Y = maxVel;
                }
                float   velX    = ((float)Game1.random.NextDouble() * 2 * maxVel) - maxVel;
                float   velY    = ((float)Game1.random.NextDouble() * 2 * maxVel) - maxVel;
                Vector2 randVel = new Vector2(velX, velY);
                addVel(followVel + randVel);
            }
        }
Esempio n. 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--;
                }
            }
        }