Beispiel #1
0
        public void HandleDoorCollision(Player p, EnemyHandler e)
        {
            playerRectangle = new Rectangle((int)(p.X + 16 * p.Scale), (int)(p.Y + 1 * p.Scale), (int)(27 * p.Scale), (int)(63 * p.Scale));
            foreach (FlashDoor f in e.doors)
            {
                if (f.Switch)
                {
                    doorRectangle_L = new Rectangle((int)f.Position.X + 28, (int)f.Position.Y + 11, 4, 122); //left side of door laser beam
                    doorRectangle_R = new Rectangle((int)f.Position.X + 32, (int)f.Position.Y + 11, 4, 122); //right side of door laser beam
                    if (doorRectangle_L.Intersects(playerRectangle))
                    {
                        p.Hitpoints -= random.Next(minDoorDmg, maxDoorDmg);
                        p.DX = -4; //push to the left
                        p.Push = true;
                    }
                    else if (doorRectangle_R.Intersects(playerRectangle))
                    {
                        p.Hitpoints -= random.Next(minDoorDmg, maxDoorDmg);
                        p.DX = 4; //push to the right
                        p.Push = true;
                    }
                }

                switchRectangle = new Rectangle((int)f.SPosition.X + 24, (int)f.SPosition.Y + 24, 16, 16);
                if (playerRectangle.Intersects(switchRectangle) && p.IntersectWithSwitch == null)
                    p.IntersectWithSwitch = f;

                if (!playerRectangle.Intersects(switchRectangle) && p.IntersectWithSwitch == f)
                    p.IntersectWithSwitch = null;
            }
        }
Beispiel #2
0
 public void PlayHurt(Player p, Zombie z=null)
 {
     if (z != null)
         hurt.Play(0.25f, 0.0f, z.X - p.X > 0 ? 0.20f : -0.20f);
     else
         hurt.Play(0.15f, 0.0f, 0.0f);
 }
Beispiel #3
0
 static void Main(string[] args)
 {
     player = new Player(1, 1, 1);
     while (running) {
         Update();
     }
 }
Beispiel #4
0
 public void HandleBulletZombieCollision(Player p, EnemyHandler e)
 {
     foreach (Bullet b in p.bullets)
         if (b.Visible)
         {
             bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 2, 1);
             foreach (ZombieDispenser zd in e.zombies)
                 foreach (Zombie z in zd.zombies)
                     if (z.Visible)
                     {
                         zombieRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 19 * z.Scale), (int)(28 * z.Scale), (int)(45 * z.Scale));
                         zombieHeadRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 4 * z.Scale), (int)(22 * z.Scale), (int)(15 * z.Scale));
                         if (bulletRectangle.Intersects(zombieRectangle))
                         {
                             z.Hitpoints -= bulletDmg;
                             b.SprayBlood = true;
                             b.Visible = false;
                         }
                         else if(bulletRectangle.Intersects(zombieHeadRectangle))
                         {
                             z.Hitpoints = 0;
                             p.Score += 5;
                             b.SprayBlood = true;
                             b.Visible = false;
                         }
                     }
         }
 }
Beispiel #5
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 #6
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 #7
0
        public void Update(Player player)
        {
            if (player.X < 400)
                origin.X = 0;
            else
                origin.X = player.X - 400;

            if (player.Y < 64)
                origin.Y = player.Y - 64;
            else
                origin.Y = 0;

            transform = Matrix.CreateTranslation(new Vector3(-origin.X, -origin.Y, 0));
        }
