Пример #1
0
    public static Scheduler SpawnEnemy(GameObject objectToSpawn, FVector2 position )
    {
        GameObject newObj = (GameObject) Instantiate(objectToSpawn, new Vector3(position.X, position.Y, 0.0f), Quaternion.identity);
        newObj.AddComponent("Scheduler");

        return newObj.GetComponent<Scheduler>();
    }
Пример #2
0
    private void UpdateShotAngle()
    {
        Ray ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
        Vector3 temp3 = ray.origin - gameObject.transform.position;
        FVector2 temp2 = new FVector2(temp3.x, temp3.y);
        temp2.Normalize();

        foreach(Weapon weap in weaponList) {
            weap.SetDirection(temp2);
        }
    }
Пример #3
0
    public static PolygonShape CreateEqlTriangle(float sideLength, float density)
    {
        FVector2[] pointList = new FVector2[3];

        pointList[0] = new FVector2(0.0f, sideLength*0.25f*SR3);
        pointList[1] = new FVector2(sideLength*-0.5f, sideLength*-0.25f*SR3);
        pointList[2] = new FVector2(sideLength*0.5f, sideLength*-0.25f*SR3);
        PolygonShape shape = new PolygonShape(new Vertices(pointList), density);

        return shape;
    }
Пример #4
0
 public static PolygonShape CreateDiamond(float height, float width, float density)
 {
     if(height <= 0.0f || width <= 0.0f) {
         print ("INVALID SIZE VALUE FOR DIAMOND CLASS");
     }
     FVector2[] pointList = new FVector2[4];
     pointList[0] = new FVector2(0.0f, height/2.0f);
     pointList[1] = new FVector2(-width/2.0f, 0.0f);
     pointList[2] = new FVector2(0.0f, -height/2.0f);
     pointList[3] = new FVector2(width/2.0f, 0.0f);
     PolygonShape shape = new PolygonShape(new Vertices(pointList), density);
     return shape;
 }
Пример #5
0
    public void AddMovementEvent(FVector2 destination, float travelTime, int interpType = 0, float delay = 0.0f, bool guaranteeArrival = false )
    {
        SetupPhysics();
        MovementEvent move = new MovementEvent();
        move.destination = destination;
        move.travelTime = travelTime;
        move.interpType = interpType;
        move.delay = delay;
        move.guaranteeArrival = guaranteeArrival;
        movementEventList.AddLast(move);

        if(!movementActive) {
            StartMovementEvent();
        }
    }
Пример #6
0
    public void SetDirection(FVector2 newDir)
    {
        newDir.Normalize();
        direction = new FVector2(newDir.X, newDir.Y);

        float zAngle = Mathf.Acos(newDir.X)*180.0f/Mathf.PI;
        if(newDir.Y < 0.0f) {
            zAngle = 360.0f - zAngle;
        }

        zAngle -= 90.0f; //Up is our 0 degrees here :P

        gameObject.transform.rotation = Quaternion.identity;
        gameObject.transform.Rotate( new Vector3(0.0f, 0.0f,zAngle));
    }
Пример #7
0
    public static PolygonShape CreateFanPiece(float sideLength, float interiorAngle, float rotationAngle)
    {
        FVector2[] pointList = new FVector2[3];

        interiorAngle = Mathf.PI/180.0f*interiorAngle;
        rotationAngle = Mathf.PI/180.0f*rotationAngle;

        pointList[0] = new FVector2(0.0f, 0.0f);
        pointList[1] = new FVector2(sideLength, 0.0f);
        pointList[2] = new FVector2(sideLength*Mathf.Cos(interiorAngle), sideLength*Mathf.Sin(interiorAngle));

        Vertices vertices = new Vertices(pointList);
        vertices.Rotate(rotationAngle);

        return new PolygonShape(vertices, 1.0f);
    }
