示例#1
0
        public void Update(GameTimer timer, ContentManager theContentManager, PowerupHandler pu, Player player, bool soundMuted)
        {
            enemiesInLevel = (background.Period + 1) * 3;

            elapsedTime += (float)timer.UpdateInterval.TotalSeconds;
            if (elapsedTime > 45f / enemiesInLevel && readyEnemies.Count > 0) //45f = time to 4000px to pass (current background width = 2000px)
            {
                elapsedTime = 0;
                readyEnemies[0].Position = new Vector2(player.Position.X + random.Next(760, 810), random.Next(110, 450));
                visibleEnemies.Add(readyEnemies[0]);
                readyEnemies.Remove(readyEnemies[0]);
            }

            foreach (Enemy e in visibleEnemies)
            {
                if (e.Position.X < player.Position.X - 100)
                {
                    if (e.IsAlive && player.IsAlive)
                        player.score.AddPoints(-5);
                    e.IsAlive = true;
                    e.Hitpoints = maxHealth;
                    e.ExplosionCreated = false;
                    e.explosionHandler.explosions.Clear();
                    readyEnemies.Add(e);
                    visibleEnemies.Remove(e);
                    break;
                }
                e.Update(timer, pu, theContentManager, player, soundMuted);
            }
        }
示例#2
0
        public GamePage()
        {
            InitializeComponent();

            // Get the content manager from the application
            contentManager = (Application.Current as App).Content;

            // Create a timer for this page
            timer = new GameTimer();
            timer.UpdateInterval = TimeSpan.FromTicks(/*333333*/ 111111);
            timer.Update += OnUpdate;
            timer.Draw += OnDraw;

            player = new Player();
            background = new Background();
            clouds = new Clouds();
            enemyHandler = new EnemyHandler(player, background);
            intersectionHandler = new IntersectionHandler();
            buildingHandler = new BuildingHandler();
            powerupHandler = new PowerupHandler();
        }
示例#3
0
        public void HandlePowerupIntersections(PowerupHandler pu, Player player)
        {
            playerRectangle = new Rectangle((int)player.X - player.W / 2, (int)player.Y - player.H / 2, player.W, player.H);
            foreach (Powerup p in pu.powerups)
            {
                powerupRectangle = new Rectangle((int)p.X, (int)p.Y, p.W, p.H);
                if (playerRectangle.Intersects(powerupRectangle))
                {
                    if (p.Type == "health")
                    {
                        if (player.Hitpoints + 5 < player.MaxHealth)
                            player.Hitpoints += 5;
                        else
                        {
                            if (player.healthPowerups.Count < 5)
                            {
                                p.Source = new Rectangle(0, 0, p.W, p.H);
                                p.Position = new Vector2(150, 438);
                                p.Scale = 2f;
                                player.healthPowerups.Add(p);
                            }
                            else
                                player.Hitpoints = player.MaxHealth;
                        }
                    }
                    else if (p.Type == "ammo")
                    {
                        if (player.Ammo + 50 < player.MaxAmmo)
                            player.Ammo += 50;
                        else
                        {
                            if (player.ammoPowerups.Count < 5)
                            {
                                p.Source = new Rectangle(0, 16, p.W * 2, p.H * 2);
                                p.Position = new Vector2(618, 438); //TODO: test behavior on higher resolution if the game scales correctly
                                p.Scale = 1f;
                                player.ammoPowerups.Add(p);
                            }
                            else
                                player.Ammo = player.MaxAmmo;
                        }
                    }
                    else if (p.Type == "ten")
                    {
                        player.score.AddPoints(10);
                    }
                    else if (p.Type == "bomb" && player.AvailibleBombs + 1 <= 2)
                    {
                        player.AvailibleBombs += 1;
                    }

                    pu.powerups.Remove(p);
                    break;
                }
            }
        }
示例#4
0
        private void GeneratePowerups(PowerupHandler pu, ContentManager theContentManager)
        {
            int x = random.Next(0, 7);

            if (x == 1)
                pu.CreatePowerup(new Vector2(this.X - 50, this.Y - 100), theContentManager, "health");
            else if (x == 2)
                pu.CreatePowerup(new Vector2(random.Next(810, 900), random.Next(20, 300)), theContentManager, "ten");
            else if (x == 3)
                pu.CreatePowerup(new Vector2(this.X - 50, this.Y - 100), theContentManager, "ammo");

            if (random.Next(30) == 13)
                pu.CreatePowerup(new Vector2(random.Next(810, 900), random.Next(20, 300)), theContentManager, "bomb");
        }
示例#5
0
        public void Update(GameTimer timer, PowerupHandler pu , ContentManager theContentManager, Player player, bool soundsMuted)
        {
            this.Position += direction * velocity * (float)timer.UpdateInterval.TotalSeconds;

            if (this.Hitpoints < 1 && !ExplosionCreated)
            {
                this.GeneratePowerups(pu, theContentManager);

                this.IsAlive = false;
                explosionHandler.CreateExplosion("normal", new Vector2(this.X - 47, this.Y - 87), contentManager);
                this.ExplosionCreated = true;
                player.score.AddPoints(10);
            }

            if (this.IsAlive &&  reloadTime == 0 && random.Next(this.Hitpoints / 2 + 1) == 1)
            {
                Bullet newBullet = new Bullet(new Vector2(this.X - 45, this.Y - 84), direction, this.Rotation);
                newBullet.LoadContent(contentManager);
                bullets.Add(newBullet);
                //if (!soundsMuted)
                //    mg.Play(0.075f, 0, 0);
            }

            reloadTime += (float)timer.UpdateInterval.TotalSeconds;
            if (reloadTime > 0.05f)
                reloadTime = 0;

            foreach (Bullet b in bullets)
            {
                b.Update(timer);
                if (b.Position.X - this.Position.X > 700)
                {
                    bullets.Remove(b);
                    break;
                }
            }

            explosionHandler.Update(timer, player.IsAlive, soundsMuted); //player.IsAlive indicates that all explosions are moving towards the player as long palyer is alive and background is scrolling

            this.Animate(player);
        }