public override void OnEnd(PlayerState newState)
 {
     isSubmerged = false;
     player.Movement.CanJump = true;
     player.Movement.MoveSpeedScale = 1.0f;
     player.Movement.AutoAccelerate = false;
 }
        public override void OnBegin(PlayerState previousState)
        {
            player.Movement.CanJump = false;
            player.Movement.MoveSpeedScale = 1.0f;
            player.Movement.AutoAccelerate = false;

            isSubmerged = false;
            player.Graphics.PlayAnimation(GameData.ANIM_PLAYER_SWIM);

            // Create a splash effect.
            Effect splash = new Effect(GameData.ANIM_EFFECT_WATER_SPLASH);
            splash.Position = player.Position - new Vector2F(0, 4);
            player.RoomControl.SpawnEntity(splash);
        }
        //-----------------------------------------------------------------------------
        // Internal methods
        //-----------------------------------------------------------------------------
        private void PerformDig(PlayerState state)
        {
            // Look for tiles to dig up.
            float distance = 6.5f;
            Vector2F center = Player.Center;
            if (Directions.IsVertical(Player.Direction))
                distance = 7.5f;
            else
                center.Y += 4.0f;
            Vector2F hotspot = GMath.Round(center) + (Directions.ToVector(Player.Direction) * distance);
            Point2I tileLoc = RoomControl.GetTileLocation(hotspot);
            if (!RoomControl.IsTileInBounds(tileLoc))
                return;

            Tile tile = RoomControl.GetTopTile(tileLoc);

            if (tile != null && tile.OnDig(Player.Direction)) {
                // Spawn dirt effect.
                Effect effect = new Effect();
                effect.Graphics.DepthLayer = DepthLayer.EffectDirt;
                effect.CreateDestroyTimer(15);
                effect.EnablePhysics(PhysicsFlags.HasGravity);
                effect.Physics.Velocity = Directions.ToVector(Player.Direction) * 0.5f;
                effect.Graphics.IsShadowVisible = false;
                effect.Graphics.PlayAnimation(GameData.ANIM_EFFECT_DIRT);
                effect.Graphics.SubStripIndex = Player.Direction;
                if (Directions.IsHorizontal(Player.Direction)) {
                    effect.Physics.ZVelocity	= 3.0f;
                    effect.Physics.Gravity		= 0.5f;
                }
                else {
                    effect.Physics.ZVelocity	= 2.5f;
                    effect.Physics.Gravity		= 0.4f;
                }
                RoomControl.SpawnEntity(effect, tile.Center);

                AudioSystem.PlaySound(GameData.SOUND_SHOVEL);
            }
            else {
                AudioSystem.PlaySound(GameData.SOUND_EFFECT_CLING);
            }

            // Check for monster interactions.
            Rectangle2I shovelHitBox = new Rectangle2I(-4, -4, 8, 8);
            shovelHitBox.Point += (Point2I) Player.CenterOffset;
            shovelHitBox.ExtendEdge(Player.Direction, 7);
            foreach (Monster monster in Player.Physics.GetEntitiesMeeting<Monster>(shovelHitBox, CollisionBoxType.Soft)) {
                monster.TriggerInteraction(InteractionType.Shovel, Player);
            }
        }
 //-----------------------------------------------------------------------------
 // Overridden Methods
 //-----------------------------------------------------------------------------
 public override void OnBegin(PlayerState previousState)
 {
     if (player.IsInMinecart) {
         weaponSwingAnimation			= GameData.ANIM_MAGIC_ROD_MINECART_SWING;
         playerSwingAnimation			= GameData.ANIM_PLAYER_SWING_NOLUNGE;
         playerSwingAnimationInMinecart	= GameData.ANIM_PLAYER_MINECART_SWING_NOLUNGE;
     }
     else {
         weaponSwingAnimation			= GameData.ANIM_MAGIC_ROD_SWING;
         playerSwingAnimation			= GameData.ANIM_PLAYER_SWING;
         playerSwingAnimationInMinecart	= GameData.ANIM_PLAYER_MINECART_SWING;
     }
     base.OnBegin(previousState);
 }
        public override void OnBegin(PlayerState previousState)
        {
            player.Movement.CanJump = false;
            player.Movement.MoveSpeedScale = 1.0f;
            player.Movement.AutoAccelerate = false;

            isSubmerged = false;
            player.Graphics.PlayAnimation(GameData.ANIM_PLAYER_SWIM);

            // Create a splash effect.
            if (player.Physics.IsInLava) {
                Effect splash = new Effect(GameData.ANIM_EFFECT_LAVA_SPLASH, DepthLayer.EffectSplash, true);
                splash.Position = player.Center + new Vector2F(0, 4);
                player.RoomControl.SpawnEntity(splash);
            }
            else {
                Effect splash = new Effect(GameData.ANIM_EFFECT_WATER_SPLASH, DepthLayer.EffectSplash, true);
                splash.Position = player.Center + new Vector2F(0, 4);
                player.RoomControl.SpawnEntity(splash);
            }

            // Check if the player should drown.
            if ((player.Physics.IsInWater && !player.SwimmingSkills.HasFlag(PlayerSwimmingSkills.CanSwimInWater)) ||
                player.Physics.IsInOcean && !player.SwimmingSkills.HasFlag(PlayerSwimmingSkills.CanSwimInOcean))
            {
                player.Graphics.PlayAnimation(GameData.ANIM_PLAYER_DROWN);
                player.RespawnDeath();
                // TODO: Cancel the hurt animation if the player was knocked in.
                //player.InvincibleTimer = 0;
                //player.Graphics.IsHurting = false;
            }
            else if (player.Physics.IsInLava && !player.SwimmingSkills.HasFlag(PlayerSwimmingSkills.CanSwimInLava)) {
                player.Graphics.IsHurting = true;
                player.Graphics.PlayAnimation(GameData.ANIM_PLAYER_DROWN);
                player.RespawnDeath();
            }

            AudioSystem.PlaySound(GameData.SOUND_PLAYER_WADE);
        }
