コード例 #1
0
ファイル: worldobject.cs プロジェクト: imiyu/DiscUsage
        /// <summary>
        /// Fire a shot from the object's current location.
        /// </summary>
        /// <param name="lev">Current level</param>
        /// <param name="shot">Information regarding shot to be fired</param>
        /// <param name="dir">Direction to fire shot</param>
        /// <param name="xMultiplier">Velocity x multiplier</param>
        /// <param name="yMultiplier">Velocity y multiplier</param>
        protected void FireShot(Level lev, ShotInfo shot, WorldDir dir,
                                float xMultiplier, float yMultiplier)
        {
            shot.Fired = true;

            WorldObject wo = new WorldObject(
                (Animation)lev.AnimationList[shot.AnimationId], shot.AnimationRate);

            Debug.Assert(wo != null,
                         "Player.Update: Failed to create player bullet");

            float velX    = shot.VelocityX * xMultiplier;
            float offsetX = shot.XOffset;

            if (dir == WorldDir.Left)
            {
                velX    = -velX;
                offsetX = -offsetX;
            }

            wo.VelocityX = velX;
            wo.VelocityY = shot.VelocityY * yMultiplier;
            wo.WorldX    = worldXValue + offsetX;
            wo.WorldY    = worldYValue + shot.YOffset;
            wo.SetTransparency(shot.UseTransparency);
            wo.staticBounds = new Bounds(0.0F, 0.0F, shot.Radius);
            wo.parentValue  = this;

            if (shot.UseGravity)
            {
                wo.AILogic = AIHandler.Create(AI.AIType.ShotArc);
            }

            lev.WorldObjects.Add(wo);
        }
コード例 #2
0
ファイル: PerspectiveMove.cs プロジェクト: AKJ1/UnityTools
        private static void MoveSelection(WorldDir dir)
        {
            Vector3 forwardDir = GetRelativeDireciton();

            for (int i = 0; i < Selection.gameObjects.Length; i++)
            {
                if (Selection.gameObjects[i].transform.parent == null)
                {
//                    Debug.Log((dirRotations[dir] * forwardDir).normalized);
//                    Debug.Log("BEFORE : " + Selection.gameObjects[i].transform.position + "\n AFTER : " +
//                              (Selection.gameObjects[i].transform.position + (dirRotations[dir]*forwardDir).normalized));
                    Selection.gameObjects[i].transform.position += (dirRotations[dir] * forwardDir).normalized;
                }
                else
                {
                    if (!Selection.gameObjects.Contains(Selection.gameObjects[i].transform.parent.gameObject))
                    {
//                        Debug.Log((dirRotations[dir] * forwardDir).normalized);
                        Selection.gameObjects[i].transform.position += (dirRotations[dir] * forwardDir).normalized;
                    }
                }
            }
            UpdateBlocks();
        }
