Beispiel #1
0
        public void Update(Player player, GameTime theGameTime, ExplosionHandler explosions, ItemHandler ih, SoundHandler sounds, Camera c)
        {
            foreach (Tower t in towers)
                t.Update(player, theGameTime, explosions, sounds, c);

            foreach (FlashDoor f in doors)
                f.Update(theGameTime);

            foreach (ZombieDispenser z in zombies)
                z.Update(theGameTime, explosions, ih, c);
        }
Beispiel #2
0
 public void HandleBulletTurretCollision(Player p, EnemyHandler e, ExplosionHandler eh)
 {
     foreach(Bullet b in p.bullets)
     {
         bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 2, 1);
         foreach(Tower t in e.towers)
             if(bulletRectangle.Intersects(t.GetRectangle()))
             {
                 b.Visible = false;
                 eh.AddExplosion(b.Position, t.contentManager, 5, 15, "explosion", 32, 0.33f);
             }
     }
 }
Beispiel #3
0
        public void Update(GameTime theGameTime, ExplosionHandler explosions, ItemHandler ih, Camera c)
        {
            if(random.Next(200) == (int)X / 64)
            {
                if (random.Next(2) == 0) newZombie = new Zombie(new Vector2(this.X + 8, this.Y + 48), new Vector2(-1, 1)); else newZombie = new Zombie(new Vector2(this.X + 8, this.Y + 48), new Vector2(1, 1));
                newZombie.LoadContent(contentManager);
                zombies.Add(newZombie);
                newZombie = null;
            }

            foreach (Zombie z in zombies)
                if (z.Visible)
                    z.Update(theGameTime, c);

            this.RemoveZombies(explosions, ih);
            this.Animate();
        }
Beispiel #4
0
        protected override void Initialize()
        {
            p = new Player(new Vector2(0, 0));
            l = new Level();
            l.Initialize(currentLevel, currentLevelType);

            items = new ItemHandler(this.Content);
            items.Initialize(currentLevel);

            enemies = new EnemyHandler();
            enemies.Initiliaze(currentLevel);
            explosions = new ExplosionHandler();
            sounds = new SoundHandler();

            camera = new Camera(graphics.GraphicsDevice.Viewport);

            ch = new CollisionHandler();

            this.ChangeLevel = false;

            base.Initialize();
        }
Beispiel #5
0
 private void RemoveZombies(ExplosionHandler explosions, ItemHandler ih)
 {
     foreach (Zombie z in zombies)
         if (z.Y > 550 || !z.Visible)
         {
             if (random.Next(10) == 1)
                 ih.AddFirstAid(z.Position, z.DX);
             else if (random.Next(5) % 2 == 0)
                 ih.AddAcid(z.Position, z.DX);
             explosions.AddExplosion(new Vector2(z.X + 20 * z.Scale, z.Y + 10 * z.Scale), contentManager, 4, 15, "blood", 32);
             zombies.Remove(z);
             break;
         }
 }
Beispiel #6
0
        public void HandleZombiePlayerCollision(Player p, EnemyHandler e, ExplosionHandler explosions, SoundHandler sounds)
        {
            playerRectangle = p.Crouching ? new Rectangle((int)(p.X + 24 * p.Scale), (int)(p.Y + 9 * p.Scale), (int)(9 * p.Scale), (int)(40 * p.Scale))
                                          : new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(60 * p.Scale));

            foreach (ZombieDispenser zd in e.zombies)
                foreach (Zombie z in zd.zombies)
                    if (z.OnScreen)
                    {
                        zombieRectangle = new Rectangle((int)(z.X + 24 * z.Scale), (int)(z.Y + 9 * z.Scale), (int)(16 * z.Scale), (int)(56 * z.Scale));
                        if (playerRectangle.Intersects(zombieRectangle))
                        {
                            z.Collide = true;
                            if (z.CanBite)
                            {
                                if (z.DX < 0 && p.DX >= 0)
                                {
                                    explosions.AddExplosion(new Vector2(p.X - 9 * p.Scale, p.Y), p.contentManager, 4, 15, "blood", 32);
                                    p.DX = -4f;
                                    p.Push = true;
                                    p.Hitpoints -= random.Next(minZombieDmg, maxZombieDmg);
                                    sounds.PlayHurt(p, z);
                                    z.realoadTime = 0.0f;
                                }
                                else if (z.DX > 0 && p.DX <= 0)
                                {
                                    explosions.AddExplosion(new Vector2(p.X + 9 * p.Scale, p.Y), p.contentManager, 4, 15, "blood", 32);
                                    p.DX = 4f;
                                    p.Push = true;
                                    p.Hitpoints -= random.Next(minZombieDmg, maxZombieDmg);
                                    sounds.PlayHurt(p, z);
                                    z.realoadTime = 0.0f;
                                }
                            }

                            if (z.DX < 0 && p.DX < 0 && !p.Push)
                                z.X = p.X - 15 * z.Scale;
                            else if (z.DX > 0 && p.DX > 0 && !p.Push)
                                z.X = p.X + 12 * z.Scale;
                        }
                        else
                            z.Collide = false;
                    }
        }
