/// <summary>
 /// handles shooting
 /// </summary>
 /// <param name="vector2"></param>
 /// <param name="alignment"></param>
 /// <param name="rotation"></param>
 public virtual void Shoot(Alignment alignment, float rotation)
 {
     PlayShootSoundEffect();
     BulletPool.CreateBullet(go, alignment,
                             bulletType, rotation + (GameWorld.Instance.Rnd.Next(-weaponSpread, weaponSpread)));
     Ammo--;
 }
Esempio n. 2
0
 /// <summary>
 /// Shoots an amount of  pellets, with a wide spread
 /// </summary>
 /// <param name="vector2"></param>
 /// <param name="alignment"></param>
 /// <param name="rotation"></param>
 public override void Shoot(Alignment alignment, float rotation)
 {
     PlayShootSoundEffect();
     for (int i = 0; i < Constant.shotgunPelletAmount; i++)
     {
         BulletPool.CreateBullet(go, alignment, bulletType, rotation + (GameWorld.Instance.Rnd.Next(-weaponSpread, weaponSpread)));
     }
     Ammo--;
     vehicle.Stats.ShotgunFired++;
 }
        /// <summary>
        /// Standard shooting behaviour for all towers
        /// </summary>
        protected virtual void Shoot()
        {
            if (shootTimeStamp + attackRate <= GameWorld.Instance.TotalGameTime)
            {
                Collider target;
                target = FindEnemiesInRange();
                if (target != null)
                {
                    Vector2 direction = new Vector2(target.CollisionBox.Center.X - GameObject.Transform.Position.X, target.CollisionBox.Center.Y - GameObject.Transform.Position.Y);
                    direction.Normalize();

                    float rotation = GetDegreesFromDestination(direction);
                    BulletPool.CreateBullet(GameObject, Alignment.Friendly, bulletType, rotation + (GameWorld.Instance.Rnd.Next(-spread, spread)));
                    shootTimeStamp = GameWorld.Instance.TotalGameTime;
                    PlayShootSoundEffect();
                }
            }
        }
        protected virtual void Shoot()
        {
            if (attackTimeStamp + attackRate <= GameWorld.Instance.TotalGameTime)
            {
                Collider target;
                target = FindTargetInRange();
                if (target != null)
                {
                    Vector2 direction = new Vector2(target.CollisionBox.Center.X - GameObject.Transform.Position.X, target.CollisionBox.Center.Y - GameObject.Transform.Position.Y);

                    direction.Normalize();

                    float rotation = GetDegreesFromDestination(direction);

                    RotateToMatchDirection(direction);

                    BulletPool.CreateBullet(GameObject, Alignment.Enemy,
                                            bulletType, rotation + (GameWorld.Instance.Rnd.Next(-spread, spread)));

                    if (attackVariation > 2)//Adds animation variation
                    {
                        attackVariation = 1;
                    }
                    animator.PlayAnimation("Attack" + attackVariation);
                    attackVariation++;

                    attackTimeStamp = GameWorld.Instance.TotalGameTime;

                    isAttacking = true;
                }
                else
                {
                    isAttacking = false;
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (gameState == GameState.Menu)
            {
                menu.Update();
            }
            else if (gameState == GameState.Game)
            {
                barrier.SignalAndWait();
                // Updates the Time
                deltaTime      = (float)gameTime.ElapsedGameTime.TotalSeconds;
                totalGameTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                //adds Gameobjects
                AddGameObjects();

                //call the Spawner
                spawner.Update();

                //Updates GameObjects
                foreach (var go in gameObjects)
                {
                    go.Update();
                }

                //Checks if any vehicle needs to respawn
                if (vehiclesToRemove.Count > 0)
                {
                    foreach (GameObject go in vehiclesToRemove)
                    {
                        foreach (Component comp in go.GetComponentList)
                        {
                            if (comp is Vehicle)
                            {
                                if ((comp as Vehicle).DeathTimeStamp + Constant.respawntime <= totalGameTime)
                                {
                                    (comp as Vehicle).Respawn((comp as Vehicle).PlayerNumber);

                                    VehiclesToRemove.Clear();

                                    break;
                                }
                            }
                        }
                        break;
                    }
                }

                lock (BulletPool.activeListKey)
                {
                    foreach (var go in BulletPool.ActiveBullets)
                    {
                        go.Update();
                    }
                }
                BulletPool.ReleaseList();
                RemoveObjects();
            }
            else if (gameState == GameState.GameOver)
            {
                gameOver.Update();
            }
            else if (gameState == GameState.Score)
            {
                //handles score funktions
                score.Update(gameTime);
            }

            base.Update(gameTime);
        }