Beispiel #1
0
        private void UpdateTarget(GameTime gameTime)
        {
            float distance = Vector2.Distance(Target.Position, Position);

            if ((distance <= CurrentStatistics.Radius * Session.singleton.Map.TileDimensions.X && Target.IsActive) &&
                (!(Map.ToMapCoordinates((int)Target.Position.X, (int)Target.Position.Y).Equals(Map.CastleLocation))))
            {
                float   rate = bulletBase.Speed;
                Vector2 d    = Vector2.Add(Target.Position, Vector2.Multiply(Target.Velocity, distance / rate)) - Position;
                Rotation = (float)Math.Atan2(d.Y, d.X);

                if (timer <= 0)
                {
                    Bullet b = bulletBase.Clone();
                    b.Fire(this);
                    Bullets.Add(b);
                    timer = CurrentStatistics.Speed;
                }
            }
            else
            {
                Target.DieEvent -= new EventHandler(m_DieEvent);
                Target           = null;
            }
        }
Beispiel #2
0
 public void Move()
 {
     if (NativeKeyboard.IsKeyDown(KeyCode.Right))
     {
         if (x > 0)
         {
             Move(Program.Direction.Right);
             if (step++ == 1)
             {
                 step = 0;
             }
         }
         CharacterDirection = Program.Direction.Right;
     }
     if (NativeKeyboard.IsKeyDown(KeyCode.Left))
     {
         if (x > 1)
         {
             Move(Program.Direction.Left);
             if (step-- == 0)
             {
                 step = 1;
             }
             CharacterDirection = Program.Direction.Left;
         }
     }
     if (jump == 0 && NativeKeyboard.IsKeyDown(KeyCode.Up))
     {
         jump = 1;
     }
     if (NativeKeyboard.IsKeyDown(KeyCode.Space))
     {
         Bullets.Add(new Bullet(x + ((CharacterDirection == Program.Direction.Right) ? +3 : -3), y - 1, CharacterDirection));
     }
 }
Beispiel #3
0
 public void Add(Bullet bullet)
 {
     lock (_locker)
     {
         Bullets.Add(bullet);
     }
 }