Beispiel #7
0
        public void HandleItemCollision(Player p, ItemHandler i, ExplosionHandler explosions, Level l, SoundHandler sounds)
        {
            if (p.Jumping || p.Falling)
                playerRectangle = new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(48 * p.Scale));
            else
            {
                playerRectangle = p.Crouching ? new Rectangle((int)(p.X + 24 * p.Scale), (int)(p.Y + 9 * p.Scale), (int)(9 * p.Scale), (int)(50 * p.Scale))
                                              : new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(60 * p.Scale));

            }
            foreach (Coin c in i.coins)
                if (c.Visible)
                {
                    coinRectangle = new Rectangle((int)c.X, (int)c.Y, 16, 16);
                    if (coinRectangle.Intersects(playerRectangle))
                    {
                        sounds.PlayPickUp();
                        c.Visible = false;
                        p.Score += 5;
                    }
                }

            foreach (FirstAid f in i.firstAids)
            {
                f.Falling = true;
                firstAidRectangle = new Rectangle((int)f.X + 1, (int)f.Y + 3, 14, 12);
                foreach (MacroBlock mb in l.levelBlocks)
                {
                    if (firstAidRectangle.Intersects(mb.GetRectangle()))
                        f.Falling = false;
                }
                if(playerRectangle.Intersects(firstAidRectangle))
                {
                    if (p.Hitpoints + firstAidHealth <= 100)
                        p.Hitpoints += firstAidHealth;
                    else
                        p.Hitpoints = 100;
                    f.Visible = false;
                }
            }

            foreach (Acid a in i.acidBalls)
            {
                a.Falling = true;
                acidRectangle = new Rectangle((int)a.X - 6, (int)a.Y - 6, 10, 10);
                foreach (MacroBlock mb in l.levelBlocks)
                {
                    if (acidRectangle.Intersects(mb.GetRectangle()))
                        a.Falling = false;
                }
                if(playerRectangle.Intersects(acidRectangle) && !a.Exploded)
                {
                    sounds.PlayHurt(p);
                    p.Hitpoints -= random.Next(minZombieDmg, maxZombieDmg) / 2;
                    explosions.AddExplosion(new Vector2(a.Position.X - 8, a.Position.Y - 8), a.contentManager, 9, 27, "acid", 16);
                    a.Exploded = true;
                }
            }
        }
