示例#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);
        }
示例#2
0
文件: Game1.cs 项目: kulhajs/Game
        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();
        }
示例#3
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;
                    }
        }
示例#4
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;
                }
            }
        }
示例#5
0
文件: Tower.cs 项目: kulhajs/Game
        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;
            }
        }
示例#6
0
文件: Tower.cs 项目: kulhajs/Game
 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;
         }
     }
 }