Пример #1
0
        private void Enemy_Collided(object sender, BlockCollisionEventArgs e)
        {
            Vector2 vec = new Vector2(VelX + ((this.X + Size / 2) / Map.EntityPixelPerCase) * Map.EntityPixelPerCase + Map.EntityPixelPerCase / 2 - (this.X + this.Size / 2),
                                      VelY + ((this.Y + Size / 2) / Map.EntityPixelPerCase) * Map.EntityPixelPerCase + Map.EntityPixelPerCase / 2 - (this.Y + this.Size / 2));

            vec.Normalize();
            //vec *= _SpeedFactor;
            this.VelX = vec.X;
            this.VelY = vec.Y;

            //this.X = ((this.X + this.Size / 2) / Map.EntityPixelPerCase) * Map.EntityPixelPerCase + Map.EntityPixelPerCase / 2;
            //this.Y = ((this.Y + this.Size / 2) / Map.EntityPixelPerCase) * Map.EntityPixelPerCase + Map.EntityPixelPerCase / 2;
        }
Пример #2
0
 public void FireCollided(object sender, BlockCollisionEventArgs e)
 {
     Collided?.Invoke(sender, e);
 }
Пример #3
0
        /// <summary>
        /// Calcule le mouvement de l'entité
        /// </summary>
        /// <param name="DeltaTime"></param>
        public override void Tick(long deltaTime)
        {
            Enemy ent = this as Enemy;

            if (ent != null)
            {
                if (ent._path == null)
                {
                    int i = 0;
                }
            }

            float dt = deltaTime / 2;
            //VelY += 0.2f;
            int vx = (int)(VelX * dt);
            int vy = (int)(VelY * dt);

            List <CollisionInfo> res = CheckCollision(X, Y, vx, vy);
            CollisionSide        rs  = 0;

            foreach (CollisionInfo c in res)
            {
                rs |= c.Side;
                if (c.Case != null && c.Case.IsBreaking)
                {
                    FireDied(this, new CancellableEventArgs(false));
                }
            }

            bool Or = false;

            if (Math.Abs(VelX) < 0.01f)
            {
                VelX = 0;
                Or   = true;
            }
            if (Math.Abs(VelY) < 0.01f)
            {
                VelY = 0;
                Or   = true;
            }
            if (Or)
            {
                FireMoved(this, new CancellableEventArgs(false));
            }

            if (vx == 0 && vy == 0)
            {
                return;
            }


            if (rs != CollisionSide.None)
            {
                BlockCollisionEventArgs e = new BlockCollisionEventArgs(X / Map.EntityPixelPerCase, Y / Map.EntityPixelPerCase, res, false);
                FireCollided(this, e);
                if ((rs & (CollisionSide.Left | CollisionSide.Right)) > 0)
                {
                    //_velx = 0;
                    vx = 0;
                }
                if ((rs & (CollisionSide.Up | CollisionSide.Down)) > 0)
                {
                    //_vely = 0;
                    vy = 0;
                }
            }


            if (X / Map.EntityPixelPerCase != (X + vx) / Map.EntityPixelPerCase) // Side only
            {
                FireChangedCase(this, new MultiCaseEventArgs(Map[X / Map.EntityPixelPerCase, Y / Map.EntityPixelPerCase], new AbsCase[] {
                    Map[(X + vx) / Map.EntityPixelPerCase, (Y + vy) / Map.EntityPixelPerCase]
                }, false));
                if (Y / Map.EntityPixelPerCase != (Y + vy) / Map.EntityPixelPerCase) // Both side and up/down
                {
                    FireChangedCase(this, new MultiCaseEventArgs(Map[X / Map.EntityPixelPerCase, Y / Map.EntityPixelPerCase], new AbsCase[] {
                        Map[(X + vx) / Map.EntityPixelPerCase, (Y + vy) / Map.EntityPixelPerCase],
                        Map[(X + vx) / Map.EntityPixelPerCase, Y / Map.EntityPixelPerCase],
                        Map[X / Map.EntityPixelPerCase, (Y + vy) / Map.EntityPixelPerCase]
                    }, false));
                }
            }
            else if (Y / Map.EntityPixelPerCase != (Y + vy) / Map.EntityPixelPerCase) // Up/Down only
            {
                FireChangedCase(this, new MultiCaseEventArgs(Map[X / Map.EntityPixelPerCase, Y / Map.EntityPixelPerCase], new AbsCase[] {
                    Map[(X + vx) / Map.EntityPixelPerCase, (Y + vy) / Map.EntityPixelPerCase]
                }, false));
            }
            X += vx;
            Y += vy;
            FireMoved(this, new CancellableEventArgs(false));
        }