Beispiel #8
0
        public void Update(Player p, GameTime theGameTime, ExplosionHandler explosions, SoundHandler sounds, Camera c)
        {
            foreach (Rocket r in rockets)
                if (r.Visible)
                    r.Update(theGameTime, new Vector2((p.X + 21 * p.Scale) - r.X, (p.Y + 3 * p.Scale) - r.Y)); //(p.x+21); (p.y+3) so it doesn't aim at player.origin

            if (reloadTime < initRealoadTime)
                reloadTime += (float)theGameTime.ElapsedGameTime.TotalSeconds;

            //this.Animate();
            this.RemoveRocket(explosions, sounds, p);

            this.OnScreen = this.X - c.origin.X < 800 ? true : false;

            if (!OnScreen)
                return;

            float dx = this.Position.X - p.X;
            float dy = this.Position.Y - p.Y;
            float dist = dx * dx + dy * dy;     //distance from player to tower

            if (dx > 64 && dist < vision * vision && (dy < 100 && dy > -30)) //if distance.X < 64 and distance y < 100 && > 30 then Rotate - facing player
            {
                this.Rotation = FAtan((dy + 2) / dx); //(y+2) so it doesn't aim at very top of head
                lightColor = 2;
                this.SeePlayer = true;
            }
            else
            {
                lightColor = 0;
                this.SeePlayer = false;
            }

            if (reloadTime > initRealoadTime && SeePlayer)
            {
                rocketDirection = new Vector2((p.X + 21 * p.Scale) - this.X, (p.Y + 3 * p.Scale) - this.Y); //(p.Y + 3) so it doesn't shoot on top of head
                rocketDirection.Normalize();

                float xx = this.X + FCos(Rotation) * Fsqrt((32 * 32 * Scale * Scale) + (9 * 9 * Scale * Scale)); //x coordinate of new rocket

                newRocket = new Rocket(new Vector2(xx, Y + 5 * Scale), rocketDirection, this.Rotation);
                newRocket.LoadContent(contentManager);
                rockets.Add(newRocket);
                newRocket = null;
                reloadTime = 0f;
            }
        }
Beispiel #9
0
 private void RemoveRocket(ExplosionHandler explosions, SoundHandler sounds, Player p)
 {
     foreach(Rocket r in this.rockets)
     {
         if (!r.Visible)
         {
             sounds.PlayExplosion(p, r);
             explosions.AddExplosion(r.Position, contentManager, 5, 15, "explosion", 32); //each time rocket is removed, explosion is created
             rockets.Remove(r);
             break;
         }
     }
 }
Beispiel #10
0
 private void RemoveBullets(ExplosionHandler explosions)
 {
     foreach (Bullet b in bullets)
         if (!b.Visible)
         {
             bullets.Remove(b);
             if (b.SprayBlood)
                 explosions.AddExplosion(b.Position, contentManager, 4, 15, "blood", 32);
             break;
         }
 }
Beispiel #11
0
        public void Update(MouseState mouseState, KeyboardState currentKeyboardState, KeyboardState oldKeyboardState, GameTime theGameTime, Camera camera, ExplosionHandler explosions)
        {
            hb.Update(camera, (int)((double)Hitpoints * 1.18));

            if ((mouseState.X + camera.origin.X) - this.X > 0)
                currentFacing = Facing.Right;
            else
                currentFacing = Facing.Left;

            //aiming
            float dx = (mouseState.X + camera.origin.X) - this.X;
            float dy = (mouseState.Y + camera.origin.Y) - this.Y;
            if (dx > 15 || dx < 15)
                this.Rotation = FAtan((dy / 10) / (dx / 10));

            //door switch interaction
            if (IntersectWithSwitch != null && IntersectWithSwitch.Switch && UseKeyPressed(currentKeyboardState, oldKeyboardState))
                IntersectWithSwitch.Switch = false;
            else if (IntersectWithSwitch != null && !IntersectWithSwitch.Switch && UseKeyPressed(currentKeyboardState, oldKeyboardState))
                IntersectWithSwitch.Switch = true;

            this.UpdateMovement(currentKeyboardState, oldKeyboardState, theGameTime);
            this.UpdateAnimation();

            if (mouseState.LeftButton == ButtonState.Pressed && reloadTime < 0.0f)
                this.UpdateAttack(mouseState, camera);

            foreach (Bullet b in bullets)
                if (b.Visible)
                    b.Update(theGameTime);

            this.RemoveBullets(explosions);

            if (reloadTime > 0.0f)
                reloadTime -= (float)theGameTime.ElapsedGameTime.TotalSeconds;

            if (this.Y > 500)
                this.Hitpoints = 0;

            if (currentFacing == Facing.Right)
                gunPosition = Crouching ? new Vector2(X + 27 * this.Scale, Y + 32 * this.Scale) : new Vector2(X + 26 * this.Scale, Y + 20 * this.Scale);
            else
                gunPosition = Crouching ? new Vector2(X + 36 * this.Scale, Y + 32 * this.Scale) : new Vector2(X + 38 * this.Scale, Y + 20 * this.Scale);

            crosshairPosition = new Vector2(mouseState.X - 4 + camera.origin.X, mouseState.Y - 4 + camera.origin.Y);
        }