Пример #8
0
    public override void InitJoint()
    {
        base.InitJoint ();

        //Microsoft.Xna.Framework.FVector2 angleV = new Microsoft.Xna.Framework.FVector2(BodyB.PhysicsBody.Position.X - BodyA.PhysicsBody.Position.X, BodyB.PhysicsBody.Position.Y - BodyA.PhysicsBody.Position.Y);
        float ang = Mathf.Atan2(BodyB.PhysicsBody.Position.Y - BodyA.PhysicsBody.Position.Y, BodyB.PhysicsBody.Position.X - BodyA.PhysicsBody.Position.X);
        Microsoft.Xna.Framework.FVector2 angleV = new Microsoft.Xna.Framework.FVector2(Mathf.Cos(ang), Mathf.Sin(ang));
        //angleV.Normalize();
        joint = FarseerPhysics.Factories.JointFactory.CreatePrismaticJoint(FSWorldComponent.PhysicsWorld,
            BodyA.PhysicsBody,
            BodyB.PhysicsBody,
            Microsoft.Xna.Framework.FVector2.Zero,
            angleV);
        joint.CollideConnected = CollideConnected;
        //joint.Frequency = Frequency;
        //joint.DampingRatio = 0.5f; d
    }
Пример #9
0
    //More efficient b/c uses Sin/Cos only once
    public static PolygonShape[] CreateFanSet(float radius, float fanAngle, int shardCount, int density)
    {
        PolygonShape[] shapeList = new PolygonShape[shardCount];

        float interiorAngle = fanAngle / ((float) shardCount) * Mathf.PI/180.0f;

        FVector2[] pointList = new FVector2[3];
        pointList[0] = new FVector2(0.0f, 0.0f);
        pointList[1] = new FVector2(radius, 0.0f);
        pointList[2] = new FVector2(radius*Mathf.Cos(interiorAngle), radius*Mathf.Sin(interiorAngle));

        Vertices vertices = new Vertices(pointList);

        for(int index = 0; index < shardCount; index++) {
            shapeList[index] = new PolygonShape(vertices, density); //PolygonShape makes a deep copy of vertices so I can reuse this sucker
            vertices.Rotate(interiorAngle);
        }

        return shapeList;
    }
Пример #10
0
    public static PolygonShape Create(float sideLength, float angle, float density)
    {
        if(sideLength <= 0.0f) {
            print ("SIDE LENGTH FOR ISOSCELES TRIANGLE CLASS MUST BE POSITIVE");
        }
        if(angle <= 0.0f || angle >= 180.0f) {
            print ("INVALID ANGLE VALUE FOR ISOSCELES TRIANGLE CLASS");
        }
        FVector2[] pointList = new FVector2[3];

        float theta = Mathf.PI/360.0f*angle; //using half the angle size

        float halfHeight = sideLength*Mathf.Cos(theta) / 2.0f;
        float halfWidth = sideLength*Mathf.Sin(theta);

        pointList[0] = new FVector2(0.0f, halfHeight);
        pointList[1] = new FVector2(-halfWidth, -halfHeight);
        pointList[2] = new FVector2(halfWidth, -halfHeight);
        PolygonShape shape = new PolygonShape(new Vertices(pointList), density);

        return shape;
    }
Пример #11
0
        public override void Logic()
        {
            /* Switch animations if picking something up. */
            if (attachedPlayer.CarryingPickup() && !carryingLastFrame) {
                attachedPlayer.animator.Play("Jump Midair Carry");
            }
            else if (!attachedPlayer.CarryingPickup() && carryingLastFrame) {
                attachedPlayer.animator.Play("Jump Midair");
            }

            /* If player isn't allow to move, then just stay frozen until he can. */
            if (!attachedPlayer.canMove) {
                return;
            }

            HandleAnimationDirection();

            float xAxisTilt = Input.GetAxis("Horizontal");

            /* Handle left/right movement. */
            float velChange = (xAxisTilt * attachedPlayer.walkingVelocity) - attachedPlayer.body.LinearVelocity.X;
            FVector2 horizImpulse = new FVector2(attachedPlayer.body.Mass * velChange, 0f);
            attachedPlayer.body.ApplyLinearImpulse(horizImpulse);

            /* Play landing animation. */
            if (attachedPlayer.IsGrounded()) {
                if (attachedPlayer.CarryingPickup()) {
                    attachedPlayer.animator.Play("Jump Landing Carry");
                }
                else {
                    attachedPlayer.animator.Play("Jump Landing");
                }
            }

            carryingLastFrame = attachedPlayer.CarryingPickup();
        }
