private void Start()
    {
        // set position at x = ScreenWidth/4
        var x = -GameSettings.WorldWidth / 4f;
        var y = -GameSettings.ScreenLimits.y + (GameSettings.ScreenLimits.y / 4f);

        transform.position = new Vector2(x, y);

        // Init
        _currentGunPosition = GunPosition.Normal;
        _shootingAngle      = _shootingAngles[(int)GunPosition.Normal];
    }
예제 #2
0
 void Beat()
 {
     if (Random.Range(0, 2) == 0)
     {
         gunPosition = GunPosition.MIDDLE;
         GetComponent <SpriteRenderer>().sprite = middle;
     }
     else
     {
         gunPosition = GunPosition.TOP;
         GetComponent <SpriteRenderer>().sprite = top;
     }
     GetComponent <Gun>().Shoot();
 }
예제 #3
0
        void ProcessShellLaunch(ref State state, Unit unit, List <GunPosition> gunPositions)
        {
            double shotStage;

            if (Utility.doubleEqual(unit.StageOfLastShot, -1))
            {
                shotStage = 0.0;
            }
            else
            {
                shotStage = unit.StageOfLastShot + 1.0 / unit.DamageRate;
                if (Utility.doubleGreaterOrEqual(shotStage, 1.0))
                {
                    shotStage -= 1.0;
                }
            }
            double currStage = 0.0;
            double lastStage = currStage;
            double step      = 1.0 / unit.DamageRate;
            int    stepCount = gunPositions.Count;

            while (Utility.doubleLess(currStage, 1))
            {
                double      x           = unit.GetCoordinate(currStage).x;
                double      y           = unit.GetCoordinate(currStage).y;
                int         index       = (int)Math.Truncate(currStage * stepCount);
                double      stageShift  = (currStage - index * 1.0 / stepCount) * stepCount;
                GunPosition gunPosition = gunPositions[index];
                double      angle       = gunPosition.Angle;
                double      currAngle;
                if (index + 1 < stepCount)
                {
                    double nextAngle = gunPositions[index + 1].Angle;
                    if (gunPosition.Direction != GunPosition.DirectionType.None)
                    {
                        currAngle = angle + (nextAngle - angle) * stageShift;
                    }
                    else
                    {
                        currAngle = angle;
                    }
                }
                else
                {
                    currAngle = angle;
                }
                if (unit.Owner == OwnerType.Player2)
                {
                    currAngle -= 180;
                    currAngle  = Utility.LimitAngle(currAngle);
                }
                state.shells.Add(new Shell(new Point2(x, y), currAngle, unit.Owner, unit, currStage));
                unit.StageOfLastShot = currStage;
                shotStage           += 1.0 / unit.DamageRate;
                currStage           += step;
            }
            if (Utility.doubleGreaterOrEqual(shotStage, 1.0 + 1.0 / unit.DamageRate))
            {
                unit.StageOfLastShot -= 1.0;
            }
        }
 private void GunDefaultPosition()
 {
     _image.sprite       = _defaultSprite;
     _shootingAngle      = _shootingAngles[(int)GunPosition.Normal];
     _currentGunPosition = GunPosition.Normal;
 }
 private void Gun90Degrees()
 {
     _image.sprite       = _ninetyDegreesSprite;
     _shootingAngle      = _shootingAngles[(int)GunPosition.Up];
     _currentGunPosition = GunPosition.Up;
 }
 private void Gun30Degrees()
 {
     _image.sprite       = _thrityDegreesSprite;
     _shootingAngle      = _shootingAngles[(int)GunPosition.Down];
     _currentGunPosition = GunPosition.Down;
 }