Esempio n. 1
0
File: Game1.cs Progetto: Cirae/Blink
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            player = new PlayerClass();
            map1 = new Map();

            base.Initialize();
        }
Esempio n. 2
0
 public void Initialize()
 {
     player1 = players[0];
     player2 = players[1];
     player3 = players[2];
     player4 = players[3];
     dummy = new PlayerClass();
     dummy.score = -100;
     rank = new PlayerClass[4];
     rankp = new List<PlayerClass>();
     ranking = new List<PlayerClass>();
     pos = new Vector2[4];
     nextState = null;
     map1 = new Map();
 }
Esempio n. 3
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);
 }
Esempio n. 4
0
 public void reset(PlayerClass p, Map newMap)
 {
     if (p == null)
         return;
     gravityEffect = 0;
     setOwner(p);
     //Width = spear.Width;
     //Height = spear.Height;
     velocity.X = 0;
     velocity.Y = 0;
     spearOrientation = 0;
     isInUse = false;
     throwing = false;
     attachedToPlayer = true;
     atRest = true;
     spear.X = spearOwner.getPlayerRect().X;
     spear.Y = spearOwner.getPlayerRect().Y;
     spearOwner.setSpear(this);
     this.m = newMap;
 }
Esempio n. 5
0
        /*
         * //Loops through the other players to check for collisions. There are Four major cases:
         * //      (Horizontal) Players are moving in opposite directions  -> both players have their horizontal movement ceased.
         * //      (Horizontal) Players are moving in the same direction   -> The faster player has their horizontal velocity matched to the other
         * //      (Vertical) Players are moving in opposite directions  -> One player gets a boost, the other dies
         * //      (Vertical) Players are moving in the same direction   -> Slight difference in the positioning
         */
        public void playerCollision()
        {
            PlayerClass[] checkedPlayers = new PlayerClass[4];
            int           counter        = 0;

            foreach (PlayerClass p in players)
            {
                //Make sure we're not checking a collision that wasn't already checked
                Boolean alreadyChecked = false;
                foreach (PlayerClass checkedPlayer in checkedPlayers)
                {
                    if (checkedPlayer == p)
                    {
                        alreadyChecked = true;
                    }
                }
                checkedPlayers[counter] = this;
                counter += 1;
                //Make sure we're not checking self collision, or dead players
                Boolean collided;
                if (p != null && p != this && !p.dead && !alreadyChecked && blinked == p.blinked)
                {
                    collided = doCollisions(playerRect, oldPos, p.playerRect, p.oldPos, p);

                    if (!collided)
                    {
                        Rectangle loopRectA = new Rectangle(playerRect.X, playerRect.Y, playerRect.Width, playerRect.Height);
                        loopRectA = loopRectangle(loopRectA);
                        Vector2 loopOldRectA = new Vector2(oldPos.X, oldPos.Y);
                        loopOldRectA = loopVector(loopOldRectA, playerRect.Width, playerRect.Height);
                        Rectangle loopRectB = new Rectangle(p.playerRect.X, p.playerRect.Y, p.playerRect.Width, p.playerRect.Height);
                        loopRectB = loopRectangle(loopRectB);
                        Vector2 loopOldRectB = new Vector2(p.oldPos.X, p.oldPos.Y);
                        loopOldRectB = loopVector(loopOldRectB, p.playerRect.Width, p.playerRect.Height);

                        collided = doCollisions(loopRectA, loopOldRectA, loopRectB, loopOldRectB, p);
                    }
                }
            }
        }
Esempio n. 6
0
        public void throwKilled(PlayerClass killed, PlayerClass killer, string method)
        {
            if (onPlayerKilled == null)
            {
                return;
            }
            Death_Sound.Play();
            if (killer == killed)
            {
                killer.score -= 1;
            }
            else if (killer != null)
            {
                killer.score += 1;
            }
            else
            {
                killed.score -= 1;
            }
            DeathEventArgs args = new DeathEventArgs(killed, killer, method);

            onPlayerKilled(this, args);
        }
Esempio n. 7
0
File: Map.cs Progetto: dah6ce/Blink
        public void Initialize(Texture2D mText, String cMap, int tS, int mX, int mY, PlayerClass[] p, Texture2D power)
        {
            mapTexture = mText;
            mapSize = new Vector2(mX, mY);
            tileSize = tS;
            mapCollisions(cMap);
            players = p;
            powerup = power;

            for(int player = 0; player < 4; player++)
            {
                if(playerStarts[player] != null && players[player] != null && players[player].active)
                    players[player].setPos(playerStarts[player]);
            }
        }
Esempio n. 8
0
 public void setThrownBy(PlayerClass owner)
 {
     thrownBy = owner;
 }
Esempio n. 9
0
 internal void setOwner(PlayerClass player) //set new Spear owner to player
 {
     spearOwner = player;
     if (spearOwner != null)
     {
         spearOwner.hasSpear = true;
     }
 }
Esempio n. 10
0
 internal void dropSpear()
 {
     spear.X = spearOwner.getPlayerRect().X+spearOwner.getPlayerRect().Width/2;
     spear.Y = spearOwner.getPlayerRect().Y;
     spearOwner.setSpear(null);
     spearOwner = null;
     attachedToPlayer = false;
     isInUse = false;
     throwing = false;
     dropped = true;
     atRest = false;
 }
Esempio n. 11
0
 private void declareVictor(PlayerClass victor)
 {
     if(victor != null)
         victor.winner();
     roundReset = 3;
     detectEndOfGame();
 }
