Exemplo n.º 1
0
        protected void UpdateMovingState()
        {
            float dir = (moveAngleIndex / (float)numMoveAngles) * GMath.FullAngle;

            Physics.Velocity = Vector2F.CreatePolar(speed, dir) * new Vector2F(1.0f, -1.0f);

            // Stop moving after a duration.
            if (moveTimer <= 0)
            {
                StopMoving();
                return;
            }

            // Change direction on collisions.
            if (changeDirectionsOnCollide && physics.IsColliding)
            {
                ChangeDirection();
            }

            // Shoot.
            if (shootType == ShootType.WhileMoving && projectileType != null && GRandom.NextInt(projectileShootOdds) == 0)
            {
                isMoving = false;
                StartShooting();
                //Shoot();
            }

            moveTimer--;
        }
Exemplo n.º 2
0
        protected void UpdateChargingState()
        {
            speed = Math.Min(chargeSpeed, speed + chargeAcceleration);

            float dir = (moveAngleIndex / (float)numMoveAngles) * GMath.FullAngle;

            Physics.Velocity = Vector2F.CreatePolar(speed, dir) * new Vector2F(1.0f, -1.0f);

            if (chargeType == ChargeType.ChargeForDuration)
            {
                if (moveTimer <= 0)
                {
                    isCharging = false;
                    return;
                }
            }
            else
            {
                if (Physics.IsColliding)
                {
                    isCharging = false;
                    return;
                }
            }

            moveTimer--;
        }
Exemplo n.º 3
0
        public override void Update()
        {
            // Adjust Z-position and velocity to hover at a certain height.
            if (Math.Abs(zPosition - GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT) > 2.0f)
            {
                if (zPosition < GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT)
                {
                    Physics.ZVelocity = Math.Min(0.5f, Physics.ZVelocity + 0.05f);
                }
                if (zPosition > GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT)
                {
                    Physics.ZVelocity = Math.Max(-0.5f, Physics.ZVelocity - GameSettings.DEFAULT_GRAVITY);
                }
            }
            else
            {
                Physics.ZVelocity = 0.0f;
                zPosition         = GameSettings.COLLECTIBLE_FAIRY_HOVER_HEIGHT;
            }

            // Adjust move direction.
            moveSpeed = physics.Velocity.Length;
            if (moveSpeed == 0.0f)
            {
                direction = GRandom.NextFloat(GMath.FullAngle);
            }
            else
            {
                direction = Physics.Velocity.Direction;
            }

            // Adjust velocity.
            if (Math.Abs(moveSpeed - maxMoveSpeed) > 0.01f)
            {
                moveSpeed += 0.04f * Math.Sign(maxMoveSpeed - moveSpeed);
            }
            else
            {
                moveSpeed = maxMoveSpeed;
            }

            // Update random motion.
            directionSpeed  += 0.05f * GRandom.NextFloat(-30.0f, 30.0f);
            directionSpeed   = GMath.Clamp(directionSpeed, -6.0f, 6.0f);
            direction       += directionSpeed;
            physics.Velocity = Vector2F.CreatePolar(moveSpeed, direction);

            // Syncronize facing direction with velocity.
            if (Physics.Velocity.X > 0.0f)
            {
                Graphics.SubStripIndex = 0;
            }
            else if (Physics.Velocity.X < 0.0f)
            {
                Graphics.SubStripIndex = 1;
            }

            base.Update();
        }
