Example #1
0
 public void Drink(DrinkSpawner drink)
 {
     if(stance != Stance.DRINKING)
     {
         stance = Stance.DRINKING;
         this.drink = drink;
         DrunkBuffer += drink.DrinkStrength;
     }
     ////play the drink animation
     //stance = Stance.DRINKING;
     //if (!model.isPlaying("GrabDrink"))
     //{
     //    //play the drinking aniamtion
     //    model.PlayAnimation("GrabDrink", false);
     //    this.drink = drink;
     //    DrunkBuffer += drink.DrinkStrength;
     //    animationSpeed = 1;
     //    DrunkBuffer += drink.DrinkStrength;
     //}
 }
Example #2
0
        public void update(float frameMultiplier)
        {
            GamePadState state = GamePad.GetState(player);

            if(!state.IsConnected)
            {
                isConnected = false;
                isPaused = true;
                disconnected = (int)player;
            }

            if(!isConnected)
            {
                if(state.IsConnected)
                {
                    isPaused = false;
                    isConnected = true;
                    disconnected = -1;
                }
            }

            //check to see if the player is pausing
            if(state.Buttons.Start == ButtonState.Pressed)
            {
                isPaused = true;
            }
            PauseMenu.update(state);
            if(!isPaused)
            {
                if(!IsDead)
                {
                    switch(stance)
                    {
                        case Stance.FLINCHING:
                            {
                                if(model.isFinished())
                                {
                                    stance = Stance.NOTHING;
                                }
                                leftRumbleStrength -= 20;
                                rightRumbleStrength -= 20;
                                break;
                                ;
                            }
                        case Stance.DRINKING:
                            {
                                //check to see if the drink animation is playing
                                if(!model.isPlaying("GrabDrink"))
                                {
                                    model.PlayAnimation("GrabDrink", false);
                                    animationSpeed = 1;
                                }

                                if(model.isFinished())
                                {
                                    drink = null;
                                    stance = Stance.NOTHING;
                                }
                                else
                                {
                                    //update the drink
                                    Vector3 newDrinkPos = Vector3.Transform(model.getBone("palm_middle_R").Translation, WorldMatrix);
                                    drink.X = newDrinkPos.X;
                                    drink.Y = newDrinkPos.Y;
                                    drink.Z = newDrinkPos.Z;
                                    drink.RotX = model.getBone("palm_middle_R").Down.X;
                                    drink.RotY = model.getBone("palm_middle_R").Up.Y;
                                    drink.RotZ = model.getBone("palm_middle_R").Left.Z;
                                    drink.updateMatrix();
                                }
                                break;
                            }
                        case Stance.NOTHING:
                            {
                                leftRumbleStrength = rightRumbleStrength = 0;
                                //check for attacks

                                //check for jab
                                if(state.Buttons.Y == ButtonState.Pressed)
                                {
                                    if(left)
                                    {
                                        stance = Stance.LEFTJAB;
                                    }
                                    else
                                    {
                                        stance = Stance.RIGHTJAB;
                                    }
                                }

                                //check for punch
                                if(state.Buttons.X == ButtonState.Pressed)
                                {
                                    if(left)
                                    {
                                        stance = Stance.LEFTPUNCH;
                                    }
                                    else
                                    {
                                        stance = Stance.RIGHTPUNCH;
                                    }
                                }

                                //check for block
                                if(state.Buttons.RightShoulder == ButtonState.Pressed)
                                {
                                    stance = Stance.BLOCKING;
                                }

                                if (Math.Abs(state.ThumbSticks.Left.X / 2) > 0.1 || Math.Abs(state.ThumbSticks.Left.Y / 2) > 0.1)
                                {
                                    if (!model.isPlaying("WalkFight"))
                                    {
                                        model.PlayAnimation("WalkFight", true);
                                    }
                                    LastX = X;
                                    X = X - (state.ThumbSticks.Left.X / 2);//*frameMultiplier);
                                    LastZ = Z;
                                    Z = Z + (state.ThumbSticks.Left.Y / 2);//*frameMultiplier);
                                    RotY = (float)Math.Atan2(state.ThumbSticks.Left.X * -1, state.ThumbSticks.Left.Y);
                                    animationSpeed = (float)Math.Sqrt(Math.Pow(state.ThumbSticks.Left.X * 4, 2) + Math.Pow(state.ThumbSticks.Left.Y * 4, 2));
                                }
                                else
                                {
                                    animationSpeed = 1;
                                    if (!model.isPlaying("StandingStill"))
                                    {
                                        model.PlayAnimation("StandingStill", true);
                                    }
                                }
                                break;
                            }
                        case Stance.BLOCKING:
                            {
                                //check to see if the blocking animation is playing and if it is not play it
                                if(!model.isPlaying("Blocking"))
                                {
                                    //play the block animation
                                    model.PlayAnimation("Blocking", false);
                                    animationSpeed = 1;
                                }

                                //check to see if the block animation is finished and is it is stop blocking
                                if(model.isFinished())
                                {
                                    stance = Stance.NOTHING;
                                }

                                break;
                            }
                        case Stance.LEFTJAB:
                            {
                                //check to see if the jabbing animation is playing and if it is not play it
                                if(!model.isPlaying("LeftJab"))
                                {
                                    model.PlayAnimation("LeftJab", false);
                                    animationSpeed = JABSPEED;
                                }

                                //check to see if it is finished
                                if(model.isFinished())
                                {
                                    left = false;
                                    stance = Stance.NOTHING;
                                }
                                break;
                            }
                        case Stance.RIGHTJAB:
                            {
                                if(!model.isPlaying("RightJab"))
                                {
                                    model.PlayAnimation("RightJab", false);
                                    animationSpeed = JABSPEED;
                                }

                                if(model.isFinished())
                                {
                                    left = true;
                                    stance = Stance.NOTHING;
                                }
                                break;
                            }
                        case Stance.LEFTPUNCH:
                            {
                                if(!model.isPlaying("LeftPunch"))
                                {
                                    model.PlayAnimation("LeftPunch", false);
                                    animationSpeed = PUNCHSPEED;
                                }

                                if(model.isFinished())
                                {
                                    left = false;
                                    stance = Stance.NOTHING;
                                }
                                break;
                            }

                        case Stance.RIGHTPUNCH:
                            {
                                if(!model.isPlaying("RightPunch"))
                                {
                                    model.PlayAnimation("RightPunch", false);
                                    animationSpeed = PUNCHSPEED;
                                }

                                if(model.isFinished())
                                {
                                    left = true;
                                    stance = Stance.NOTHING;
                                }
                                break;
                            }
                    }
                    model.Update(animationSpeed);
                    DrunkBuffer -= drunkDepletion;
                    //update the matrix
                    updateMatrix();
                    //update the fists positions

                    //update the left fist
                    Vector3 point = Vector3.Transform(model.getBone("hand_L").Translation, WorldMatrix);
                    leftFist.OrigenX = point.X;
                    leftFist.OrigenY = point.Y;
                    leftFist.OrigenZ = point.Z;

                    //update the right fist
                    point = Vector3.Transform(model.getBone("hand_R").Translation, WorldMatrix);
                    rightFist.OrigenX = point.X;
                    rightFist.OrigenY = point.Y;
                    rightFist.OrigenZ = point.Z;
                    GamePad.SetVibration(player, leftRumbleStrength / 100.0f, rightRumbleStrength / 100.0f);
                }
                else
                {
                    //make sure the stance is nothing
                    stance = Stance.NOTHING;
                    GamePad.SetVibration(player, 0, 0);
                    //player is dead so play the death animation
                    if(!model.isPlaying("KnockOut"))
                    {
                        model.PlayAnimation("KnockOut", false);
                    }
                    model.Update(animationSpeed);
                }
            }
            else
            {
                if ((PauseMenu.IsSelected(0) && state.Buttons.X == ButtonState.Pressed))
                {
                    isPaused = false;
                }
                else
                if (PauseMenu.IsSelected(1) && state.Buttons.X == ButtonState.Pressed)
                {
                    isPaused = false;
                    parent.resetTimers();
                    parent.playMusic();
                    room.stopSound();
                    parent.gameState = Game1.GameState.MainMenu;

                }
            }
        }
