Ejemplo n.º 1
0
 private void readGameObjectsFromPhoneState()
 {
     if (states.Count == 0 &&
         PhoneApplicationService.Current.State.Count > 0 &&
         PhoneApplicationService.Current.State.ContainsKey(stateKey))
     {
         SpartaState state = PhoneApplicationService.Current.State[stateKey] as SpartaState;
         if (state != null)
         {
             if (state.Mode == SpartaState.SpartaStateMode.Loading || state.Mode == SpartaState.SpartaStateMode.TransitionIn)
             {
                 state = Activator.CreateInstance(state.GetType()) as SpartaState;
             }
             state.Initialize();
             state.LoadContent();
             state.Mode = SpartaState.SpartaStateMode.Activated;
             states.Add(state);
         }
     }
 }
Ejemplo n.º 2
0
 private void writeGameObjectsToPhoneState()
 {
     PhoneApplicationService.Current.State.Clear();
     if (states.Count > 0)
     {
         SpartaState[] spartaStates = this.states.Array;
         int           count        = this.states.Count;
         for (int i = 0; i < count; i++)
         {
             SpartaState state = spartaStates[i];
             if (state.Mode == SpartaState.SpartaStateMode.Loading ||
                 state.Mode == SpartaState.SpartaStateMode.TransitionIn ||
                 state.Mode == SpartaState.SpartaStateMode.Activated)
             {
                 state.PrepareForTombstone();
                 PhoneApplicationService.Current.State.Add(stateKey, state);
                 return;
             }
         }
     }
 }
Ejemplo n.º 3
0
        protected void AddState(SpartaState state, SpartaState.SpartaStateMode mode, SpartaTransition transitionIn, SpartaTransition transitionOut)
        {
            if (state == null)
            {
                return;
            }

            if (states.Count > 0 && (mode == SpartaState.SpartaStateMode.Loading))
            {
                SpartaState[] spartaStates = this.states.Array;
                int           count        = this.states.Count;
                for (int i = 0; i < count; i++)
                {
                    if (spartaStates[i].Mode == SpartaState.SpartaStateMode.Loading)
                    {
                        spartaStates[i].Mode = SpartaState.SpartaStateMode.Deactivated;
                    }
                    else if (spartaStates[i].Mode == SpartaState.SpartaStateMode.Activated || spartaStates[i].Mode == SpartaState.SpartaStateMode.TransitionIn)
                    {
                        if (transitionOut.transitionType == SpartaTransitionType.None)
                        {
                            spartaStates[i].Mode = SpartaState.SpartaStateMode.Deactivated;
                        }
                        else
                        {
                            spartaStates[i].TransitionOut = transitionOut;
                            spartaStates[i].Mode          = SpartaState.SpartaStateMode.TransitionOff;
                        }
                    }
                }
            }

            state.TransitionIn = transitionIn;
            state.Mode         = mode;

            if (!states.Contains(state))
            {
                states.Add(state);
            }
        }
