public static void Create_Projectile(Vector2 StartPosition, Vector2 Direction, int Speed, int Damage, string AssetName, bool IsEnemyProjectile)
        {
            bool NeedNew = true;

            foreach (Projectile newBullet in Globals.ProjectileList)
            {
                if (!newBullet.IsAlive)
                {
                    newBullet.InitializeProjectile(Damage, Direction, Speed, AssetName, StartPosition, IsEnemyProjectile);
                    newBullet.LoadContent();
                    newBullet.SpritePosition.X -= newBullet.SpriteSize.Width / 2;
                    NeedNew = false;
                    break;
                }
            }

            if (NeedNew)
            {
                Projectile newBullet = new Projectile();
                newBullet.InitializeProjectile(Damage, Direction, Speed, AssetName, StartPosition, IsEnemyProjectile);
                newBullet.LoadContent();
                newBullet.SpritePosition.X -= newBullet.SpriteSize.Width / 2;
                Globals.ProjectileList.Add(newBullet);
            }
        }
Example #2
0
        private void fireProjectile()
        {
            double velX = m_velocity.X;
            double velY = m_velocity.Y;

            velX = 500;

            if (velX != 0 && velY != 0)
            {
                Projectile fireball = new Projectile(m_position.X, m_position.Y, velX, velY, PlayerId, PlayerGlowType);
                Game1.Instance.gameData.projectiles.Add(fireball);
            }
        }
        public void Update(bool[] input, int millis)
        {
            dt += millis;

            if (input[0])
            {
                player.standing = false;
                player.moving_left = true;
                if ((player.pos.X - player.pmove_speed) >= 0)
                {
                    player.pos.X -= player.pmove_speed;
                }
            }
            if (input[2])
            {
                player.standing = false;
                player.moving_left = false;
                if ((player.pos.X + player.pmove_speed) <= width)
                {
                    player.pos.X += player.pmove_speed;
                }
            }
            if (input[1])
            {
                player.standing = false;
                if ((player.pos.Y + player.pmove_speed) <= height)
                {
                    player.pos.Y += player.pmove_speed;
                }
            }
            if(input[3])
            {
                player.standing = false;
                if ((player.pos.Y - player.pmove_speed) >= 0)
                {
                    player.pos.Y -= player.pmove_speed;
                }
            }
            if (!(input[0] || input[1] || input[2] || input[3]))
            {
                player.standing = true;
            }

            weapon.pos = player.pos;
            player.bound.X = (int) player.pos.X;
            player.bound.Y = (int) player.pos.Y;

            zombies[0].Update(player.bound);

            if (input[4])
            {
                if (dt >= (shoot_dt * 1000))
                {
                    dt = 0;

                    Projectile p;
                    Vector2 offset;
                    if (!player.moving_left)
                    {
                        p = new Projectile(20, 10);
                        offset = new Vector2(84, 59);
                        p.pos = player.pos + offset;
                        weapon.switchFrameList(false);
                    }
                    else
                    {
                        p = new Projectile(20, -10);
                        offset = new Vector2(-84, 59);
                        p.pos = player.pos + offset;
                        weapon.switchFrameList(false);
                    }

                    p.standing_dt = 0.05f;
                    p.standingFrames.Add(tm.getTexture("BULLET"));
                    p.standingFrames.Add(tm.getTexture("BULLET2"));
                    p.standingFrames.Add(tm.getTexture("BULLET3"));
                    p.standingFrames.Add(tm.getTexture("BULLET4"));

                    projectiles.Add(p);
                }

            }
            else
            {
                weapon.switchFrameList(true);
            }

            for (int i = 0; i < projectiles.Count; i++)
            {
                projectiles[i].Update();
                if(outOfLevel(projectiles[i]))
                {
                    projectiles.RemoveAt(i);
                }

            }
        }