Ejemplo n.º 1
0
    public override void Advance()
    {
        FVector dpos = new FVector(input.xAxis, -input.yAxis);
        dpos = dpos.Normalize();
        if (input.stab && input.stabChanged)
        {
            // Swing counter-clockwise
            sword.Swing(Sword.SwingState.CCWISE, facing);
        }
        else if (input.swingLeft && input.swingLeftChanged)
        {
            // Stab
            sword.Swing(Sword.SwingState.STAB, facing);
        }
        else if (input.swingRight && input.swingRightChanged)
        {
            // Swing clockwise
            sword.Swing(Sword.SwingState.CWISE, facing);
        }

        if (dpos.x != 0L || dpos.y != 0L)
        {
            position.x += dpos.x * CalculateSpeed() * Game.TIMESTEP;
            position.y += dpos.y * CalculateSpeed() * Game.TIMESTEP;
            lastFacing.RemoveAt(0);
            lastFacing.Add(dpos);
        }

        FInt fdx = 0L;
        FInt fdy = 0L;
        foreach (FVector vec in lastFacing)
        {
            fdx += vec.x;
            fdy += vec.y;
        }

        // TODO: Clean up this hack with animations
        if (fdx < 0L)
        {
            characterImg.transform.localPosition = new Vector3(30, 118, 0);
            characterImg.transform.localScale = new Vector3(184, 253, 1);
            characterMask.transform.localScale = new Vector3(137, 148, 1);
        }
        else
        {
            characterImg.transform.localPosition = new Vector3(-30, 118, 0);
            characterImg.transform.localScale = new Vector3(-184, 253, 1);
            characterMask.transform.localScale = new Vector3(-137, 148, 1);
        }

        sword.Advance();
        base.Advance();
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the result of adding two bounding volumes together.
        /// </summary>
        /// <param name="a">The first bounding volume.</param>
        /// <param name="b">The second bounding volume.</param>
        /// <returns>A new bounding volume.</returns>
        public static FSphere operator +(FSphere a, FSphere b)
        {
            if (a.W == 0.0f)
            {
                a = b;
            }
            else if (a.IsInside(b))
            {
                a = b;
            }
            else if (b.IsInside(a))
            {
                // no change
            }
            else
            {
                FSphere newSphere;

                FVector dirToOther     = b.Center - a.Center;
                FVector unitDirToOther = dirToOther;
                unitDirToOther.Normalize();

                float newRadius = (dirToOther.Size() + b.W + a.W) * 0.5f;

                // find end point
                FVector end1      = b.Center + unitDirToOther * b.W;
                FVector end2      = a.Center - unitDirToOther * a.W;
                FVector newCenter = (end1 + end2) * 0.5f;

                newSphere.Center = newCenter;
                newSphere.W      = newRadius;

                // make sure both are inside afterwards
                Debug.Assert(b.IsInside(newSphere, 1.0f));
                Debug.Assert(a.IsInside(newSphere, 1.0f));

                a = newSphere;
            }

            return(a);
        }
Ejemplo n.º 3
0
 public override void Advance()
 {
     if (state == State.WAITING)
     {
         cooldown += Game.TIMESTEP;
         if (cooldown >= jumpCooldown)
         {
             cooldown = 0L;
             jumpDirection = Game.instance.GetNearestPlayerPosition(position);
             jumpDirection.x = (jumpDirection.x - position.x);
             jumpDirection.y = (jumpDirection.y - position.y);
             jumpDirection = jumpDirection.Normalize();
             if (jumpDirection.x < 0L)
             {
                 transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
             }
             else
             {
                 transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
             }
             state = State.JUMPING;
         }
     }
     else if (state == State.JUMPING)
     {
         timeJumping += Game.TIMESTEP;
         if (timeJumping >= jumpDuration)
         {
             timeJumping = 0L;
             state = State.WAITING;
         }
         else
         {
             position.x += jumpDirection.x * speed * Game.TIMESTEP;
             position.y += jumpDirection.y * speed * Game.TIMESTEP;
         }
     }
     base.Advance();
 }