Example #1
0
            public override void Update(GameTime gameTime)
            {
                Gameplay g = Sender.Parent.Parent;

                #region Gestion de la gravité
                float vx = Velocity.X;
                float vy = Velocity.Y;

                if (!_onFloor)
                {
                    vy = GRAVITY;
                }

                // Dans l'eau
                if (Position.Y > g.WaterLevel)
                {
                    Velocity.Normalize();
                    if (Position.Y > g.WaterLevel + g.WaterHeight)
                    {
                        Die(false);
                    }
                }
                #endregion

                #region Limitations de la vélocité
                vx       = MathHelper.Clamp(vx, -SPEED_MAX, SPEED_MAX);
                vy       = MathHelper.Clamp(vy, -SPEED_MAX, SPEED_MAX);
                Velocity = new Vector2(vx, vy);
                #endregion

                #region Récupération de l'ancienne position en 3 points en bas (Gauche / Centre / Droite) pour vérifier les collisions
                Vector2 previousPosMiddle = new Vector2(BoundingBox.Location.X, BoundingBox.Size.Y);
                Vector2 previousPosLeft   = new Vector2(BoundingBox.Left, BoundingBox.Bottom);
                Vector2 previousPosRight  = new Vector2(BoundingBox.Right, BoundingBox.Bottom);
                #endregion

                base.Update(gameTime);

                #region Collision avec le sol
                Vector2 newPosLeft   = new Vector2(Position.X - ImgBox.Value.Width / 2, Position.Y);
                Vector2 newPosMiddle = Position;
                Vector2 newPosRight  = new Vector2(Position.X + ImgBox.Value.Width / 2, Position.Y);

                if (g.IsSolid(newPosLeft, previousPosLeft) ||
                    g.IsSolid(newPosMiddle, previousPosMiddle) ||
                    g.IsSolid(newPosRight, previousPosRight))
                {
                    _onFloor = true;

                    // Récupère l'altitude en Y à position.X -20 et +20 afin d'en déterminer l'angle à partir d'un vecteur tracé entre ces deux points.
                    Vector2 center = g.FindHighestPoint(Position, 0);
                    Vector2 before = g.FindHighestPoint(Position, -BoundingBox.Width / 2);
                    Vector2 after  = g.FindHighestPoint(Position, BoundingBox.Width / 2);
                    Angle     = (float)utils.MathAngle(after - before);
                    Position += center;
                }
                else
                {
                    _onFloor = false;
                }
                RefreshBoundingBox();
                #endregion
            }
Example #2
0
 public Particle(Gameplay pParent, Texture2D pImage, Rectangle?pImgBox, Vector2 pPosition, Vector2 pOrigin, Vector2 pScale) : base(pImage, pImgBox, pPosition, pOrigin, pScale)
 {
     Parent = pParent;
 }