コード例 #3
0
ファイル: player.cs プロジェクト: imiyu/DiscUsage
        /// <summary>
        /// Update the player.
        /// </summary>
        /// <param name="gi">Input instance</param>
        /// <param name="lev">Current level</param>
        /// <returns>Always false</returns>
        public override bool Update(Input gi, Level lev)
        {
            // Assume there is no misfire this frame
            misfireValue = false;

            // If a shot is charging then update the time
            if (shotStarted)
            {
                shotTime += GameMain.SecondsPerFrame;
            }

            // If the player is not dead then update it
            if ((State & AnimationState.Dead) == 0)
            {
                // clear out the current direction but leave the animation
                // state
                State = prevState & AnimationState.AnimationMask;

                // If attacking then update the shot state
                if ((State & AnimationState.Attack) != 0)
                {
                    // If the shot is not already fired and the current
                    // animation cell is the one where the player shoots
                    // then launch a shot
                    if (!GetShotInfo()[0].Fired &&
                        Animation.CurCell == GetShotInfo()[0].ShootCell)
                    {
                        // Determine the direction of the shot
                        WorldDir dir = WorldDir.Left;
                        if ((DrawOptions & DrawOptions.BlitMirrorLeftRight)
                            == 0)
                        {
                            dir = WorldDir.Right;
                        }

                        // Velocity multipliers
                        float shotVelXMultiplier;
                        float shotVelYMultiplier;

                        // Determine the chance of a misfire based on the shot
                        // bar charge (min to max)
                        float misfireChance =
                            shotMisfireMax - CurrentShotBarPercent *
                            (shotMisfireMax - shotMisfireMin);

                        if (GameMain.Random() < misfireChance)
                        {
                            // A misfire occurred so set the flag and
                            // update the velocity multipliers accordingly
                            misfireValue       = true;
                            shotVelXMultiplier = shotMisfireVelocityXMin +
                                                 GameMain.Random() *
                                                 (shotVelocityXMax - shotVelocityXMin);
                            shotVelYMultiplier = shotMisfireVelocityYMin +
                                                 GameMain.Random() *
                                                 (shotVelocityYMax - shotVelocityYMin);
                        }
                        else
                        {
                            // No misfire, so the velocities are set
                            // relative to the bar charge percentage
                            shotVelXMultiplier = shotVelocityXMin +
                                                 CurrentShotBarPercent *
                                                 (shotVelocityXMax - shotVelocityXMin);
                            shotVelYMultiplier = shotVelocityYMax -
                                                 CurrentShotBarPercent *
                                                 (shotVelocityYMax - shotVelocityYMin);
                        }

                        // Fire a shot and reset the charge time
                        shotTime = 0.0F;
                        FireShot(lev, GetShotInfo()[0], dir,
                                 shotVelXMultiplier, shotVelYMultiplier);
                    }
                    else if (Animation.Done)
                    {
                        // If the shot animation is done then reset shot info
                        GetShotInfo()[0].Fired = false;
                        State    = AnimationState.Walk;
                        curCycle = WalkCycle;
                    }
                }
                else if (gi.KeyPressed((int)Keys.Down))
                {
                    // If pressing down then attempt to crawl.
                    State    = AnimationState.Duck;
                    curCycle = DuckCycle;
                }
                else if (gi.KeyPressed((int)Keys.Up))
                {
                    // If pressing up then stand up
                    State    = AnimationState.Walk;
                    curCycle = WalkCycle;
                }
                else if (!shotStarted && gi.KeyDown(
                             (int)gi.HardwareKeys[buttonMapValue[
                                                      (int)Buttons.FireShot]]))
                {
                    // If the fire button is pressed then start charging
                    // the bar
                    shotStarted = true;
                    shotTime    = 0.0F;
                }
                else if (shotStarted && gi.KeyReleased(
                             (int)gi.HardwareKeys[buttonMapValue[
                                                      (int)Buttons.FireShot]]))
                {
                    // If the fire button is released then start the shot
                    // animation
                    curCycle = AttackCycle;
                    State   |= AnimationState.Attack;
                    Animation.SetCycle(WalkCycle.StartCell,
                                       WalkCycle.EndCell, WalkCycle.AnimationRate);
                    Animation.StartOneShot(AttackCycle.StartCell,
                                           AttackCycle.EndCell, AttackCycle.AnimationRate);
                    shotStarted = false;
                }

                Debug.Assert(curCycle != null,
                             "Player.Update: Invalid animation sequence");

                Debug.Assert((State & AnimationState.AnimationMask) != 0,
                             "Player.Update: Invalid animation state determined");

                // Attempt to walk in the direction the user is pressing
                if (gi.KeyDown((int)Keys.Left))
                {
                    WalkLeft(lev);
                }
                else if (gi.KeyDown((int)Keys.Right))
                {
                    WalkRight(lev);
                }
                else
                {
                    Stop(lev);
                }

                Debug.Assert((State & AnimationState.DirectionMask) != 0 &&
                             (State & AnimationState.AnimationMask) != 0,
                             "Player.Update: Invalid movement state determined");
            }

            // Update the animation
            Animation.Update(GameMain.SecondsPerFrame);

            // Set the previous state
            prevState = State;

            // The player always returns false
            return(false);
        }
コード例 #4
0
ファイル: worldobject.cs プロジェクト: imiyu/DiscUsage
        /// <summary>
        /// Update this world object.
        /// </summary>
        /// <param name="gi">Input instance</param>
        /// <param name="lev">Current level</param>
        /// <returns>true if the object should be removed, false otherwise
        /// </returns>
        virtual public bool Update(Input gi, Level lev)
        {
            // If the object is not active then check the activation distance
            if (!activeValue)
            {
                if (Math.Abs(lev.Player.WorldX - worldXValue) <=
                    activateDistance)
                {
                    activeValue = true;
                }
                else
                {
                    return(false);
                }
            }

            // If the object is in a death animation then check if it has
            // finished
            if ((curState & AnimationState.Dead) != 0)
            {
                if (animationValue.Done)
                {
                    activeValue = false;
                }

                animationValue.Update(GameMain.SecondsPerFrame);

                return(false);
            }

            // If the object is attacking then check the shot data
            if ((curState & AnimationState.Attack) != 0)
            {
                // If the object has a shot...
                if (GetShotInfo() != null)
                {
                    // Check all shots...
                    foreach (ShotInfo shot in GetShotInfo())
                    {
                        // If the shot is not already fired and the animation
                        // is in the proper shooting cell then fire it
                        if (!shot.Fired && animationValue.CurCell == shot.ShootCell)
                        {
                            WorldDir dir = WorldDir.Left;
                            if ((DrawOptions &
                                 DrawOptions.BlitMirrorLeftRight) != 0)
                            {
                                dir = WorldDir.Right;
                            }

                            FireShot(lev, shot, dir, 1.0F, 1.0F);
                        }

                        // If the animation is done the reset it
                        if (animationValue.Done)
                        {
                            shot.Fired = false;
                            Stand();
                        }
                    }
                }
            }

            // If the object has AI then update it
            if (AILogic != null)
            {
                AILogic.Update(this, lev);
            }

            // Update the object's world position
            worldXValue += GameMain.SecondsPerFrame * velocityXValue;
            worldYValue += GameMain.SecondsPerFrame * velocityYValue;

            // If the object is dynamic then check if it is off-screen
            if (dynamicValue)
            {
                if (worldXValue > lev.Player.WorldX + 1.5F * lev.ViewWidth ||
                    worldXValue < lev.WorldX - 1.5F * lev.ViewWidth)
                {
                    return(true);
                }
            }

            // Update the animation
            animationValue.Update(GameMain.SecondsPerFrame);

            // Do not remove this object
            return(false);
        }