示例#1
0
        public virtual void collide(clsSprite s)
        {
            if (!live(20))
            {
                return;
            }
            // s.collide(this);
            s.live(20);
            // without the moment
            float e   = inf.elastic;
            float ee  = 1.0f + e;
            float emt = inf.mass - e * s.inf.mass;
            float ems = s.inf.mass - e * inf.mass;
            float m   = inf.mass + s.inf.mass;
            float vx  = (emt * velocity.X + ee * s.inf.mass * s.velocity.X) / m;
            float vy  = (emt * velocity.Y + ee * s.inf.mass * s.velocity.Y) / m;

            s.velocity.X = (ee * inf.mass * velocity.X + ems * s.velocity.X) / m;
            s.velocity.Y = (ee * inf.mass * velocity.Y + ems * s.velocity.Y) / m;
            velocity.X   = vx;
            velocity.Y   = vy;
            // attenuation
            s.acceleration.X = -0.2f;
            s.acceleration.Y = -0.2f;
            acceleration.X   = -0.2f;
            acceleration.Y   = -0.2f;
        }
示例#2
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     for (int i = sprites.Count - 1; i >= 0; --i)
     {
         clsSprite sprite = sprites[i];
         sprite.move();
         if (!sprite.alive())
         {
             sprites.RemoveAt(i);
         }
         else if (sprite.isvanish() &&
                  !sprite.intersect(ClientRectangle))
         {
             sprites.RemoveAt(i);
         }
         else
         {
             for (int j = sprites.Count - 1; j >= 0; --j)
             {
                 clsSprite s = sprites[j];
                 if (j != i && sprite.intersect(s.rect()))
                 {
                     sprite.collide(s);
                 }
             }
             if (sprite.alive() && sprite.isemission())
             {
                 Byte[] b = new Byte[4];
                 rand.NextBytes(b);
                 if (b[0] <= 8)
                 {
                     foreach (clsShot s in sprite.emit(infShot))
                     {
                         sprites.Add(s);
                     }
                 }
             }
         }
     }
     Invalidate();
 }