Esempio n. 12
0
        public void Initialize()
        {
            player1 = new PlayerClass();
            player2 = new PlayerClass();
            player3 = new PlayerClass();
            player4 = new PlayerClass();

            returnState = null;

            animations = new List<Animation>();

            player1.title = "P1";
            player2.title = "P2";
            player3.title = "P3";
            player4.title = "P4";

            player1.onPlayerKilled += new PlayerClass.PlayerKilledHandler(playerKilled);
            player2.onPlayerKilled += new PlayerClass.PlayerKilledHandler(playerKilled);
            player3.onPlayerKilled += new PlayerClass.PlayerKilledHandler(playerKilled);
            player4.onPlayerKilled += new PlayerClass.PlayerKilledHandler(playerKilled);

            currPlayer = PlayerKeys.Player1;
            paused = false;
            playerPaused = 0;
            AudioManager.TriggerBattle();
        }
Esempio n. 13
0
 public void setPlayers(PlayerClass[] players)
 {
     this.players = players;
 }
Esempio n. 14
0
        public Boolean doCollisions(Rectangle rectA, Vector2 oldRectA, Rectangle rectB, Vector2 oldRectB, PlayerClass p)
        {
            Rectangle inter = Rectangle.Intersect(rectB, rectA);

            if (inter.Width > 0 && inter.Height > 0)
            {
                Boolean xCollision = true, yCollision = true;
                //Keeps track of the total relative distance traveled
                Vector2 distTraveled = new Vector2(Math.Abs(p.velocity.X - this.velocity.X), Math.Abs(p.velocity.Y - this.velocity.Y));

                //This deals with face collisions, where the objects already 'collided' on the X or Y plane
                if ((oldRectA.X >= oldRectB.X && oldRectA.X <= oldRectB.X + rectB.Width - 1) || (oldRectA.X + rectA.Width - 1 >= oldRectB.X && oldRectA.X + rectA.Width - 1 <= oldRectB.X + rectB.Width - 1))
                {
                    xCollision = false;
                }
                else if ((oldRectA.Y >= oldRectB.Y && oldRectA.Y <= oldRectB.Y + rectB.Height - 1) || (oldRectA.Y + rectA.Height - 1 >= oldRectB.Y && oldRectA.Y + rectA.Height - 1 <= oldRectB.Y + rectB.Height - 1))
                {
                    yCollision = false;
                }

                //If it's not a face collision, it's a dreaded diagonal...
                if (xCollision && yCollision)
                {
                    //Whichever direction the collision occurs at a higher velocity is assumed to be the 'first' collision.
                    //If they are even we go with a horizontal collision
                    //This might have to be refined if the collisions feel sloppy
                    if (distTraveled.X < distTraveled.Y)
                    {
                        yCollision = false;
                    }
                    else
                    {
                        xCollision = false;
                    }
                }

                if (xCollision)
                {
                    //Case 1, the directions are different.
                    if (((this.velocity.X < 0) ? (p.velocity.X >= 0) : (p.velocity.X <= 0)))
                    {
                        int thisDist, otherDist;
                        if (this.velocity.X == 0)
                        {
                            otherDist = Math.Abs((int)Math.Floor(inter.Width * (p.velocity.X / distTraveled.X)));
                            thisDist  = inter.Width - otherDist;
                        }
                        else
                        {
                            thisDist  = Math.Abs((int)Math.Floor(inter.Width * (this.velocity.X / distTraveled.X)));
                            otherDist = inter.Width - thisDist;
                        }


                        if (this.velocity.X < 0)
                        {
                            playerRect.X   += thisDist;
                            p.playerRect.X -= otherDist;
                            this.velocity.X = 0;
                            p.velocity.X    = 0;
                        }
                        else
                        {
                            playerRect.X   -= thisDist;
                            p.playerRect.X += otherDist;
                            this.velocity.X = 0;
                            p.velocity.X    = 0;
                        }
                    }
                    //Case 2, the directions are the same.
                    else
                    {
                        if (Math.Abs(this.velocity.X) > Math.Abs(p.velocity.X))
                        {
                            if (this.velocity.X > 0)
                            {
                                playerRect.X = p.playerRect.X - playerRect.Width;
                            }
                            else if (this.velocity.X < 0)
                            {
                                playerRect.X = p.playerRect.X + p.playerRect.Width;
                            }
                        }
                    }
                }
                else if (yCollision)
                {
                    //Case 3, collision is vertical and opposite directions.
                    //if (((this.velocity.Y < 0) ? (p.velocity.Y >= 0) : (p.velocity.Y <= 0)))
                    //{
                    int thisDist  = Math.Abs((int)Math.Floor(inter.Height * (this.velocity.Y / distTraveled.Y)));
                    int otherDist = inter.Height - thisDist;

                    if (this.velocity.Y < 0)
                    {
                        playerRect.Y   += thisDist;
                        p.playerRect.Y -= otherDist;
                        this.velocity.Y = 20;
                        p.velocity.Y    = -20;
                        this.setDead(true, p, "STOMP");
                        //this.rectA.Height = rectA.Height / 2;
                        //this.rectA.Y += rectA.Height;
                    }
                    else
                    {
                        playerRect.Y   -= thisDist;
                        p.playerRect.Y += otherDist;
                        this.velocity.Y = -20;
                        p.velocity.Y    = 20;
                        p.setDead(true, this, "STOMP");
                        //rectB.Height = rectB.Height / 2;
                        //rectB.Y += rectB.Height;
                    }
                }
                return(true);
            }
            return(false);
        }
Esempio n. 15
0
 public DeathEventArgs(PlayerClass killed, PlayerClass killer, String method)
 {
     Killed = killed;
     Killer = killer;
     Method = Method;
 }
Esempio n. 16
0
 public DeathEventArgs(PlayerClass killed, PlayerClass killer, String method)
 {
     Killed = killed;
     Killer = killer;
     Method = Method;
 }