Пример #1
0
        public void StateMachine(ref double delta, KeyboardState keyboardState,ref float speed, ref GamePadState gamePadState,ref float turn)
        {
            switch (state)
            {
                case States.Start:
                    location.Y = 0;
                    state = States.StanceStart;
                    delta = 0;
                    break;

                case States.StanceStart:
                    location.Y = 0;
                    spineOrientation = 0;
                    victoria.PlayClip("raiseB");
                    victoria.AnimPlayer.Speed = 0;
                    state = States.Stance;
                    break;

                case States.Stance:
                    speed = GetDesiredSpeed(ref keyboardState, ref gamePadState);
                    location.Y = 0;
                    if (speed > 0)
                    {
                        // We need to leave the stance state and start walking
                        victoria.PlayClip("walkstartB");
                        victoria.AnimPlayer.Speed = speed;
                        state = States.WalkStart;
                    }
                    else if (turn > 0)
                    {
                        victoria.PlayClip("leftturn");
                        state = States.LeftStart;
                    }
                    else if (turn < 0)
                    {
                        victoria.PlayClip("rightturn");
                        state = States.RightStart;
                    }
                    else if (keyboardState.IsKeyDown(Keys.RightControl) || keyboardState.IsKeyDown(Keys.LeftControl))
                    {
                        state = States.crouchStart;
                    }
                    else if (keyboardState.IsKeyDown(Keys.Enter))
                    {
                        state = States.startaiming;
                    }

                    break;

                case States.WalkStart:
                case States.WalkLoop:

                    if (delta > victoria.AnimPlayer.Clip.Duration - victoria.AnimPlayer.Time)
                    {
                        delta = victoria.AnimPlayer.Clip.Duration - victoria.AnimPlayer.Time;
                        location.Y = 0;
                        // The clip is done after this update
                        state = States.WalkLoopStart;
                    }

                    speed = GetDesiredSpeed(ref keyboardState, ref gamePadState);
                    if (speed == 0)
                    {
                        delta = 0;
                        state = States.StanceStart;
                    }
                    else
                    {
                        victoria.AnimPlayer.Speed = speed;
                    }

                    break;
                case States.WalkLoopStart:
                    victoria.PlayClip("walkloopB");
                    victoria.PlayClip("walkloopB").Speed = GetDesiredSpeed(ref keyboardState, ref gamePadState);
                    state = States.WalkLoop;
                    break;
                case States.Left:
                    if (delta > victoria.AnimPlayer.Clip.Duration - victoria.AnimPlayer.Time)
                    {
                        delta = victoria.AnimPlayer.Clip.Duration - victoria.AnimPlayer.Time;
                        location.Y = 0;
                        // The clip is done after this update
                        state = States.LeftStart;
                    }

                    speed = GetDesiredSpeed(ref keyboardState, ref gamePadState);
                    if (speed > 0)
                    {
                        victoria.PlayClip("walkstartB");
                        victoria.AnimPlayer.Speed = speed;
                        state = States.WalkStart;
                    }
                    if (turn <= 0)
                    {
                        delta = 0;
                        state = States.StanceStart;
                    }
                    break;
                case States.LeftStart:
                    {
                        victoria.PlayClip("leftturn").Speed = 1;
                        state = States.Left;
                        break;
                    }
                case States.Right:
                    if (delta > victoria.AnimPlayer.Clip.Duration - victoria.AnimPlayer.Time)
                    {
                        delta = victoria.AnimPlayer.Clip.Duration - victoria.AnimPlayer.Time;
                        location.Y = 0;
                        // The clip is done after this update
                        state = States.RightStart;
                    }

                    speed = GetDesiredSpeed(ref keyboardState, ref gamePadState);
                    if (speed > 0)
                    {
                        victoria.PlayClip("walkstartB");
                        victoria.AnimPlayer.Speed = speed;
                        state = States.WalkStart;
                    }
                    if (turn >= 0)
                    {
                        delta = 0;
                        state = States.StanceStart;
                    }
                    break;
                case States.RightStart:
                    {
                        victoria.PlayClip("rightturn").Speed = 1;
                        state = States.Right;
                        break;
                    }
                case States.startaiming:
                    spineOrientation = 0;
                    victoria.PlayClip("raiseB");
                    victoria.AnimPlayer.Speed = 1;
                    state = States.aiming;
                    break;
                case States.aiming:
                    if (delta > victoria.AnimPlayer.Clip.Duration - victoria.AnimPlayer.Time)
                    {
                        if (keyboardState.IsKeyDown(Keys.Enter))
                        {
                            state = States.StanceStart;
                        }
                        state = States.aimed;
                    }
                    break;
                case States.aimed:
                    location.Y = 0;
                    if (keyboardState.IsKeyDown(Keys.Enter))
                    {
                        state = States.lowerStart;
                    }
                    if (keyboardState.IsKeyDown(Keys.Space) && pieCount > 0 && activePie == null)
                    {
                        if (pieCount > 0 && pieCooldown < 0)
                        {
                            pieCooldown = 1;
                            activePie = createPie();
                            pieCount--;
                            pieNumber = (pieNumber + 1) % 3;
                            ///////
                            if (pieCount > 0)
                                reloadingPie = createReload();
                            ///////

                        }

                    }
                    break;
                case States.lowerStart:

                    victoria.PlayClip("lowerB");
                    victoria.AnimPlayer.Speed = 1;
                    state = States.lowering;
                    break;
                case States.lowering:
                    if (delta > victoria.AnimPlayer.Clip.Duration - victoria.AnimPlayer.Time)
                    {
                        state = States.StanceStart;
                    }
                    spineOrientation = spineOrientation * (1 - .25f * ((float)victoria.AnimPlayer.Time / (float)victoria.AnimPlayer.Clip.Duration));
                    break;
                case States.crouchStart:
                    victoria.PlayClip("crouch");
                    victoria.AnimPlayer.Speed = .5f;
                    state = States.crouching;
                    break;
                case States.crouching:
                    if (delta > victoria.AnimPlayer.Clip.Duration - victoria.AnimPlayer.Time)
                    {
                        state = States.StanceStart;
                    }
                    break;

            }
        }