Example #3
0
        public bool loadRoom(string roomAddress, ContentManager content, Shader shader, GraphicsDevice device,string[] selectCombatants)
        {
            //load the menu
            Texture2D exit = content.Load<Texture2D>("Exit");
            Texture2D resume = content.Load<Texture2D>("Resume");

            Combatant.PauseMenu = new Menu(4, new Rectangle(
                parent.ScreenWidth / 2 - (exit.Width / 2),
                parent.ScreenHeight / 2 - (exit.Height / 2 * 2),
                exit.Width,
                exit.Height),
                resume, exit);
            hasWon = false;
            BFFileReader reader = new BFFileReader(roomAddress);
            reader.Open();

            Dictionary<string, RefModel> modelDefs = new Dictionary<string, RefModel>();
            string line;
            //read all of the info in the script
            #region room parser
            while ((line = reader.ReadLine()) != null)
            {
                string[] param = line.Split(' ');

                //read the param
                switch (param[0])
                {
                    case "ModelDef":
                        {
                            //add the new modelname to the hashtable
                            BFModel model = new BFModel();//***
                            model.model = content.Load<Model>(param[1]);
                            shader.setEffects(model);
                            //add the model to the hashtable of models
                            models.Add(param[1], model);
                            break;
                        }
                    case "Music":
                        {
                            //set music
                            music = content.Load<SoundEffect>(param[1]);
                            break;
                        }
                    case "Model":
                        {
                            string modelName = param[1];
                            RefModel refModel = new RefModel();
                            while ((line = reader.ReadLine()) != null && line != "}")
                            {
                                //keep reading into this modelRef
                                param = line.Split(' ');
                                switch (param[0])
                                {
                                    case "ModelID":
                                        {
                                            //set the model id of this ref mode
                                            refModel.ModelID = param[1];

                                            break;
                                        }
                                    case "CollideType":
                                        {
                                            switch (param[1].ToUpper())
                                            {
                                                case "AABB":
                                                    {
                                                        refModel.ORIGEN = new AABB();
                                                        refModel.CollisionType = Origen.Collision_Type.AABB;

                                                        break;
                                                    }
                                                case "NONE":
                                                    {
                                                        refModel.CollisionType = Origen.Collision_Type.NONE;
                                                        break;
                                                    }
                                                case "BC":
                                                    {
                                                        refModel.ORIGEN = new BC();
                                                        refModel.CollisionType = Origen.Collision_Type.BC;
                                                        break;
                                                    }
                                                case "BS":
                                                    {
                                                        refModel.ORIGEN = new BS();
                                                        refModel.CollisionType = Origen.Collision_Type.BS;
                                                        break;
                                                    }
                                            }
                                            break;
                                        }
                                    case "OrigenX":
                                        {
                                            refModel.X = float.Parse(param[1]);
                                            break;
                                        }
                                    case "OrigenY":
                                        {
                                            refModel.Y = float.Parse(param[1]);
                                            break;
                                        }
                                    case "OrigenZ":
                                        {
                                            refModel.Z = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotX":
                                        {
                                            refModel.RotX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotY":
                                        {
                                            refModel.RotY = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotZ":
                                        {
                                            refModel.RotZ = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfWidth":
                                        {
                                            refModel.HalfWidth = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfHeight":
                                        {
                                            refModel.HalfHeight = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfLength":
                                        {
                                            refModel.HalfLength = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Radius":
                                        {
                                            refModel.Radius = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransX":
                                        {
                                            refModel.TransX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransY":
                                        {
                                            refModel.TransY = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransZ":
                                        {
                                            refModel.TransZ = float.Parse(param[1]);
                                            break;
                                        }
                                }

                            }

                            refModel.updateMatrix();
                            //add the refmodel to the list of modelsDefs
                            modelDefs.Add(modelName, refModel);
                            break;
                        }

                    case "DrinkSpawner":
                        {
                            string modelID = "";
                            float X = 0, Y = 0, Z = 0, RotX = 0, RotY = 0, RotZ = 0,spawnTime = 0,drinkStrength = 0,
                                halfWidth = 0,halfLength = 0,halfHeight = 0,transX = 0,transY = 0,transZ = 0;
                            while ((line = reader.ReadLine()) != null && line != "}")
                            {
                                param = line.Split(' ');
                                switch (param[0])
                                {
                                    case "X":
                                        {
                                            X = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Y":
                                        {
                                            Y = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Z":
                                        {
                                            Z = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotX":
                                        {
                                            RotX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotY":
                                        {
                                            RotY = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotZ":
                                        {
                                            RotZ = float.Parse(param[1]);
                                            break;
                                        }
                                    case "ModelID":
                                        {
                                            modelID = param[1];
                                            break;
                                        }
                                    case "SpawnTime":
                                        {
                                            spawnTime = float.Parse(param[1]);
                                            break;
                                        }
                                    case "DrinkStrength":
                                        {
                                            drinkStrength = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfWidth":
                                        {
                                            halfWidth = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfHeight":
                                        {
                                            halfHeight= float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfLength":
                                        {
                                            halfLength = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransX":
                                        {
                                            transX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransZ":
                                        {
                                            transZ = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransY":
                                        {
                                            transY = float.Parse(param[1]);
                                            break;
                                        }

                                }

                            }

                            DrinkSpawner drinkSpawner = new DrinkSpawner();
                            drinkSpawner.CollisionType = Origen.Collision_Type.AABB;
                            drinkSpawner.ORIGEN = new AABB();
                            drinkSpawner.X = X;
                            drinkSpawner.Y = Y;
                            drinkSpawner.Z = Z;
                            drinkSpawner.StartX = X;
                            drinkSpawner.StartY = Y;
                            drinkSpawner.StartZ = Z;
                            drinkSpawner.DrinkStrength = drinkStrength;
                            drinkSpawner.HalfHeight = halfHeight;
                            drinkSpawner.HalfLength = halfLength;
                            drinkSpawner.HalfWidth = halfWidth;
                            drinkSpawner.ModelID = modelID;
                            drinkSpawner.RotX = RotX;
                            drinkSpawner.RotY = RotY;
                            drinkSpawner.RotZ = RotZ;
                            drinkSpawner.TransX = transX;
                            drinkSpawner.TransY = transY;
                            drinkSpawner.TransZ = transZ;
                            drinkSpawner.DrinkSpawnTime = spawnTime;
                            drinkSpawner.SpawnTime = spawnTime;
                            drinkSpawner.updateMatrix();
                            drinks.Add(drinkSpawner);
                            break;
                        }

                    case "ModelGroup":
                        {
                            List<string> includedModels = new List<string>();
                            float X = 0, Y = 0, Z = 0, RotX = 0, RotY = 0, RotZ = 0;
                            while ((line = reader.ReadLine()) != null && line != "}")
                            {
                                param = line.Split(' ');
                                switch (param[0])
                                {
                                    case "X":
                                        {
                                            X = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Y":
                                        {
                                            Y = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Z":
                                        {
                                            Z = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotX":
                                        {
                                            RotX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotY":
                                        {
                                            RotY = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotZ":
                                        {
                                            RotZ = float.Parse(param[1]);
                                            break;
                                        }
                                    case "IncludeModel":
                                        {
                                            includedModels.Add(param[1]);
                                            break;
                                        }
                                }

                            }

                            //now add the models to the scenes models
                            foreach (string modelName in includedModels)
                            {
                                //load the model to copy the model data from
                                RefModel temp = (RefModel)modelDefs[modelName];
                                RefModel copy = new RefModel();
                                copy.ORIGEN = new AABB();
                                copy.ORIGEN.Type = Origen.Collision_Type.AABB;
                                copy.HalfHeight = temp.HalfHeight;
                                copy.HalfLength = temp.HalfLength;
                                copy.HalfWidth = temp.HalfWidth;
                                copy.X = temp.X + X;
                                copy.Y = temp.Y + Y;
                                copy.Z = temp.Z + Z;
                                copy.RotX = temp.RotX + RotX;
                                copy.RotY = temp.RotY + RotY;
                                copy.RotZ = temp.RotZ + RotZ;
                                copy.TransX = temp.TransX;
                                copy.TransY = temp.TransY;
                                copy.TransZ = temp.TransZ;
                                copy.ModelID = temp.ModelID;
                                copy.updateMatrix();
                                //add the copy
                                parts.Add(copy);
                            }
                            break;
                        }

                    case "XWidth":
                        {
                            xWidth = float.Parse(param[1]);
                            break;
                        }

                    case "YWidth":
                        {
                            yWidth = float.Parse(param[1]);
                            break;
                        }

                    case "ZWidth":
                        {
                            zWidth = float.Parse(param[1]);
                            break;
                        }
                    case "LeftWallTexture":
                        {
                            leftWallTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "RightWallTexture":
                        {
                            rightWallTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "FrontWallTexture":
                        {
                            frontWallTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "BackWallTexture":
                        {
                            backWallTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "CeilingTexture":
                        {
                            ceilingTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "FloorTexture":
                        {
                            floorTex = content.Load<Texture2D>(param[1]);
                            break;
                        }

                    case "Light":
                        {
                            switch (param[1])
                            {
                                case "X":
                                    {
                                        lightPos.X = float.Parse(param[2]);
                                        break;
                                    }
                                case "Y":
                                    {
                                        lightPos.Y = float.Parse(param[2]);
                                        break;
                                    }
                                case "Z":
                                    {
                                        lightPos.Z = float.Parse(param[2]);
                                        break;
                                    }
                                case "Power":
                                    {
                                        lightPower = float.Parse(param[2]);
                                        break;
                                    }
                                case "Ambient":
                                    {
                                        ambientPower = float.Parse(param[2]);
                                        break;
                                    }

                            }
                            break;
                        }
                    case "FloorXDensity":
                        {
                            floorXDensity = float.Parse(param[1]);
                            break;
                        }
                    case "FloorYDensity":
                        {
                            floorYDensity = float.Parse(param[1]);
                            break;
                        }
                    case "WallXDensity":
                        {
                            wallXDensity = float.Parse(param[1]);
                            break;
                        }
                    case "WallYDensity":
                        {
                            wallYDensity = float.Parse(param[1]);
                            break;
                        }
                    case "BarX":
                        {
                            barX = float.Parse(param[1]);
                            break;
                        }
                    case "BarY":
                        {
                            barY = float.Parse(param[1]);
                            break;
                        }
                    case "BarWidth":
                        {
                            barWidth = float.Parse(param[1]);
                            break;
                        }

                }
            }
            #endregion
            //close the file
            reader.Close();

            //play the music if the music exists
            if (music != null)
            {
                instance = music.CreateInstance();
                instance.IsLooped = true;
                instance.Play();
            }

            winSong = content.Load<SoundEffect>("WinSong").CreateInstance();
            winSong.IsLooped = true;
            //set up the bounding box for the room

            //init the buffers
            initBuffers(device);

            bounds = new AABB(0, 0, 0, xWidth, yWidth, zWidth);
            //load the combatants after clearing the list of the old ones
            combatants.Clear();
            loadCombatants(content,selectCombatants,parent.NumOfPlayers);

            return true;
        }