Exemplo n.º 4
0
        protected void StartMoving()
        {
            isMoving  = true;
            speed     = moveSpeed;
            moveTimer = GRandom.NextInt(moveTime.Min, moveTime.Max);
            Graphics.PlayAnimation(animationMove);

            float dir = (moveAngleIndex / (float)numMoveAngles) * GMath.FullAngle;

            Physics.Velocity = Vector2F.CreatePolar(moveSpeed, dir) * new Vector2F(1.0f, -1.0f);
        }
        public override void Update()
        {
            base.Update();

            // Check if we should stop controlling the boomerang.
            if (!weapon.IsEquipped || !weapon.IsButtonDown() || boomerang.IsDestroyed || boomerang.IsReturning)
            {
                Player.BeginBusyState(10);
            }
            else
            {
                // TODO: update move controls.

                // Poll movement keys.
                bool isArrowDown = false;
                for (int dir = 0; dir < 4 && !isArrowDown; dir++)
                {
                    if (Controls.Arrows[dir].IsDown())
                    {
                        isArrowDown = true;
                    }
                }

                if (isArrowDown)
                {
                    int   useAngle     = player.UseAngle;
                    float currentAngle = boomerangMotionDirection;
                    float goalAngle    = player.UseAngle * GMath.QuarterAngle * 0.5f;
                    float distCW       = GMath.GetAngleDistance(currentAngle, goalAngle, WindingOrder.Clockwise);
                    float distCCW      = GMath.GetAngleDistance(currentAngle, goalAngle, WindingOrder.CounterClockwise);

                    if (distCW != 0.0f || distCCW != 0.0f)
                    {
                        int sign = (distCW <= distCCW ? -1 : 1);
                        boomerangMotionDirection += sign * 7f;
                        boomerangMotionDirection  = GMath.Plusdir(boomerangMotionDirection);
                    }

                    Vector2F velocity = Vector2F.CreatePolar(boomerang.Speed, boomerangMotionDirection);
                    velocity.Y = -velocity.Y;
                    boomerang.Physics.Velocity = velocity;
                }

                // Determine direction

                // Apply motion.
                //Vector2F keyMotion = ((Vector2F) keyMove).Normalized;

                //boomerang.Physics.Velocity += keyMotion;
                //int length = boomerang.Physics.Velocity.Length;
            }
        }
Exemplo n.º 6
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        // Called when the items button is pressed (A or B).
        public override void OnButtonPress()
        {
            if (!seedTracker.IsEmpty || !HasAmmo())
            {
                return;
            }

            UseAmmo();

            SeedType seedType = CurrentSeedType;

            int direction = Player.UseDirection;

            Player.Direction = direction;

            // Determine the seed spawn position based on player facing direction.
            Vector2F seedPos;

            if (direction == Directions.Up)
            {
                seedPos = Directions.ToVector(direction) * 1;
            }
            else if (direction == Directions.Down)
            {
                seedPos = Directions.ToVector(direction) * 8;
            }
            else
            {
                seedPos = new Vector2F(0, 6) + (Directions.ToVector(direction) * 4);
            }

            // Spawn the main seed projectile.
            SeedProjectile seed = new SeedProjectile(seedType, false);

            Player.ShootProjectile(seed,
                                   Directions.ToVector(direction) * GameSettings.SLINGSHOT_SEED_SPEED,
                                   seedPos, 5);
            seedTracker.TrackEntity(seed);

            // Spawn the extra 2 seeds for the Hyper Slingshot.
            if (level == Item.Level2)
            {
                for (int i = 0; i < 2; i++)
                {
                    int sideDirection = direction + (i == 0 ? 1 : 3);

                    // Calculate the velocity based on a degree offset.
                    float degrees = direction * GMath.QuarterAngle;
                    if (i == 0)
                    {
                        degrees += GameSettings.SLINGSHOT_SEED_DEGREE_OFFSET;
                    }
                    else
                    {
                        degrees -= GameSettings.SLINGSHOT_SEED_DEGREE_OFFSET;
                    }
                    Vector2F velocity = Vector2F.CreatePolar(GameSettings.SLINGSHOT_SEED_SPEED, degrees);
                    velocity.Y = -velocity.Y;

                    // Spawn the seed.
                    seed = new SeedProjectile(seedType, false);
                    Player.ShootProjectile(seed, velocity, seedPos, 5);
                    seedTracker.TrackEntity(seed);
                }
            }

            // Set the tool animation.
            Player.EquipTool(Player.ToolVisual);
            if (level == Item.Level1)
            {
                Player.ToolVisual.PlayAnimation(GameData.ANIM_SLINGSHOT_1);
            }
            else
            {
                Player.ToolVisual.PlayAnimation(GameData.ANIM_SLINGSHOT_2);
            }
            Player.ToolVisual.AnimationPlayer.SubStripIndex = direction;

            // Begin the player busy state.
            Player.BusyState.SetEndAction(delegate(PlayerState playerState) {
                playerState.Player.UnequipTool(playerState.Player.ToolVisual);
            });
            Player.BeginBusyState(10, GameData.ANIM_PLAYER_THROW, GameData.ANIM_PLAYER_MINECART_THROW);
        }