Пример #2
0
        public void Update(GameTime gameTime)
        {
            int mouseX = Mouse.GetState().X;
                int mouseY= Mouse.GetState().Y;
            if (section == 1 && Mouse.GetState().LeftButton==ButtonState.Pressed && mouseX<=width && mouseX>=0 && mouseY<=height &&mouseY>=0)
            {
                Vector3 nearsource = new Vector3((float)mouseX, (float)mouseY, 0f);
                Vector3 farsource = new Vector3((float)mouseX, (float)mouseY, 1f);

                Matrix world = Matrix.CreateTranslation(0, 0, 0);

                Vector3 nearPoint = game.GraphicsDevice.Viewport.Unproject(nearsource,
                    game.Camera.Projection, game.Camera.View, world);

                Vector3 farPoint = game.GraphicsDevice.Viewport.Unproject(farsource,
                    game.Camera.Projection, game.Camera.View, world);
                Vector3 direction = farPoint - nearPoint;
                direction.Normalize();
                bool test = pieReload.clicked(game.Camera.Eye, direction,4f);
                if (test)
                    pieCount = 10;
            }

            double deltaTotal = gameTime.ElapsedGameTime.TotalSeconds;
            double deltaTotal2=deltaTotal;
            spitCooldown +=(float) gameTime.ElapsedGameTime.TotalSeconds;

            #region spit
            if(drawSpit)
            {
                spitTime+=(float)gameTime.ElapsedGameTime.TotalSeconds;
                if(spitTime>10)
                {
                    drawSpit=false;
                    spitTime=0;
                }
                if(foraward)
                    spitLocation.Z += 150*(float)gameTime.ElapsedGameTime.TotalSeconds;
                else
                    spitLocation.Z -= 150 * (float)gameTime.ElapsedGameTime.TotalSeconds;
              }
            #endregion

            #region pieUpdate
            pieCooldown -= (float)deltaTotal;
            //updating pie location
            if (activePie != null)
                activePie.Update(deltaTotal);
            ////
            if (reloadingPie != null)
            {
                reloadingPie.reloadUpdate(deltaTotal, spineOrientation);
                if (reloadingPie.reloaded)
                    reloadingPie = null;
            }

            ////
            foreach (PieClass pie in stuckPies)
            {
                pie.Update(deltaTotal);
            }
            #endregion

            #region alien Update
            do
            {
                double delta = deltaTotal2;
                dalekInfo.Update(delta, transform.Translation);
                KeyboardState keyboardState = Keyboard.GetState();
                GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);

                AlienStateMachine(ref delta);
                Alien.Update(delta);

               //alien collision
                if (activePie != null)
                {
                    if (Vector3.Distance(alienPosition, activePie.Position) < 150 && alienState==States.pieCatch)
                    {
                        alienState = States.pieEat;
                        activePie.devoured = true;

                    }
                    if(Vector3.Distance(alienPosition,activePie.Position)<500 && alienState!=States.pieCatch && alienState!=States.pieCatchstart && alienState!=States.pieEat)
                    {
                        alienState = States.pieCatchstart;
                        alienOrientation = (float)(Math.PI)-activePie.fireAngle;
                    }
                    else if (alienState == States.pieCatch && Vector3.Distance(alienPosition, activePie.Position) > 600)
                    {
                        if (aboutFace)
                            alienOrientation = (float)Math.PI;
                        else
                            alienOrientation = 0;
                        alienState = States.WalkLoopStart;
                    }
                }
                else if (alienState == States.pieCatch && activePie==null)
                {
                    alienState = States.WalkLoopStart;
                    if (aboutFace)
                        alienOrientation = (float)Math.PI;
                    else
                        alienOrientation = 0;
                }

                if (!drawSpit && Vector3.Distance(location, alienPosition) < 500 && spitCooldown>60)
                {
                    drawSpit = true;
                    spitCooldown = 0;
                    if (location.Z > alienPosition.Z)
                    {
                        alienOrientation = 0;
                        foraward = true;
                    }
                    else
                    {
                        alienOrientation = (float)Math.PI;
                        foraward = false;
                    }
                    spitLocation = alienPosition;
                    spitLocation.Y = 180;
                    alienState = States.spitting;
                }
                 //
                // Part 1:  Compute a new orientation
                //

                    Matrix deltaMatrix = Alien.DeltaMatrix;
                    float deltaAngle = (float)Math.Atan2(deltaMatrix.Backward.X, deltaMatrix.Backward.Z);
                    float newOrientation = alienOrientation + deltaAngle;

                    //
                    // Part 2:  Compute a new location
                    //

                    // We are likely rotated from the angle the model expects to be in
                    // Determine that angle.
                    Matrix rootMatrix = Alien.RootMatrix;
                    float actualAngle = (float)Math.Atan2(rootMatrix.Backward.X, rootMatrix.Backward.Z);
                    Vector3 newLocation;

                    newLocation = alienPosition + Vector3.TransformNormal(Alien.DeltaPosition,
                                   Matrix.CreateRotationY(newOrientation - actualAngle));

                if (alienState == States.spitting)
                {
                    newLocation = alienPosition;
                }
                //
                // I'm just taking these here.  You'll likely want to add something
                // for collision detection instead.
                //
                if (!aboutFace && alienPosition.Z > 800)
                {
                    alienOrientation = (float)Math.PI;
                    aboutFace = true;
                }
                else if (aboutFace && alienPosition.Z < -600)
                {
                    alienOrientation = 0;
                    aboutFace = false;
                }

                alienPosition = newLocation;
                alienMatrix = Matrix.CreateRotationY(alienOrientation) * Matrix.CreateTranslation(alienPosition);
                deltaTotal2 -= delta;
            } while (deltaTotal2 > 0);
            #endregion

            #region VictoriaUpdate
            do
            {
                #region infoUpdate
                double delta = deltaTotal;
                bazooka.Update(delta);
                Pies.Update(delta);
                DalekModel.Update(delta);

                KeyboardState keyboardState = Keyboard.GetState();
                GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
                float speed = 0;

                float turn = GetDesiredTurnRate(ref keyboardState, ref gamePadState) * (float)delta;
                StateMachine(ref delta, keyboardState, ref speed,ref gamePadState, ref turn);

                //
                // State update
                //

                if (state != States.lowering && state != States.lowerStart && state != States.aimed && state != States.aiming && state != States.startaiming)
                    orientation+=turn;
                else if (state == States.aimed)
                {
                    spineOrientation += turn;
                    if (spineOrientation < - Math.PI/3)
                        spineOrientation = (float)-Math.PI / 3;
                    else if (spineOrientation > Math.PI/3)
                        spineOrientation = (float) Math.PI/3;

                }

                victoria.Update(delta);
                //bazooka.Update(delta);
                //
                // Part 1:  Compute a new orientation
                //

                Matrix deltaMatrix = victoria.DeltaMatrix;
                float deltaAngle = (float)Math.Atan2(deltaMatrix.Backward.X, deltaMatrix.Backward.Z);
                float newOrientation = orientation + deltaAngle;

                //
                // Part 2:  Compute a new location
                //

                // We are likely rotated from the angle the model expects to be in
                // Determine that angle.
                Matrix rootMatrix = victoria.RootMatrix;
                float actualAngle = (float)Math.Atan2(rootMatrix.Backward.X, rootMatrix.Backward.Z);
                Vector3 newLocation = location + Vector3.TransformNormal(victoria.DeltaPosition,
                               Matrix.CreateRotationY(newOrientation - actualAngle));

                //
                // I'm just taking these here.  You'll likely want to add something
                // for collision detection instead.
                //

                //location = newLocation;
                orientation = newOrientation;
            #endregion

                #region collision
                Vector3 adjustedLocation = location;
                adjustedLocation.Y = spitLocation.Y;
                if(drawSpit && Vector3.Distance(adjustedLocation,spitLocation)<50 && state!=States.crouching && state!=States.crouchStart)
                {
                    pieHits = 0;
                    Player.isBeingSlimed=true;
                    drawSpit=false;
                    spitTime=0;

                }

                if (activePie != null)
                {
                    String collidsion;
                    if (activePie.pieNumber == 1)
                        collidsion = TestRegion(activePie.Position);
                    else if (activePie.pieNumber == 2)
                        collidsion=TestRegion(activePie.Position-new Vector3(10*(float)Math.Cos(activePie.fireAngle - 1.6),0,-10*(float)Math.Sin(activePie.fireAngle - 1.6)));
                    else
                         collidsion=TestRegion(activePie.Position-new Vector3(20*(float)Math.Cos(activePie.fireAngle - 1.6),0,-20*(float)Math.Sin(activePie.fireAngle - 1.6)));

                    if (collidsion.Contains("Door") || collidsion == "")
                    {
                        activePie.notMoving = true;
                        stuckPies.Add(activePie);
                        activePie = null;
                    }

                }

                string region = TestRegion(newLocation);

                if (!region.Contains("Door") && region.Contains("1"))
                {
                    isBeingSlimed = false;
                }
                if (region != "" && !region.Contains("Door"))
                {
                    UpdateDoor(-1, gameTime);
                    if (region[region.Length-1].ToString()!=section.ToString())
                    {
                        previousSection = section;
                        if (!Int32.TryParse(region[region.Length - 1].ToString(), out section))
                            throw new Exception();
                    }
                    location = newLocation;
                }
                else if (region.Contains("Door"))
                {
                    switch (region[region.Length - 1])
                    {
                        case '1':
                            UpdateDoor(0, gameTime);
                            if (game.phibesModel[0].doorState[0].currentstate == DoorClass.DoorState.open)
                                location = newLocation;
                            break;
                        case '2':
                            UpdateDoor(1, gameTime);
                            if (game.phibesModel[1].doorState[0].currentstate == DoorClass.DoorState.open)
                                location = newLocation;
                            break;
                        case '3':
                            UpdateDoor(2, gameTime);
                            if (game.phibesModel[2].doorState[1].currentstate == DoorClass.DoorState.open)
                                location = newLocation;
                            break;
                        case '4':
                            UpdateDoor(3, gameTime);
                            if (game.phibesModel[4].doorState[0].currentstate == DoorClass.DoorState.open)
                                location = newLocation;
                            break;
                        case '5':
                            UpdateDoor(4, gameTime);
                            if (game.phibesModel[5].doorState[0].currentstate == DoorClass.DoorState.open)
                                location = newLocation;
                            break;
                    }

                }
                #endregion

                SetPlayerTransform();
                deltaTotal -= delta;

            } while (deltaTotal > 0);
            #endregion

            //
            // Make the camera follow the player
            //

            Vector3 cameraBehind = new Vector3((float)Math.Sin(orientation+spineOrientation), 0,(float) Math.Cos(orientation+spineOrientation));
            game.Camera.Eye = location + new Vector3(0, 180, 0) /*- 100 * cameraBehind*/;
            Matrix stuff = Matrix.CreateRotationY(orientation + spineOrientation);
            game.Camera.Center = game.Camera.Eye + stuff.Backward +new Vector3(0, -0.1f, 0);
        }