Пример #12
0
    /* If the player's velocity gets larger than the predefined limits, then enforce the
     * predefined limits by brute force. */
    void HandleVelocityCap()
    {
        FVector2 currentVelocity = body.LinearVelocity;
        FVector2 cappingForce = new FVector2(0f, 0f); // Use this opposing force to enfore the velocity cap.

        /* Cap positive/negative x velocity if necessary. */
        if (Mathf.Abs(currentVelocity.X) > maxVelocityX) {
            cappingForce.X = maxVelocityX - currentVelocity.X;
        }

        /* Cap positive y velocity if necessary. Don't mess w/ negative y velocity or you might mess up gravity. */
        if (currentVelocity.Y > maxVelocityY) {
            cappingForce.Y = maxVelocityY - currentVelocity.Y;
        }

        body.ApplyLinearImpulse(cappingForce);
    }
Пример #13
0
        public override void Logic()
        {
            /* Switch animations if picking something up. */
            if (attachedPlayer.CarryingPickup() && !carryingLastFrame) {
                attachedPlayer.animator.Play("Jump Lift Carry");
            }
            else if (!attachedPlayer.CarryingPickup() && carryingLastFrame) {
                attachedPlayer.animator.Play("Jump Lift");
            }

            /* If player isn't allow to move, then just stay frozen until he can. */
            if (!attachedPlayer.canMove) {
                return;
            }

            HandleAnimationDirection();

            float xAxisTilt = Input.GetAxis("Horizontal");

            /* If player is touching the ground. */
            if (isGrounded) {

                /* Play lifting animation. */
                if (attachedPlayer.CarryingPickup()) {
                    attachedPlayer.animator.Play("Jump Lift Carry");
                }
                else {
                    attachedPlayer.animator.Play("Jump Lift");
                }

                isGrounded = false;
                float impulse = attachedPlayer.jumpingVelocity * attachedPlayer.body.Mass;
                FVector2 verticalMovement = new FVector2(0.0f, impulse);
                attachedPlayer.body.ApplyLinearImpulse(verticalMovement);

                /* Play jumping sound. */
                attachedPlayer.sfxPlayer.clip = attachedPlayer.jumpSound;
                attachedPlayer.sfxPlayer.loop = false;
                /* Give some variation to the jump pitch. */
                if (!attachedPlayer.NearVortex()) {
                    attachedPlayer.sfxPlayer.pitch = 1.0f + 0.02f*UnityEngine.Random.Range(-11, 6);
                }
                attachedPlayer.sfxPlayer.Play();
            }

            if (Input.GetButtonUp("Jump")) {
                releasedJumpButton = true;
            }

            /* If you released the jump button, then player's jump should stop sooner. */
            if (releasedJumpButton) {
                attachedPlayer.body.ApplyLinearImpulse(
                    new FVector2(
                        0.0f,
                        -attachedPlayer.body.LinearVelocity.Y * attachedPlayer.jumpReleaseVelocityFalloffRate
                    )
                );
            }

            /* Handle left/right movement. */
            float velChange = (xAxisTilt * attachedPlayer.walkingVelocity) - attachedPlayer.body.LinearVelocity.X;
            FVector2 horizImpulse = new FVector2(attachedPlayer.body.Mass * velChange, 0f);
            attachedPlayer.body.ApplyLinearImpulse(horizImpulse);

            carryingLastFrame = attachedPlayer.CarryingPickup();
        }
Пример #14
0
 private FVector2 GetConstantSpeed(FVector2 startPoint, FVector2 endPoint, float travelTime)
 {
     FVector2 distanceVector = endPoint - startPoint;
     FVector2 speedVector = new FVector2(distanceVector.X/travelTime, distanceVector.Y/travelTime);
     return speedVector;
 }
Пример #15
0
 public void Serialize(ref Microsoft.Xna.Framework.FVector2 data)
 {
     Serialize(ref data.X);
     Serialize(ref data.Y);
 }
Пример #16
0
 public void AddRelativeMovementEvent(FVector2 distanceVector, float traveltime, int interType = 0, float delay = 0.0f, bool guaranteeArrival = false)
 {
     SetupPhysics();
     FVector2 destination = new FVector2(body.Position.X + distanceVector.X, body.Position.Y + distanceVector.Y);
     AddMovementEvent(destination, traveltime, interType, delay, guaranteeArrival);
 }
Пример #17
0
 public static UnityEngine.Vector3 FVector2ToVector3(Microsoft.Xna.Framework.FVector2 input)
 {
     return(new UnityEngine.Vector3(input.X, input.Y, 0f));
 }