Exemple #1
0
 //Constructor for new spear
 //Takes inputs (Player, ScreenSize, Map)
 public SpearClass(PlayerClass spearOwner, Texture2D spearText,Texture2D indicatorText, Vector2 ScreenSize, /*necesary?*/ Map m, PlayerClass[] players)
 {
     this.spearText = spearText;
     this.indicatorText = indicatorText; 
     this.players = players;
     spear.Width = spearText.Width-20;
     spear.Height = spearText.Height;
     Width = spearText.Width;
     Height = spearText.Height;
     velocity.X = 0;
     velocity.Y = 0;
     this.spearOwner = spearOwner;
     spearOrientation = 0;
     this.SCREENSIZE = ScreenSize;
     this.m = m;
     spearOwner.setSpear(this);
 }
Exemple #2
0
        //Check to see if the spear is colliding with a player
        private void playerCollision()
        {
            if (isInUse && attachedToPlayer)
            {
                PlayerClass[] players = spearOwner.getPlayers();
                foreach (PlayerClass player in players)
                {
                    if (player != null && !player.Equals(spearOwner) && !player.dead && player.blinked == spearOwner.blinked)
                    {
                        Rectangle adjustedRect = new Rectangle(spear.Location, spear.Size);
                        adjustedRect.X -= 27;

                        bool hit = VectorMath.rectCollision(adjustedRect, orientation, player.getPlayerRect(), 0, new Point(16, 8));
                        
                        if (hit)//player.getPlayerRect().Intersects(this.spear))
                        {
                            if (player.shield)
                            {
                                player.shield = false;
                            }
                            else
                            {
                            player.setDead(true, this.spearOwner, "SPEAR");
                            Hit_Player_Sound.Play();
                        }

                        //Wrap-around collisions
                        if(this.spear.X <= spear.Width)
                        {
                            Rectangle tempRect = new Rectangle((int)(spear.X + SCREENSIZE.X), (int)spear.Y, spear.Width, spear.Height);
                            if (VectorMath.rectCollision(tempRect, orientation, player.getPlayerRect(), 0, new Point(16, 8)))//player.getPlayerRect().Intersects(tempRect))
                            {
                                player.setDead(true, this.spearOwner, "SPEAR");
                                Hit_Player_Sound.Play();
                            }
                        }
                        else if(this.spear.X >= SCREENSIZE.X - this.spear.Width)
                        {
                            Rectangle tempRect = new Rectangle((int)(spear.X - SCREENSIZE.X - 32), (int)spear.Y, spear.Width, spear.Height);
                            if (VectorMath.rectCollision(tempRect, orientation, player.getPlayerRect(), 0, new Point(16, 8)))//player.getPlayerRect().Intersects(tempRect))
                            {
                                player.setDead(true, this.spearOwner, "SPEAR");
                                Hit_Player_Sound.Play();
                            }
                        }
                    }
                }
            }
            if (!attachedToPlayer)
            {
                foreach (PlayerClass p in players)
                {
                    if(p != null) { 
                        if (!attachedToPlayer && !throwing)
                        {
                            //Rectangle inter = Rectangle.Intersect(p.getPlayerRect(), spear);//new Rectangle((int)spear.X,(int)spear.Y, spear.Width, spear.Height));
                            Rectangle adjustedRect = new Rectangle(spear.Location, spear.Size);
                            adjustedRect.X -= 27;
                            bool hit = VectorMath.rectCollision(adjustedRect, orientation+(float)(Math.PI/2), p.getPlayerRect(), 0, new Point(16, 8));

                            if (!hit && spear.X > SCREENSIZE.X - spear.Width / 2)
                            {
                                Rectangle dupePos = new Rectangle((int)(adjustedRect.X - SCREENSIZE.X), adjustedRect.Y, adjustedRect.Width, adjustedRect.Height);
                                hit = VectorMath.rectCollision(dupePos, orientation - (float)(Math.PI / 2), p.getPlayerRect(), 0, new Point(16, 8));

                            }

                            if (!hit && spear.Y > SCREENSIZE.Y - spear.Width / 2)
                            {
                                Rectangle dupePos = new Rectangle((int)(adjustedRect.X), (int)(adjustedRect.Y - SCREENSIZE.Y), adjustedRect.Width, adjustedRect.Height);
                                hit = VectorMath.rectCollision(dupePos, orientation, p.getPlayerRect(), 0, new Point(16, 8));

                            }

                            if (hit && !p.hasSpear && !throwing && !p.dead)
                            {
                                gravityEffect = 0;
                                attachedToPlayer = true;
                                setOwner(p);
                                spearOwner.setSpear(this);
                                isInUse = false;
                                throwing = false;
                                p.hasSpear = true;
                                dropped = false;
                            }
                        }
                        if (!atRest && thrownBy != null && p.blinked == thrownBy.blinked)
                        {
                            Rectangle adjustedRect = new Rectangle(spear.Location, spear.Size);
                            adjustedRect.X -= 27;
                            bool hit = VectorMath.rectCollision(adjustedRect, orientation, p.getPlayerRect(), 0, new Point(16, 8));

                            if (!hit && spear.X > SCREENSIZE.X - spear.Width / 2)
                            {
                                Rectangle dupePos = new Rectangle((int)(adjustedRect.X - SCREENSIZE.X), adjustedRect.Y, adjustedRect.Width, adjustedRect.Height);
                                hit = VectorMath.rectCollision(dupePos, orientation - (float)(Math.PI / 2), p.getPlayerRect(), 0, new Point(16, 8));

                            }

                            if (!hit && spear.Y > SCREENSIZE.Y - spear.Width / 2)
                            {
                                Rectangle dupePos = new Rectangle((int)(adjustedRect.X), (int)(adjustedRect.Y - SCREENSIZE.Y), adjustedRect.Width, adjustedRect.Height);
                                hit = VectorMath.rectCollision(dupePos, orientation, p.getPlayerRect(), 0, new Point(16, 8));

                            }

                            if (hit && spearOwner != p && !p.dead && !dropped)
                            {
                                if (p.shield)
                                {
                                    p.shield = false;
                                }
                                //ask david about how this should work
                                else if (p.spearCatch && !p.hasSpear)
                                {
                                    p.spearCatch = false;
                                    //pickup spear
                                    gravityEffect = 0;
                                    attachedToPlayer = true;
                                    setOwner(p);
                                    spearOwner.setSpear(this);
                                    isInUse = false;
                                    throwing = false;
                                    p.hasSpear = true;
                                }
                                else
                                {
                                    if(bomb)
                                    {
                                        bombExplosion();
                                        bomb = false;
                                    }
                                p.setDead(true, thrownBy, "SPEAR");
                                Hit_Player_Sound.Play();
                            }

                            //When the spear first leaves the one who threw its hitbox, make it live.
                            if(!hit && spearOwner != null && spearOwner == p)
                            {
                                isInUse = false;
                                attachedToPlayer = false;
                                if(spearOwner.spear == this)
                                {
                                    spearOwner.hasSpear = false;
                                    spearOwner.setSpear(null);
                                }
                                    
                                setOwner(null);
                        }
                        }
                    }
                }
            }
            }

        }