Пример #3
0
        public void AlienStateMachine(ref double delta)
        {
            switch (alienState)
            {
                case States.Start:
                    alienPosition.Y = 10;
                    alienState = States.WalkLoopStart;
                    delta = 0;
                    break;
                case States.StanceStart:
                    alienPosition.Y = 10;
                    alienState = States.Stance;
                    Alien.PlayClip("stance");
                    delta = 0;
                    break;
                case States.Stance:
                    break;
                case States.WalkStart:
                    if (delta > Alien.AnimPlayer.Clip.Duration - Alien.AnimPlayer.Time)
                    {
                        delta = Alien.AnimPlayer.Clip.Duration - Alien.AnimPlayer.Time;
                        alienPosition.Y = 10;
                        // The clip is done after this update
                        alienState = States.WalkLoopStart;
                    }
                    else
                        Alien.AnimPlayer.Speed = 1;
                    break;
                case States.WalkLoopStart:
                   Alien.PlayClip("walkloop");
                    alienState = States.WalkStart;
                    break;
                case States.pieCatchstart:
                    Alien.PlayClip("eat");
                    Alien.AnimPlayer.Speed = 1;
                    alienState = States.pieCatch;
                    break;
                case States.pieCatch:
                    if (Alien.AnimPlayer.Time > 1)
                    {
                        Alien.AnimPlayer.Speed = 0;
                    }
                    break;
                case States.pieEat:
                    Alien.AnimPlayer.Speed = 1;
                    if (delta > Alien.AnimPlayer.Clip.Duration - Alien.AnimPlayer.Time)
                    {
                        delta = Alien.AnimPlayer.Clip.Duration - Alien.AnimPlayer.Time;
                        alienPosition.Y = 10;
                        activePie = null;
                        pieHits++;
                        if (aboutFace)
                            alienOrientation = (float)Math.PI;
                        else
                            alienOrientation = 0;
                        alienState = States.WalkLoopStart;
                    }
                    break;
                case States.spitting:
                    if (spitTime > 5||!drawSpit)
                    {
                        alienState = States.WalkLoopStart;
                        if (aboutFace)
                            alienOrientation = (float)Math.PI;
                        else
                            alienOrientation = 0;
                        alienPosition.Y = 10;

                    }
                    break;

            }
        }