Beispiel #8
0
        /// <summary>
        /// 用户登录加入到游戏中,可以不断的调用,表示不断的有人加入到游戏中
        /// </summary>
        /// <param name="idx">玩家编号</param>
        /// <param name="user"></param>
        /// <returns>如果游戏开始(Start)则无法加入</returns>
        public bool Join(int idx, ModelUser user)
        {
            //TODO 考虑用锁保证和SetRoleCount的并发问题
            if (isGameStarted) return false;

            if (TheContext.DicIdxPlayer.ContainsKey(idx)) return false;

            Player newPlayer = new Player();
            newPlayer.theUser = user;
            newPlayer.Idx = idx;
            newPlayer.theStatus = PlayerStatus.Ready;
            TheContext.Players.Add(newPlayer);
            TheContext.DicIdxPlayer.Add(idx, newPlayer);
            Console.WriteLine("{0}加入了游戏,编号{1}", newPlayer.theUser.Name, newPlayer.Idx);

            return true;
        }
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
 public void HandleEndLevel(Game1 game, Player p, Level l)
 {
     playerRectangle = new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(60 * p.Scale));
     eolRectangle = new Rectangle((int)(l.endOflevel.X + 42), (int)l.endOflevel.Y, 10, 64);
     if (playerRectangle.Intersects(eolRectangle))
         game.ChangeLevel = true;
 }
Beispiel #11
0
 public void PlayExplosion(Player p, Rocket r)
 {
     float volume = (-(FAbs(r.X - p.X) / 400f) + 1) / 5;
     explosion.Play(volume > 0.0f ? volume : 0.0f, 0.0f, r.X - p.X > 0 ? 0.25f : -0.25f);
 }
Beispiel #12
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 #13
0
 public void Initialize()
 {
     //Objekte der Klassen werden initialisiert.
     map = new Map(new System.Drawing.Bitmap("Collision-Maps/Collision-Bitmap.bmp"));
     player = new Player("Cookie2", new Vector2f(200, 1400));
     enemy = new Enemy01();
     checkPointList = checkPointList01();
     text = new Texture("Collision-Maps/Collision-Bitmap.bmp");
     sprite = new Sprite(text);
     sprite.Scale = new Vector2f(50, 50);
     powerups = new Powerups01();
     hud = new Hud();
     start = new TimeSpan(0, 0, 3);
     Stopwatch timer = new Stopwatch();
     TimeSpan time = new TimeSpan();
     timer.Start();
     time = new TimeSpan(0, 0, 1);
     pH = new ParticleHandler();
 }
Beispiel #14
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 #15
0
        public void HandleMovingCollision(Player p, Level l, Camera c)
        {
            p.Falling = true;

            playerRectangle = new Rectangle((int)(p.X + 24 * p.Scale), (int)(p.Y + 58 * p.Scale), (int)(16 * p.Scale), (int)(6 * p.Scale));
            foreach (MacroBlock mb in l.levelBlocks)
                if (mb.IsOnScreen(c))
                {
                    if (playerRectangle.Intersects(mb.GetRectangle()))
                    {
                        p.Falling = false;
                        break;
                    }
                }
        }
Beispiel #16
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 #17
0
        public void HandleRocketCollision(Player p, EnemyHandler e)
        {
            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)(45 * p.Scale))
                                             : new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(60 * p.Scale));

            }
            foreach (Tower t in e.towers)
                foreach (Rocket r in t.rockets)
                    if (r.Visible)
                    {
                        rocketRectangle = new Rectangle((int)r.X, (int)r.Y, 3, 3);
                        if (playerRectangle.Intersects(rocketRectangle))
                        {
                            r.Visible = false;
                            p.Push = true;

                            if(r.DX > 0)
                                p.DX = 3.5f;
                            else
                                p.DX = -3.5f;

                            p.Hitpoints -= random.Next(minRocketDmg, maxRocketDmg);
                        }

                        foreach(ZombieDispenser zd in e.zombies)
                            foreach(Zombie z in zd.zombies)
                                if (z.Visible && r.Visible)
                                {
                                    zombieRectangle = new Rectangle((int)(z.X + 24 * z.Scale), (int)z.Y, (int)(16 * z.Scale), (int)(60 * z.Scale));
                                    if(rocketRectangle.Intersects(zombieRectangle))
                                    {
                                        r.Visible = false;
                                        z.Hitpoints = 0;
                                    }
                                }
                    }
        }
Beispiel #18
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;
                    }
        }