Beispiel #4
0
        public void Shoot(Direction d)
        {
            if (shootTimer <= 0)
            {
                // Shoot
                Bullet b = new Bullet(this);
                b.Position = position;
                switch (d)
                {
                case Direction.Left:
                    b.Velocity = new Vector2(-1, 0);
                    break;

                case Direction.Right:
                    b.Velocity = new Vector2(1, 0);
                    break;

                case Direction.Up:
                    b.Velocity = new Vector2(0, -1);
                    break;

                case Direction.Down:
                    b.Velocity = new Vector2(0, 1);
                    break;

                default:
                    break;
                }
                Bullets.Add(b);
                shootTimer += ShootDelay;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Update the system and all active bullets contained in it.
        /// </summary>
        public void Update()
        {
            if (!Begun)
            {
                return;
            }
            // Update the bullets.
            foreach (DmlBullet bullet in Bullets)
            {
                bullet.Update(this);
            }

            // Add the newly spawned bullets.
            foreach (DmlBullet bullet in ToAdd)
            {
                if (Bullets.Count >= DmlSystem.BULLET_CAP)
                {
                    break;
                }
                Bullets.Add(bullet);
            }

            ToAdd.Clear();

            // Remove all the dead bullets.
            Bullets.RemoveAll(b => b.Dead);

            // Update the timeline.
            Timeline.Update(this);
        }
Beispiel #6
0
        public override void Update(GameTime gameTime)
        {
            Player p = GetNearestPlayer();

            gunTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (p != null && Vector2.Distance(p.Position, Position) > 300)
            {
                float a = GetAngleBetweenSprite(p);
                Velocity = new Vector2((float)Math.Cos(a), (float)Math.Sin(a)) * 400f;
            }

            if (p != null && gunTimer > 600)
            {
                gunTimer = 0;
                float a = GetAngleBetweenSprite(p);

                Vector2 vel = new Vector2((float)Math.Cos(a), (float)Math.Sin(a)) * (float)(250f + rand.NextDouble() * 100);

                Bullet b = new LinearBullet(EntitySide.ENEMY, 3000f, vel)
                {
                    Texture  = BulletTexture,
                    Size     = new Point(16, 16),
                    Position = Position,
                    Color    = Color.White,
                };
                Bullets.Add(b);
            }

            Position += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            Velocity  = Vector2.Zero;
            base.Update(gameTime);
        }
Beispiel #7
0
            public override void RightClick(Player player)
            {
                item.stack++;
                // Get the item that the player is holding in their mouse.
                Item mouse = Main.mouseItem;

                // If the bandolier already has an item of this type,
                if (Bullets.Any(x => x.type == mouse.type))
                {
                }
                else if (Bullets.Count > 0 && (mouse.IsAir || mouse.ammo != AmmoID.Bullet || mouse.notAmmo || !mouse.consumable))
                {
                    // Don't give back more than 999
                    player.QuickSpawnItem(Bullet, Math.Min(999, Bullet.maxStack));
                    Bullets.Remove(Bullet);
                }
                // Otherwise, add a new item to the queue.
                else if (Bullets.Count < 10 && mouse.stack >= 999 || mouse.stack == mouse.maxStack)
                {
                    mouse.stack = 1;
                    Bullets.Add(mouse.Clone());

                    mouse.TurnToAir();
                    player.inventory[58] = mouse;
                }

                // Update stats, kill the item, and update the mouse item.
                Bullets.RemoveAll(x => x.IsAir);
                UpdateStats();
            }
Beispiel #8
0
        public void Shoot()
        {
            Bullet bullet = new Bullet(this.Rotation + pi, this.Position, this.faceDirection);

            bullet.Texture = bulletTexture;
            Bullets.Add(bullet);
        }
Beispiel #9
0
 void Attack()
 {
     if (_nextTimeAttack <= LivedTime)
     {
         Bullets.Add(_bulletPoolBase.CreateObject());
         _nextTimeAttack = LivedTime + _timeBetweenAttacks;
     }
 }
Beispiel #10
0
 public void MakeShot(Player player)
 {
     if (Bullets.Count < MaxBulletCount)
     {
         Bullets.Add(new Bullet(new Point(player.Location.X, player.Location.Y + 5),
                                player.CurrentTypeMovement));
     }
 }
Beispiel #11
0
 public void Register(Bullet bullet)
 {
     if (Bullets.Count >= MaxBullets)
     {
         throw new InvalidOperationException($"Bullet count has reached the maximum for {Name}");
     }
     Bullets.Add(bullet);
 }
        public void Shoot()
        {
            Bullet b = (new Bullet(Position + new Vecteur2D(9, 0), GameVariables.defaultShootSpeed, 1, Direction.Down, GameSprites.Bullet2));

            Bullets.Add(b);
            Game.game.AddGameEntity(b);
            GameSounds.ennemyShooting.Play();
        }
Beispiel #13
0
 public override void Initialize()
 {
     base.Initialize();
     for (int i = 0; i < CountOfBullets; i++)
     {
         BulletBase bullet = new Bullet2(Danmaku, GetPosition(FiArray[i]), Danmaku.MainObject, OwnerObject, OnCollision);
         Bullets.Add(bullet);
     }
 }
Beispiel #14
0
        /// <summary>
        /// Lance un missile.
        /// </summary>
        public void Shoot()
        {
            //Console.WriteLine("Tir du joueur");
            Bullet b = new Bullet(new Vecteur2D(this.Position.x + 9, Position.y), ShootingSpeed, 7, Direction.Up, GameSprites.Bullet1);

            Bullets.Add(b);
            Game.game.AddGameEntity(b);
            GameSounds.playerShooting.Play();
        }
Beispiel #15
0
        private void PopulateState(BaseItem item)
        {
            if (item is Empty empty)
            {
                EmptyItems.Add(empty);
                return;
            }

            if (item is AiTank aiTank)
            {
                AiTanks.Add(aiTank);

                if (item is AiPrizeTank aiPrizeTank)
                {
                    AiPrizeTanks.Add(aiPrizeTank);
                }

                return;
            }

            if (item is EnemyTank enemyTank)
            {
                EnemyTanks.Add(enemyTank);
                return;
            }

            if (item is MyTank myTank)
            {
                MyTank = myTank;
                return;
            }

            if (item is Bullet bullet)
            {
                Bullets.Add(bullet);
                return;
            }

            if (item is River river)
            {
                Rivers.Add(river);
                return;
            }

            if (item is Tree tree)
            {
                Trees.Add(tree);
                return;
            }

            if (item is Ice ice)
            {
                Ice.Add(ice);
                return;
            }
        }
Beispiel #16
0
        public override void Update()
        {
            //string pattern = "Arrowhead";
            //string trajectory = "Arc";
            //int numBullets = 10;
            //string bulletType = "BulletTypeA";
            int initialXPosition = Constants.K - (30 * ((Mobs.Count / 2) - 1));

            if (FrameCount == 0)
            {
                foreach (MobileEntity mob in Mobs)
                {
                    mob.Position = new Vector2((initialXPosition + 30 * Mobs.IndexOf(mob)), -30 * (Mobs.IndexOf(mob) + 1));
                    mob.Active   = true;
                }
            }
            foreach (MobileEntity mob in Mobs)
            {
                //mobs enter from top of screen for 5 seconds
                if (FrameCount < 5 * Constants.FPS)
                {
                    if (mob.Position.Y < Constants.F)
                    {
                        mob.UpdatePosition("down");
                    }
                    else if (mob.Position.Y < Constants.F + mob.MoveSpeed)
                    {
                        //fire(pattern, mob, bulletType, mob.Color, numBullets, trajectory);
                        if (this.willFire && mob.Active)
                        {
                            //List<MobileEntity>bullets = formation.SetFormation("BulletTypeA", mob.Position);
                            Formation formation = new Arrowhead(bulletMaker, mob.Position);
                            //List<MobileEntity> bulletFormation = BulletMaker.CreateBulletList("BulletTypeA", new Arrowhead(mob.Position));
                            Bullets.Add(MoveScriptMaker.CreateMoveScript("Arc", formation.SetFormation("BulletTypeA"), false));
                        }
                        mob.UpdatePosition("down");
                    }
                }
                else //mobs begin exiting one by one
                {
                    if (FrameCount > (5 + Mobs.IndexOf(mob)) * Constants.FPS)
                    {
                        mob.UpdatePosition("up");
                    }
                    if (mob.Position.Y < 0)
                    {
                        mob.Active = false;
                    }
                }
            }
            foreach (MoveScript formation in Bullets)
            {
                formation.Update();
            }
            FrameCount++;
        }
Beispiel #17
0
        public void Shoot()
        {
            Point p = new Point(Position.X + 25, Position.Y + 25);

            if (Ammo > 0)
            {
                Bullets.Add(new Bullet(p, Dir, Color.OrangeRed));
                Ammo--;
            }
        }
        void handleMessagePlayerInfo(GameMessage message)
        {
            if (!(message is MessagePlayerInfo))
            {
                return;
            }
            MessagePlayerInfo messageInfo = message as MessagePlayerInfo;

            if (message.PlayerID == ThisPlayerID)
            {
                while (UnacknowledgedInputs.Count > 0 &&
                       UnacknowledgedInputs.Peek().InputNumber <= messageInfo.InputNumber)
                {
                    UnacknowledgedInputs.Dequeue();
                }
            }
            Player newPlayer = null;

            if (Players.Keys.Contains(messageInfo.PlayerID))
            {
                newPlayer = messageInfo.Player;
                if (messageInfo.Player.PlayerState == PlayerState.Shoot)
                {
                    var bullet = newPlayer.Shoot(int.MaxValue);
                    Bullets.Add(bullet);
                }
                if (EventChangeState.GetInvocationList().Count() > 0)
                {
                    if (newPlayer.PlayerState != PlayerState.None)
                    {
                        EventChangeState(newPlayer, message.PlayerID);
                    }
                }
            }
            else
            {
                return;
            }

            if (isReconcilation && message.PlayerID == ThisPlayerID)
            {
                foreach (var messageAction in UnacknowledgedInputs)
                {
                    applyInput(newPlayer, messageAction.Action);
                    updatePhysicsPlayer(newPlayer, PhysicalUpdateInterval);
                    newPlayer.PlayerState = newPlayer.PlayerState & (PlayerState.Killed | PlayerState.Shoot);
                }
            }

            /* if (Players[message.PlayerID].Position.X != newPlayer.Position.X
            || Players[message.PlayerID].Position.Y != newPlayer.Position.Y)
            ||   return;*/

            Players[message.PlayerID] = newPlayer;
        }
Beispiel #19
0
            public override void RightClick(Player player)
            {
                item.stack++;
                // Get the item that the player is holding in their mouse.
                Item mouse = Main.mouseItem;

                // If the bandolier already has an item of this type,
                if (Bullets.Any(x => x.type == mouse.type))
                {
                    // just add their stacks together.
                    Item item1 = Bullets.First(x => x.type == mouse.type);
                    item1.stack += mouse.stack;

                    mouse.TurnToAir();
                    player.inventory[58] = mouse;
                }
                else if (Bullets.Count > 0 && (mouse.IsAir || mouse.ammo != AmmoID.Bullet || mouse.notAmmo || !mouse.consumable))
                {
                    if (Bullet.stack > 4995)
                    {
                        Bullet.stack -= 4995;
                        for (int i = 0; i < 5; i++)
                        {
                            player.QuickSpawnItem(Bullet, 999);
                        }
                    }
                    else
                    {
                        int numStacks = Bullet.stack / 999;
                        int remainder = Bullet.stack % 999;

                        for (int i = 0; i < numStacks; i++)
                        {
                            player.QuickSpawnItem(Bullet, 999);
                        }

                        player.QuickSpawnItem(Bullet, remainder);
                        Bullets.Remove(Bullet);
                    }
                }
                // Otherwise, add a new item to the queue.
                else if (Bullets.Count < 5)
                {
                    mouse.maxStack = 999999;
                    Bullets.Add(mouse.Clone());

                    mouse.TurnToAir();
                    player.inventory[58] = mouse;
                }

                // Update stats, kill the item, and update the mouse item.
                Bullets.RemoveAll(x => x.IsAir || x.type == 0);
                UpdateStats();
            }
 /// <summary>
 /// what happens when the Seeker fires
 /// </summary>
 public override void fire()
 {
     if (BulletCoolDown == 0)
     {
         Bullets.Add(new SeekingBullet(Position.X - Settings.bulletWidth / 2, Position.Y - Settings.bulletHeight / 2, Velocity.X, Velocity.Y, Rotation, "laser3PIC", target));
         BulletCoolDown = 150;
         base.fire();
         try { GameSounds.effect(GameMedia.getDir["laser2SND"]); }
         catch { }
     }
 }
Beispiel #21
0
 public static void Add(string name, Bullet bullet)
 {
     if (!Bullets.ContainsKey(name))
     {
         Bullets.Add(name, bullet);
         if (DefaultBullet == null)
         {
             DefaultBullet = bullet;
         }
     }
 }
Beispiel #22
0
 public void Shoot()
 {
     if (Bullets.Count < k_MaxNumOfBullets && IsShootableActive)
     {
         Vector2 bulletPosition = new Vector2(m_Position.X + k_DeltaForCorrectBulletPosiotionX, m_Position.Y - k_DeltaForCorrectBulletPosiotionY);
         Bullet  bullet         = new Bullet(bulletPosition, eDirection.Up, Game as GameStructure);
         bullet.TintColor = Color.Red;
         Bullets.Add(bullet);
         SpaceShipManager.Add(bullet);
         m_ShootSound.Play();
     }
 }
Beispiel #23
0
        public Bullet FireBullet()
        {
            if ((Bullets.Count) > MaxBullets)
            {
                return(null);
            }
            var bulletId  = $"{Id}_{++LifetimeBulletCount}";
            var newBullet = new Bullet(Team, this, bulletId, Position);

            Bullets.Add(newBullet);
            return(newBullet);
        }
Beispiel #24
0
 /// <summary>
 /// Creates and prepares bullets
 /// </summary>
 private void PrepareBullets()
 {
     BulletsGameObj = GameObject.Find("Bullets");
     for (int i = 0; i < 3; i++)
     {
         GameObject bullet = PhotonNetwork.Instantiate(_bullet.name, Vector3.zero, Quaternion.identity);
         bullet.GetComponent <Bullet>().photonView.RPC("SetActive", RpcTarget.All, false);
         bullet.name             = photonView.Owner.NickName + "Bullet" + (i + 1);
         bullet.transform.parent = BulletsGameObj.transform;
         Bullets.Add(bullet);
     }
 }
        private void CreateBullet(DynamicEntity entity)
        {
            if ((entity as IShootingEntity).Recharge > 0)
            {
                return;
            }

            float x = entity.X + entity.Width / 2 - 6;
            float y = entity.Y + entity.Height / 2 - 6;

            Bullets.Add(new BulletViewModel(Convert.ToInt32(x), Convert.ToInt32(y), 10, 10, entity.Direction, entity));
            (entity as IShootingEntity).Recharge = 0.3f;
        }
Beispiel #26
0
        public void Shoot()
        {
            Random rnd = Program.Rnd;
            int    nb  = 10; //rnd.Next(100);

            for (int i = 0; i < nb; i++)
            {
                Bullets.Add(new Bullet()
                {
                    Position = new Vector2(rnd.Next(4096)), Velocity = new Vector2(rnd.Next(30)), Type = (eAmmoType)rnd.Next(2), ShouldBeSend = true
                });
            }
        }
 private void BulletShoot()
 {
     lock (Sprite)
     {
         ShotSound.Play();
         BulletCounter++;
         var bullet = new Bullet {
             Shape = { Position = Center }
         };
         bullet.CurrentVelocity = AimDirectionNormal * bullet.MaxVelocity;
         Bullets.Add(bullet);
     }
 }
Beispiel #28
0
        public void Gun()
        {
            var bullet = new Bullet(this.SceneManager.UpdateTime.TotalGameTime)
            {
                Texture      = BulletTexture,
                SceneManager = this.SceneManager,
                Position     = this.CenterPosition(),
                Size         = new MyPoint(9, 23)
            };

            bullet.Position.X -= (bullet.Size.X / 2);
            bullet.Show();
            Bullets.Add(bullet);
        }
 protected override void updatePlayers(int time)
 {
     foreach (var player in Players.Values.ToArray())
     {
         if ((player.PlayerState & PlayerState.Killed) == 0)
         {
             updatePhysicsPlayer(player, time);
             if ((player.PlayerState & PlayerState.Shoot) != 0)
             {
                 Bullets.Add(player.Shoot(Environment.TickCount));
             }
         }
     }
 }
Beispiel #30
0
        public void Shot()
        {
            if (Bullets.Count() != 0)
            {
                return;
            }

            // 四方向に弾を生成する
            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
            {
                var bulletArea = new Rectangle(Area.Center, (ShotSize, ShotSize), Location.Center);
                Bullets.Add(new Bullet(bulletArea, dir, Color));
            }
        }