Пример #1
0
        /// <summary>
        /// Shoot method with starting conditions to compensate for network delay
        /// </summary>
        /// <param name="target">Where is bulet traveling to</param>
        /// <param name="shootOrgin">Where shot was fired</param>
        /// <param name="shootRotation">How was weapon rotated during shoot</param>
        public void Shoot(Vector2f target, Vector2f shootOrgin, float shootRotation, Player player, bool sendToServer)
        {
            if (Ammo != 0 && Reloading != true && ShootTimer.ElapsedTime.AsMilliseconds() > AttackSpeed)
            {
                ShootTimer.Restart();

                // maybe figure out how to make this Vector2f -> Vector2 -> Vector2f mess cleaner later
                const float projectileSpeed  = 10f;
                Vector2     normalizedTarget = new Vector2(target.X, target.Y);
                normalizedTarget = Vector2.Normalize(normalizedTarget);
                Vector2f   myTarget = new Vector2f(normalizedTarget.X, normalizedTarget.Y);
                Projectile bullet   = new Projectile(myTarget * projectileSpeed, ProjectileSprite, shootOrgin, shootRotation);
                Projectiles.Add(bullet);
                ChangeAmmo(-1);


                Sound sound = ResourceHolderFacade.GetInstance().Sounds.Get(SoundIdentifier.GenericGun);
                sound.Volume = ResourceHolderFacade.GetInstance().CurrentVolume.GetVolume();
                sound.Play();

                if (sendToServer)
                {
                    var shootEventData = new ShootEventData(player.ToDTO(), target, this.Position, this.Rotation);
                    //GameState.GetInstance().ConnectionManager.Connection.SendAsync("ShootEventServer", shootEventData);
                    GameState.GetInstance().ConnectionManagerProxy.Connection.SendAsync("ShootEventServer", shootEventData);
                }
            }
        }
Пример #2
0
    private void OnPanUpdated(BlastyEventData ev)
    {
        var touchEventData = (TouchEventData)ev;

        if (touchEventData.PanType == TouchManager.PanType.World)
        {
            return;
        }

        switch (touchEventData.TouchState)
        {
        case TouchManager.TouchState.InitPan:
            _initialDragPosition = touchEventData.CurPosition;
            StartNewAiming();
            GetInitialDirectionOnScreenSpace();
            break;

        case TouchManager.TouchState.UpdatePan:
            MoveDirectionArrow(touchEventData);
            UpdateArrowSize(touchEventData.CurPosition);
            break;

        case TouchManager.TouchState.FinishPan:
            FinishAiming();
            if (_curPower < _minPowerToShoot)
            {
                return;
            }

            var shootEventData = new ShootEventData();
            shootEventData.ValidShot = true;
            shootEventData.Power     = 10f;

            EventManager.Instance.TriggerEvent(ShootEvent.EventName, shootEventData);

            OnPowerChanged(0f);
            break;
        }
    }
Пример #3
0
 public void ShootEventServer(ShootEventData shootData)
 {
     OurLogger.Log(shootData.ToString());
     Clients.AllExcept(Context.ConnectionId).SendAsync("ShootEventClient", shootData);
 }