예제 #1
0
    public override void Shoot(bool firstDown)
    {
        if (!automatic && !firstDown)
        {
            return;
        }

        if (canShoot)
        {
            timeSinceLastShot = 0;
            canShoot          = false;
            canReload         = false;
            reloading         = false;

            if (bulletsInClip > 0)
            {
                ///
                /// Create the bullets
                ///
                player.AudioSource.PlayOneShot(shoot);
                bulletsInClip -= 1;

                for (int i = 0; i < pelletCount; i++)
                {
                    ShotgunPellet bullet = ((GameObject)Instantiate(shotgunPelletPrefab.gameObject)).GetComponent <ShotgunPellet>();
                    bullet.transform.position = bulletSpawnPoint.position;
                    bullet.transform.rotation = bulletSpawnPoint.rotation;
                    bullet.SetHitMarkerCallBack(hitMarkerCallback);
                    bullet.InitBulletTrail(bullet.transform.position);
                    bullet.SetupBulletVelocity(i == 0);

                    //Align(bullet.transform, bulletSpawnPoint.rotation.eulerAngles);
                }

                muzzleFlash.ShowFlash();

                ///
                /// Create the shell
                ///
                Shell_Base shell = (Shell_Base)Instantiate(shellPrefab, shellSpawnPoint.position, transform.rotation * shellSpawnPoint.localRotation);
                shell.AddVelocity(player.Rigidbody.velocity);
            }
            else
            {
                player.AudioSource.PlayOneShot(outOfAmmo);
            }
        }
    }
예제 #2
0
        public override void Update(float elapsed)
        {
            if (Game.currentState == State.StateType.ServerState)
            {
                Player player = (Player)(Game.states[Game.currentState]).netState.Entities[id];
                Random rand   = new Random();
                for (int i = 0; i < 10; i++)
                {
                    float angle = (float)Math.Atan2(player.direction.Y, player.direction.X);
                    angle += (float)rand.Next(-10, 10) * .1f * rand.Next(-1, 1);

                    Vector2f      randVelocity = new Vector2f((float)Math.Cos(angle), (float)Math.Sin(angle));
                    ShotgunPellet pellet       = new ShotgunPellet(player.rect.Position, randVelocity, player.Id);
                    pellet.Init();
                }
            }
        }
예제 #3
0
        public override Entity ToEntity()
        {
            ShotgunPellet pellet = new ShotgunPellet(new SFML.System.Vector2f(RectX, RectY), new SFML.System.Vector2f(velocityX, velocityY), ParentId);

            pellet.Id = Id;

            RectangleShape rect = new RectangleShape();

            rect.Position  = new SFML.System.Vector2f(RectX, RectY);
            rect.Size      = new SFML.System.Vector2f(RectWidth, RectHeight);
            rect.FillColor = Color.Red;

            pellet.rect = rect;

            pellet.moveDelta = new SFML.System.Vector2f(MoveDeltaX, MoveDeltaY);

            pellet.damagePoints = damagePoints;
            pellet.age          = age;

            pellet.moveSpeed = MoveSpeed;

            return(pellet);
        }