Exemple #6
0
 public virtual void OnBegin(PlayerState previousState)
 {
 }
Exemple #7
0
 public void End(PlayerState newState)
 {
     this.isActive = false;
     OnEnd(newState);
 }
Exemple #8
0
 //-----------------------------------------------------------------------------
 // Begin/end
 //-----------------------------------------------------------------------------
 public void Begin(Player player, PlayerState previousState)
 {
     this.player = player;
     this.isActive = true;
     OnBegin(previousState);
 }
Exemple #9
0
 //-----------------------------------------------------------------------------
 // Virtual methods
 //-----------------------------------------------------------------------------
 public virtual bool RequestStateChange(PlayerState newState)
 {
     if (!isNaturalState && newState is PlayerNormalState)
         return false;
     return true;
 }
 public override void OnEnd(PlayerState newState)
 {
     player.Movement.MoveCondition = PlayerMoveCondition.FreeMovement;
     player.UnequipTool(playerTool);
 }
 //-----------------------------------------------------------------------------
 // Overridden methods
 //-----------------------------------------------------------------------------
 public override bool RequestStateChange(PlayerState newState)
 {
     return true;
 }
Exemple #12
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public Player()
        {
            direction			= Directions.Down;
            useDirection		= 0;
            useAngle			= 0;
            autoRoomTransition	= false;
            syncAnimationWithDirection = true;
            movement = new PlayerMoveComponent(this);

            // Unit properties.
            originOffset	= new Point2I(0, -2);
            centerOffset	= new Point2I(0, -8);
            Health			= 4 * 3;
            MaxHealth		= 4 * 3;
            swimmingSkills	= PlayerSwimmingSkills.CantSwim;
            invincibleTimer	= 0;
            tunic			= PlayerTunics.GreenTunic;

            // Physics.
            Physics.CollisionBox		= new Rectangle2F(-4, -10, 8, 9);
            Physics.SoftCollisionBox	= new Rectangle2F(-6, -14, 12, 13);
            Physics.CollideWithWorld	= true;
            Physics.CollideWithEntities	= true;
            Physics.CollideWithRoomEdge	= true;
            Physics.HasGravity			= true;

            // Graphics.
            Graphics.ShadowDrawOffset = originOffset;
            Graphics.DrawOffset = new Point2I(-8, -16);

            // Create the basic player states.
            state			= null;
            stateNormal		= new PlayerNormalState();
            stateBusy		= new PlayerBusyState();
            stateSwim		= new PlayerSwimState();
            stateLadder		= new PlayerLadderState();
            stateLedgeJump	= new PlayerLedgeJumpState();
            stateSwing		= new PlayerSwingState();
            stateHoldSword	= new PlayerHoldSwordState();
            stateSpinSword	= new PlayerSpinSwordState();

            toolAnimation	= new AnimationPlayer();
        }