Ejemplo n.º 4
0
 protected void DrawState(GameTime gameTime, SpartaState state)
 {
     //state.OnBeforeDraw(gameTime, SpriteBatch);
     state.Draw(gameTime, SpriteBatch);
     state.OnPostDraw(gameTime, SpriteBatch);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            SpartaState[] spartaStates = states.Array;
            int           count        = states.Count;

            SpartaState activatedState     = null;
            SpartaState transitionInState  = null;
            SpartaState transitionOutState = null;

            for (int i = 0; i < count; i++)
            {
                if (spartaStates[i].Mode == SpartaState.SpartaStateMode.Activated)
                {
                    activatedState = spartaStates[i];
                    break;
                }
                else if (spartaStates[i].Mode == SpartaState.SpartaStateMode.TransitionIn)
                {
                    transitionInState = spartaStates[i];
                }
                else if (spartaStates[i].Mode == SpartaState.SpartaStateMode.TransitionOff)
                {
                    transitionOutState = spartaStates[i];
                }
            }

            if (activatedState != null)
            {
                activatedState.OnBeforeDraw(gameTime, SpriteBatch);
                GraphicsDevice.Clear(BackgroundColor);
                DrawBackgroundImage();
                activatedState.Draw(gameTime, SpriteBatch);
                activatedState.OnPostDraw(gameTime, SpriteBatch);
            }
            else
            {
                if (transitionOutState != null)
                {
                    transitionOutState.OnBeforeDraw(gameTime, SpriteBatch);
                }
                if (transitionInState != null)
                {
                    transitionInState.OnBeforeDraw(gameTime, SpriteBatch);
                }
                GraphicsDevice.Clear(BackgroundColor);
                DrawBackgroundImage();
                bool stopDrawing = false;
                if (transitionInState != null && transitionOutState != null)
                {
                    if (transitionInState.DrawPriority)
                    {
                        DrawState(gameTime, transitionOutState);
                        DrawState(gameTime, transitionInState);
                        stopDrawing = true;
                    }
                    else if (transitionOutState.DrawPriority)
                    {
                        DrawState(gameTime, transitionInState);
                        DrawState(gameTime, transitionOutState);
                        stopDrawing = true;
                    }
                }
                if (!stopDrawing)
                {
                    if (transitionOutState != null)
                    {
                        DrawState(gameTime, transitionOutState);
                    }
                    if (transitionInState != null)
                    {
                        DrawState(gameTime, transitionInState);
                    }
                }
            }
#if DEBUG
            SpartaDebug.Draw(SpriteBatch);
#endif
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
#if DEBUG
            SpartaDebug.Update(gameTime);
#endif
#if WINDOWS_PHONE
            SpartaTouch.Update();
#endif
#if WINDOWS
            SpartaMouse.Update();
            SpartaKeyboard.Update();
#endif
            bool backButtonPressed = GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed;
            DeltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (states.Count > 0)
            {
                SpartaState   toBeRemoved  = null;
                SpartaState[] spartaStates = states.Array;
                int           count        = states.Count;

                for (int i = 0; i < count; i++)
                {
                    switch (spartaStates[i].Mode)
                    {
                    case SpartaState.SpartaStateMode.Activated:
                        if (backButtonPressed)
                        {
                            spartaStates[i].OnBackButtonPressed();
                        }
                        spartaStates[i].Update(gameTime);
                        break;

                    case SpartaState.SpartaStateMode.Loading:
                        spartaStates[i].Initialize();
                        spartaStates[i].LoadContent();
                        if (spartaStates[i].TransitionIn.transitionType == SpartaTransitionType.None &&
                            spartaStates[i].TransitionOut.transitionType == SpartaTransitionType.None)
                        {
                            spartaStates[i].Mode = SpartaState.SpartaStateMode.Activated;
                        }
                        else if (spartaStates[i].TransitionIn.transitionType != SpartaTransitionType.None)
                        {
                            spartaStates[i].Mode = SpartaState.SpartaStateMode.TransitionIn;
                        }
                        else
                        {
                            spartaStates[i].Mode = SpartaState.SpartaStateMode.TransitionOff;
                        }
                        spartaStates[i].Update(gameTime);
                        break;

                    case SpartaState.SpartaStateMode.TransitionIn:
                        spartaStates[i].Update(gameTime);
                        break;

                    case SpartaState.SpartaStateMode.TransitionOff:
                        spartaStates[i].Update(gameTime);
                        break;

                    case SpartaState.SpartaStateMode.Deactivated:
                        spartaStates[i].UnloadContent();
                        toBeRemoved = spartaStates[i];
                        break;
                    }
                }

                if (toBeRemoved != null)
                {
                    states.Remove(toBeRemoved);
                    toBeRemoved.Dispose();
                    toBeRemoved = null;
                }
            }
        }
Ejemplo n.º 7
0
 public void SetState(SpartaState state, SpartaTransition transitionIn, SpartaTransition transitionOut)
 {
     AddState(state, SpartaState.SpartaStateMode.Loading, transitionIn, transitionOut);
 }
Ejemplo n.º 8
0
 public void SetState(SpartaState state)
 {
     AddState(state, SpartaState.SpartaStateMode.Loading, SpartaTransition.Default, SpartaTransition.Default);
 }