Exemplo n.º 1
0
        public virtual Bullet Shoot(Enemy b)
        {
            if ((DateTime.Now - this.lastShoot).TotalMilliseconds < Config.ShootInterval)
                return null;
            else
                lastShoot = DateTime.Now;

            Vector2d Target = Vector2d.Zero;
            bool hit;
            Target = GetIntersect(b.position, b.P.Points[1].Coords,
                                    Bullet.Speed, b.Speed,
                                    b.position, this.position, out hit);

            if (!hit && b.P.Points.Count < 3)
                return null;
            if (!hit)
                Target = GetIntersect2(b.P.Points[1].Course - b.Elapsed, b.P.Points[1].Coords, b.P.Points[2].Coords,
                                    Bullet.Speed, b.Speed,
                                    b.position, this.position, out hit);
            if (Target.X > Config.MapSizeX || Target.Y > Config.MapSizeY || Target.X < 0 || Target.Y < 0)
                return null;
            Bullet ret = new Bullet(this.position, Target, DateTime.Now);
            ret.enemy = b;

            if (this is Cannon1)
                ret.Strength = Config.Strenght1;
            else if (this is Cannon2)
                ret.Strength = Config.Strenght2;
            else if (this is Cannon3)
                ret.Strength = Config.Strenght3;
            return ret;
        }
Exemplo n.º 2
0
        public virtual Vector2d BulletPrediction(Enemy b)
        {
            Vector2d dir = b.dir;

            //predicted bullet target
            Vector2d X = b.Speed * b.position - position * Bullet.Speed;
            X /= +b.Speed - Bullet.Speed;
            double d = (position - X).Length;
            Vector2d res = b.position + b.dir * d * Bullet.Speed;

            return res;
        }
Exemplo n.º 3
0
        private void Init()
        {
            Money = Config.InitialMoney;
            lastSpawn = DateTime.Now;
            spawn = 100;
            m = new Map(11, 6);
            st = DateTime.Now;
            Cannons = new List<Cannon>();

            Cannon1 c = new Cannon1(); c.position = new Vector2d(560, 80); Cannons.Add(c);

            c = new Cannon1(); c.position = new Vector2d(400, 200); Cannons.Add(c);
            c = new Cannon1(); c.position = new Vector2d(240, 100); Cannons.Add(c);
            c = new Cannon1(); c.position = new Vector2d(240, 180); Cannons.Add(c);
            c = new Cannon1(); c.position = new Vector2d(240, 240); Cannons.Add(c);

            Bullets = new List<Bullet>();

            Enemies = new LinkedList<Enemy>();
            Enemy a = new Enemy(); a.position = new Vector2d(0, 0);
            Enemies.AddFirst(a);
        }
Exemplo n.º 4
0
 private void glControl1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         Enemy a = new Enemy();
         Enemies.AddLast(a);
     }
 }
Exemplo n.º 5
0
 public virtual void CreateAim(Enemy Ball)
 {
     Vector2d a = BulletPrediction(Ball);
     Aim = a - position;
 }