Exemple #13
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------
        public override void Initialize()
        {
            base.Initialize();

            BeginState(stateNormal);
            previousState = stateNormal;
        }
Exemple #14
0
 //-----------------------------------------------------------------------------
 // Player states
 //-----------------------------------------------------------------------------
 // Begin the given player state.
 public void BeginState(PlayerState newState)
 {
     if (state != newState) {
         if (state != null) {
             state.End(newState);
         }
         previousState = state;
         state = newState;
         newState.Begin(this, previousState);
     }
 }
 //-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 public PlayerSwingState()
 {
     this.weaponAnimation	= null;
     this.nextState			= null;
     this.equipSlot			= 0;
     this.hasPeaked			= false;
 }
 public override void OnEnd(PlayerState newState)
 {
     player.Movement.MoveCondition = PlayerMoveCondition.FreeMovement;
     player.toolAnimation.Animation = null;
 }
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------
        public override void OnBegin(PlayerState previousState)
        {
            player.Direction = player.UseDirection;
            player.Graphics.PlayAnimation(GameData.ANIM_PLAYER_SWING);
            player.Movement.MoveCondition = PlayerMoveCondition.OnlyInAir;
            player.toolAnimation.Animation = weaponAnimation;
            player.toolAnimation.SubStripIndex = player.Direction;
            player.toolAnimation.Play();

            hasPeaked = false;

            AudioSystem.PlayRandomSound("Items/slash_1", "Items/slash_2", "Items/slash_3");
        }
Exemple #18
0
 public virtual void OnEnd(PlayerState newState)
 {
 }
 public override void OnEnd(PlayerState newState)
 {
     isSubmerged = false;
     player.Movement.CanJump = true;
     player.Movement.MoveSpeedScale = 1.0f;
     player.Movement.AutoAccelerate = false;
     player.Graphics.DepthLayer = DepthLayer.PlayerAndNPCs;
 }
Exemple #20
0
 // Begin the given player state as a special state.
 public void BeginSpecialState(PlayerState newState)
 {
     if (specialState != null && !specialState.IsActive)
         specialState = null;
     if (specialState != newState) {
         if (specialState != null)
             specialState.End(newState);
         previousSpecialState = specialState;
         specialState = newState;
         specialState.Begin(this, previousSpecialState);
     }
 }
Exemple #21
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------
        public override void Initialize()
        {
            base.Initialize();

            viewFocusOffset		= Vector2F.Zero;
            direction			= Directions.Down;
            useDirection		= 0;
            useAngle			= 0;
            autoRoomTransition	= false;
            isStateControlled	= false;
            syncAnimationWithDirection = true;

            // Initialize tools.
            toolShield.Initialize(this);
            toolSword.Initialize(this);
            toolVisual.Initialize(this);

            // Begin the default player state.
            BeginState(stateNormal);
            previousState	= stateNormal;
            specialState	= null;
            previousSpecialState = null;
        }
 //-----------------------------------------------------------------------------
 // Overridden methods
 //-----------------------------------------------------------------------------
 public override void OnBegin(PlayerState previousState)
 {
     player.Movement.MoveCondition = PlayerMoveCondition.OnlyInAir;
     playerTool = player.ToolVisual;
     Swing(player.UseDirection);
 }