示例#1
0
        // --------------------------

        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Character Actions
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Varying Methods allow characters to change states
        // ----------------------------------
        #region Action Controllers

        // ----------------------------------
        /// <summary>
        /// Sets the entity state
        /// </summary>
        /// <param name="new_state">State to set</param>
        public void Set_State(Shared.EntityState new_state)
        {
            // Include all contingencies
            if (Active_Attack == "none")
            {
                State = new_state;
            }
        }
示例#2
0
        // ----------------------------------

        #endregion
        // ----------------------------------

        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Draw & Update & Bounds
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        // ----------------------------------
        #region Draw & Update & Bounds
        /// <summary>
        /// Updates animation, position, logic, etc.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // --------------------------
            // Disable entities that are not within the screen
            // Hooray for optimization.
            // --------------------------

            // Leniance radius lets specific groupds of entities load from a
            // determined bounds outside the screen
            // --------------------------

            Shared.Scene = Shared.Screen.Get_WorldSpace();

            float leniance_range = 15 * Shared.Block_Dimension;

            if (Get_Bounds().Top > Shared.Scene.Bottom + leniance_range)
            {
                Enabled = false;
            }
            else if (Get_Bounds().Bottom < Shared.Scene.Top - leniance_range)
            {
                Enabled = false;
            }
            else if (Get_Bounds().Left > Shared.Scene.Right + leniance_range)
            {
                Enabled = false;
            }
            else if (Get_Bounds().Right < Shared.Scene.Left - leniance_range)
            {
                Enabled = false;
            }
            else
            {
                Enabled = true;
            }

            if (Get_Bounds().Top >= Shared.Active_World.Size.Y)
            {
                if (!dead)
                {
                    Health_Points = 0;
                    Particles.Do_Bloodspurt(this, 50, 4, true);
                }
            }


            if (Enabled && !dead)
            {
                // -------------------------------
                // Cooldown Control
                // -------------------------------
                if (Attack_Roster.Count() != 0)
                {
                    foreach (KeyValuePair <string, Attack> attack in Attack_Roster)
                    {
                        if (attack.Value.Cooldown_timer > 0f)
                        {
                            float elapsed_time = (float)gameTime.ElapsedGameTime.TotalSeconds;
                            attack.Value.Cooldown_timer -= elapsed_time;
                        }
                        else
                        {
                            attack.Value.Cooldown_timer = 0f;
                        }
                    }
                }
                // -------------------------------


                // -------------------------------
                // 0 Health = Dead Character. Derp
                if (Health_Points <= 0)
                {
                    Try_Dead();
                }
                // -------------------------------

                Physics(gameTime);        // Runs physics checks
                Invulnerablity(gameTime); // Runs invulnerability timer

                // Jitter Fix
                // ------------------------
                Position.X = (float)Math.Round(Position.X);
                Position.Y = (float)Math.Round(Position.Y);
                // ------------------------

                Grid_Position.X = (int)Math.Round((Position.X / Shared.Pixel_Scale) / Shared.Block_Dimension);
                Grid_Position.Y = (int)Math.Ceiling((Position.Y / Shared.Pixel_Scale) / Shared.Block_Dimension);

                // Ensures we will not run out of range of our animation list
                if (Animated)
                {
                    Shared.EntityState temp_state = State;
                    // --------------------------
                    // Make sure animation set exists
                    if (!Animation_state.ContainsKey(State))
                    {
                        // The animation does not exist. Default animation to idle
                        // --------------------------

                        temp_state = Shared.EntityState.IDLE;
                        if (!Animation_state.ContainsKey(temp_state))
                        {
                            // Idle isn't set? This entity is bugged. Avoid it.
                            // --------------------------
                            return;
                        }
                    }
                    int max_index;
                    // --------------------------
                    // Animation Frame Calculation
                    max_index = Animation_state[temp_state].Frames.Count();
                    anim_delay++;
                    if (anim_delay > Shared.FPS)
                    {
                        anim_delay = 0;
                        anim_index++;
                        if (anim_index >= max_index)
                        {
                            final_frame = true;
                            if (Animation_state[temp_state].Loop)
                            {
                                anim_index = 0;
                            }
                            else
                            {
                                anim_index = Animation_state[temp_state].Frames.Count() - 1;
                            }
                        }
                        else
                        {
                            final_frame = false;
                        }
                    }

                    // --------------------------
                    // Complete Attacks
                    if (Active_Attack != "none" && final_frame)
                    {
                        Try_Attack_Clear();
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Base entity draw method
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Draw(GameTime gameTime)
        {
            if (Enabled)
            {
                List <Rectangle> animation;
                Rectangle        source;
                Vector2          origin;
                Texture2D        image;
                Vector2          draw_position = Position;
                SpriteEffects    flipDirection;

                if (animated)
                {
                    Shared.EntityState temp_state = State;

                    // Animation doesn't exist checks
                    // --------------------
                    if (!Animation_state.ContainsKey(State))
                    {
                        // Set to IDLE by default
                        // --------------------
                        temp_state = Shared.EntityState.IDLE;

                        if (State == Shared.EntityState.FALLING)
                        {
                            if (Animation_state.ContainsKey(Shared.EntityState.JUMPING))
                            {
                                // If this entity doesn't have a falling animation, resort to Jumping
                                // --------------------
                                temp_state = Shared.EntityState.JUMPING;;
                            }
                        }
                        else if (State == Shared.EntityState.RUNNING)
                        {
                            if (Animation_state.ContainsKey(Shared.EntityState.WALKING))
                            {
                                // If this entity doesn't have a falling animation, resort to Jumping
                                // --------------------
                                temp_state = Shared.EntityState.WALKING;;
                            }
                        }
                        else if (!Animation_state.ContainsKey(Shared.EntityState.IDLE))
                        {
                            // Idle isn't set? This entity is bugged. Avoid it.
                            // --------------------------

                            return;
                        }
                    }
                    // --------------------
                    animation = Animation_state[temp_state].Frames;
                    // --------------------

                    // --------------------
                    // Safety Dance
                    if (anim_index >= animation.Count())
                    {
                        anim_index = 0;
                    }
                    // --------------------
                    // Full Play
                    if (State_Cache != State)
                    {
                        anim_index = 0;
                    }
                    // --------------------
                    source = animation[anim_index];
                    image  = SpriteSheet;
                    origin = new Vector2(FrameSize.X / 2, FrameSize.Y / 2);
                }
                else
                {
                    source = new Rectangle(0, 0, Still_image.Width, Still_image.Height);
                    image  = Still_image;
                    origin = new Vector2(Still_image.Width / 2, Still_image.Height / 2);
                }
                // --------------------
                // Direction
                // --------------------
                if (Active_Attack == "none")
                {
                    if (direction == Shared.Direction.LEFT)
                    {
                        flipDirection = SpriteEffects.FlipHorizontally;
                    }
                    else
                    {
                        flipDirection = SpriteEffects.None;
                    }
                }
                else
                {
                    if (ATK_Direction == Shared.Direction.LEFT)
                    {
                        flipDirection = SpriteEffects.FlipHorizontally;
                    }
                    else if (ATK_Direction == Shared.Direction.RIGHT)
                    {
                        flipDirection = SpriteEffects.None;
                    }
                    else
                    {
                        if (direction == Shared.Direction.LEFT)
                        {
                            flipDirection = SpriteEffects.FlipHorizontally;
                        }
                        else
                        {
                            flipDirection = SpriteEffects.None;
                        }
                    }
                }

                if (Invulnerable)
                {
                    Overlay_Color = new Color(255, 150, 150);
                }

                // --------------------
                // Draw
                // --------------------
                spriteBatch.Begin
                (
                    SpriteSortMode.FrontToBack,
                    BlendState.AlphaBlend,
                    SamplerState.PointClamp,
                    DepthStencilState.Default,
                    RasterizerState.CullNone,
                    null,
                    Shared.Screen.Get_Camera()
                );
                spriteBatch.Draw
                (
                    image,
                    Position,
                    source,
                    Overlay_Color,
                    rotation,
                    origin,
                    Shared.Pixel_Scale,
                    flipDirection,
                    0
                );
                spriteBatch.End();
                // ----------------------------------
                // Refresh Basics
                State_Cache   = State;
                Overlay_Color = Color.White;
                // ----------------------------------
                // Debug Bound Box Borders
                if (this is Character && Shared.Debug)
                {
                    Draw_Box(Get_Bounds(), 1, Color.Red);
                }
                // ----------------------------------
            }
        }