Example #1
0
        public Projectile(BulletType bulletType, int lifetime, UnitGraphics uGraphics, DCollider collider,
                          double shooterVelocity, double shooterFacing, double bulletVelocity, double shooterAngle,
                          double spawnX, double spawnY)
        {
            this.bulletType = bulletType;
            this.angle      = shooterAngle;
            this.velocity   = shooterVelocity;
            this.facing     = shooterFacing;

            this.uGraphics = uGraphics;
            this.collider  = collider;
            this.lifetime  = lifetime;
            this.posX      = spawnX;
            this.posY      = spawnY;

            Geometry.ApplyForce(ref this.velocity, ref this.angle, bulletVelocity, shooterFacing);
            if (bulletType == BulletType.Straight)
            {
                damage = 1;
            }
            else if (bulletType == BulletType.StraightStrong)
            {
                damage = 3;
            }
            else if (bulletType == BulletType.FourWay)
            {
                damage = 1;
            }
        }
Example #2
0
        /// <summary>
        /// Create one or more attack projectiles
        /// </summary>
        /// <param name="lifeTime">Number of game frames before the projectile auto-expires</param>
        /// <param name="currentFrame">Current game frame</param>
        /// <param name="bulletType">Type of bullet (default uses bulletMode as the type)</param>
        /// <param name="force">Force the bullet to fire even if it hasn't been long enough</param>
        /// <returns></returns>
        public void FireWeapon(int lifeTime, long currentFrame, BulletType bulletType = BulletType.Auto, bool force = false)
        {
            var projectiles = new List <Projectile>();

            //If it hasn't been long enough, don't fire.
            if (!force && currentFrame - lastFrameFired < framesBetweenBullets)
            {
                return;
            }
            if (bulletType == BulletType.Auto)
            {
                bulletType = bulletMode;
            }
            lastFrameFired = currentFrame;
            UnitGraphics bulletGfx      = null;
            DCollider    bulletCollider = null;
            double       bulletVelocity = 0;
            double       bulletAngle    = facing; //Bullet is thrusted in the direction of the firing unit's facing
            int          bulletCount    = 1;

            if (bulletType == BulletType.Straight)
            {
                bulletGfx      = new UnitGraphics(uGraphics.color, LineArt.TinyTim);
                bulletCollider = new DCollider(0, 0, 4);
                bulletVelocity = 4;
            }
            else if (bulletType == BulletType.StraightStrong)
            {
                bulletGfx      = new UnitGraphics(uGraphics.color, LineArt.TinyTim);
                bulletCollider = new DCollider(0, 0, 4);
                bulletVelocity = 4;
            }
            else if (bulletType == BulletType.FourWay)
            {
                bulletGfx      = new UnitGraphics(uGraphics.color, LineArt.TinyTim);
                bulletCollider = new DCollider(0, 0, 4);
                bulletVelocity = 3;
                bulletCount    = 4;
            }
            else
            {
                System.Diagnostics.Debugger.Break();
            }
            for (int i = 0; i < bulletCount; i++)
            {
                lastBulletIndex = (lastBulletIndex + 1) % bulletPoints.Count;
                var bulletSpawnPoint = Geometry.Rotate(bulletPoints[lastBulletIndex], (float)facing);
                projectiles.Add(new Projectile(bulletType, lifeTime, bulletGfx, bulletCollider, velocity, facing,
                                               bulletVelocity, bulletAngle, posX + bulletSpawnPoint.X, posY + bulletSpawnPoint.Y));
                if (bulletType == BulletType.FourWay)
                {
                    bulletAngle += (Math.PI / 2);
                }
            }

            if (!ReferenceEquals(OnWeaponFire, null))
            {
                OnWeaponFire(projectiles);
            }
        }
Example #3
0
 public DCollider(UnitGraphics uGraphics)
 {
     dCircles.Add(new DCircle()
     {
         Radius = 10
     });
     //throw new NotImplementedException("Need to make a collision shape from the graphics");
 }
Example #4
0
 public ShipBase(UnitGraphics uGraphics, Behavior behavior, int health, int framesBetweenBullets, double posX, double posY, List <PointF> bulletPoints)
 {
     this.uGraphics            = uGraphics;
     this.collider             = new DCollider(uGraphics);
     this.bulletPoints         = bulletPoints;
     this.posX                 = posX;
     this.posY                 = posY;
     this.health               = health;
     this.behavior             = behavior;
     this.framesBetweenBullets = framesBetweenBullets;
 }