示例#1
0
 public bool overlap(OneDBox box)
 {
     if (this.layer != box.layer)
     {
         return(false);
     }
     if (this.x > box.x)
     {
         //overlap right
         if (this.x < box.x + box.width)
         {
             return(true);
         }
         //overlap enveloped
         if (this.x + this.width < box.x + box.width)
         {
             return(true);
         }
         //too far right
         return(false);
     }
     //overlap left
     if (this.x + this.width > box.x)
     {
         return(true);
     }
     //overlap enveloping
     if (this.x + this.width > box.x + box.width)
     {
         return(true);
     }
     return(false);
 }
示例#2
0
 public float overlapAmount(OneDBox box)
 {
     if (this.x > box.x)
     {
         //overlap enveloped
         if (this.x + this.width < box.x + box.width)
         {
             if (this.width < box.width) { return this.width; }
             else { return box.width; }
         }
         //overlap right
         if (this.x < box.x + box.width)
         {
             return box.x + box.width - this.x;
         }
         //too far right
         return 0;
     }
     //overlap enveloping
     if (this.x + this.width > box.x + box.width)
     {
         if (this.width < box.width) { return this.width; }
         else { return box.width; }
     }
     //overlap left
     if (this.x + this.width > box.x)
     {
         return this.x + this.width - box.x;
     }
     return 0;
 }
示例#3
0
	// Use this for initialization
	void Start () {
        maxHitpoints = baseHitpoints;
        box = new OneDBox(transform.position.x - width / 2, width, 0);
        float spriteWidth = GetComponent<SpriteRenderer>().sprite.rect.width;

        if (direction == 1)
        {
            labBox = new OneDBox(box.x, labWidth, 0);
        }
        else
        {
            labBox = new OneDBox(box.x + box.width - labWidth, labWidth, 0);
        }
        hitpoints = maxHitpoints;
        if (direction == 1)
        {
            doorBox = new OneDBox(box.x + width - doorXPos - doorWidth, doorWidth, 0);
        }
        else
        {
            doorBox = new OneDBox(box.x + doorXPos, doorWidth, 0);
        }

        floorBox = new OneDBox(box.x + box.width/2 + floorXOffset * direction - floorWidth/2, floorWidth, 0);
	}
示例#4
0
 public bool overlap (OneDBox box) {
     if (this.layer != box.layer)
     {
         return false;
     }
     if (this.x > box.x) {
         //overlap right
         if (this.x < box.x + box.width) {
             return true;
         }
         //overlap enveloped
         if (this.x + this.width < box.x + box.width) {
             return true;
         }
         //too far right
         return false;
     }
     //overlap left
     if (this.x + this.width > box.x) {
         return true;
     }
     //overlap enveloping
     if (this.x + this.width > box.x + box.width) {
         return true;
     }
     return false;
 }
示例#5
0
    // Use this for initialization
    void Start()
    {
        maxHitpoints = baseHitpoints;
        box          = new OneDBox(transform.position.x - width / 2, width, 0);
        float spriteWidth = GetComponent <SpriteRenderer>().sprite.rect.width;

        if (direction == 1)
        {
            labBox = new OneDBox(box.x, labWidth, 0);
        }
        else
        {
            labBox = new OneDBox(box.x + box.width - labWidth, labWidth, 0);
        }
        hitpoints = maxHitpoints;
        if (direction == 1)
        {
            doorBox = new OneDBox(box.x + width - doorXPos - doorWidth, doorWidth, 0);
        }
        else
        {
            doorBox = new OneDBox(box.x + doorXPos, doorWidth, 0);
        }

        floorBox = new OneDBox(box.x + box.width / 2 + floorXOffset * direction - floorWidth / 2, floorWidth, 0);
    }
示例#6
0
	// Use this for initialization
	public override void UnityStart () {
        //for fun
        walkSpeed = walkSpeed * (1 + walkSpeedRandomness * (Random.value - 0.5f));
        xScale += Random.value * xScaleRandomness;
        width = width * xScale;
        height = height * xScale;

        //set collision box
        box = new OneDBox(transform.position.x - (width / 2), width, 0); 

        animator = GetComponent<Animator>();
	}
示例#7
0
    // Use this for initialization
    public override void UnityStart()
    {
        //for fun
        walkSpeed = walkSpeed * (1 + walkSpeedRandomness * (Random.value - 0.5f));
        xScale   += Random.value * xScaleRandomness;
        width     = width * xScale;
        height    = height * xScale;

        //set collision box
        box = new OneDBox(transform.position.x - (width / 2), width, 0);

        animator = GetComponent <Animator>();
    }
    // Use this for initialization
    void Start () {
        box = new OneDBox(transform.position.x - (width / 2), width, 0); 
        animator = GetComponent<Animator>();

        pickupSource = gameObject.AddComponent<AudioSource>();
        pickupSource.clip = pickupClip;
        pickupSource.playOnAwake = false;
        pickupSource.loop = false;

        putdownSource = gameObject.AddComponent<AudioSource>();
        putdownSource.clip = putdownClip;
        putdownSource.playOnAwake = false;
        putdownSource.loop = false;
    }
    // Use this for initialization
    void Start()
    {
        box      = new OneDBox(transform.position.x - (width / 2), width, 0);
        animator = GetComponent <Animator>();

        pickupSource             = gameObject.AddComponent <AudioSource>();
        pickupSource.clip        = pickupClip;
        pickupSource.playOnAwake = false;
        pickupSource.loop        = false;

        putdownSource             = gameObject.AddComponent <AudioSource>();
        putdownSource.clip        = putdownClip;
        putdownSource.playOnAwake = false;
        putdownSource.loop        = false;
    }
示例#10
0
 public int requestStairs(int level, OneDBox igorBox)
 {
     if (!igorBox.overlap(doorBox))
     {
         return(-1);
     }
     if (level > floors)
     {
         return(floors);
     }
     if (level <= 0)
     {
         return(0);
     }
     return(level);
 }
示例#11
0
 public bool IsValidMove (Team t, OneDBox b) {
     b.FixedUpdate();
     float width = background.GetComponent<SpriteRenderer>().sprite.rect.width;
     float center = background.GetComponent<Transform>().position.x;
     if ( b.x > center + width / 2 || b.x < -1 * (center + width / 2) )
     {
         return false;
     }
     else if (t.Equals(right))
     {
         return !left.fort.box.overlap(b);
     }
     else
     {
         return !right.fort.box.overlap(b);
     }
 }
示例#12
0
 public float overlapAmount(OneDBox box)
 {
     if (this.x > box.x)
     {
         //overlap enveloped
         if (this.x + this.width < box.x + box.width)
         {
             if (this.width < box.width)
             {
                 return(this.width);
             }
             else
             {
                 return(box.width);
             }
         }
         //overlap right
         if (this.x < box.x + box.width)
         {
             return(box.x + box.width - this.x);
         }
         //too far right
         return(0);
     }
     //overlap enveloping
     if (this.x + this.width > box.x + box.width)
     {
         if (this.width < box.width)
         {
             return(this.width);
         }
         else
         {
             return(box.width);
         }
     }
     //overlap left
     if (this.x + this.width > box.x)
     {
         return(this.x + this.width - box.x);
     }
     return(0);
 }
示例#13
0
    public bool IsValidMove(Team t, OneDBox b)
    {
        b.FixedUpdate();
        float width  = background.GetComponent <SpriteRenderer>().sprite.rect.width;
        float center = background.GetComponent <Transform>().position.x;

        if (b.x > center + width / 2 || b.x < -1 * (center + width / 2))
        {
            return(false);
        }
        else if (t.Equals(right))
        {
            return(!left.fort.box.overlap(b));
        }
        else
        {
            return(!right.fort.box.overlap(b));
        }
    }
示例#14
0
 // Use this for initialization
 void Start()
 {
     box = new OneDBox(transform.position.x - (width / 2), width, 0);
 }
    // Update is called once per frame
    void Update()
    {
        //update timers
        animationTimer -= Time.deltaTime;
        if (animationTimer < 0)
        {
            animationTimer = 0;

            //stairs animation switching
            SpriteRenderer sprender = GetComponent <SpriteRenderer>();
            if (isExitingStairs)
            {
                animator.SetBool("isExitingStairs", false);
            }
            if (isInStairwell)
            {
                animationTimer   = stairsAnimateDuration;
                sprender.enabled = true;
                isInStairwell    = false;
                isExitingStairs  = true;
                animator.SetBool("isEnteringStairs", false);
                animator.SetBool("isExitingStairs", true);
                transform.position = new Vector3(transform.position.x, team.fort.getFloorHeight(floorPos), transform.position.z);
                if (heldResource != null)
                {
                    heldResource.GetComponent <SpriteRenderer>().enabled = true;
                    heldResource.level = floorPos;
                    heldResource.setY(transform.position.y);
                }
            }
            if (isEnteringStairs)
            {
                animationTimer   = stairsInsideDuration;
                isInStairwell    = true;
                isEnteringStairs = false;
                sprender.enabled = false;
                if (heldResource != null)
                {
                    heldResource.GetComponent <SpriteRenderer>().enabled = false;
                }
            }
        }

        //check pick-up and put-down
        if (Input.GetAxis(digButton) > 0 && animationTimer == 0)
        {
            if (heldResource == null)
            {
                //lift item
                if (game.RemoveResource(this))
                {
                    pickupSource.Play();
                    animationTimer       = pickUpDuration;
                    isLiftingNotDropping = true;
                    animator.SetBool("isLifting", true); //do you even lift bro?
                }
            }
            else
            {
                //drop item
                putdownSource.Play();
                heldResource.Drop();
                game.AddResource(heldResource);
                heldResource         = null;
                animationTimer       = putDownDuration;
                isLiftingNotDropping = false;
                animator.SetBool("isLifting", false);
            }
        }

        //check going up/down stairs
        if (Input.GetAxis(stairsAxis) != 0 && animationTimer == 0 && team.fort.requestStairs(floorPos, box) != -1)
        {
            //go up or down
            if (Input.GetAxis(stairsAxis) > 0)
            {
                floorPos = team.fort.requestStairs(floorPos + 1, box);
            }
            else
            {
                floorPos = team.fort.requestStairs(floorPos - 1, box);
            }
            //set animation/position
            animationTimer   = stairsAnimateDuration;
            isEnteringStairs = true;
            animator.SetBool("isEnteringStairs", true);
            box.x = team.fort.doorBox.x + 3;
        }

        //check walk if we're not animating
        if (animationTimer == 0)
        {
            animator.SetBool("isLifting", false);
            //input
            float walkDir = Input.GetAxis(walkAxis);
            //physics
            OneDBox next = new OneDBox(box.x, box.width, walkDir * walkSpeed);
            if (game.IsValidMove(team, next) && (floorPos == 0 || next.overlapAmount(team.fort.floorBox) == next.width))
            {
                box.velocity = next.velocity;
            }
            else
            {
                box.velocity = 0;
            }
            //animation
            if (walkDir != 0)
            {
                animator.SetBool("isWalking", true);
                if (walkDir < 0)
                {
                    transform.localScale = new Vector3(1, 1, 1);
                }
                else if (walkDir > 0)
                {
                    transform.localScale = new Vector3(-1, 1, 1);
                }
            }
            else
            {
                animator.SetBool("isWalking", false);
            }
        }
        else
        {
            box.velocity = 0;
            animator.SetBool("isWalking", false);
        }

        //final animator information
        animator.SetFloat("animTimer", animationTimer);
        animator.SetBool("isHolding", heldResource != null);
    }
示例#16
0
 public int requestStairs(int level, OneDBox igorBox)
 {
     if (!igorBox.overlap(doorBox))
     {
         return -1;
     }
     if (level > floors)
     {
         return floors;
     }
     if (level <= 0)
     {
         return 0;
     }
     return level;
 }
    // Update is called once per frame
    void Update () {
        //update timers
        animationTimer -= Time.deltaTime;
        if (animationTimer < 0)
        {
            animationTimer = 0;

            //stairs animation switching
            SpriteRenderer sprender = GetComponent<SpriteRenderer>();
            if (isExitingStairs)
            {
                animator.SetBool("isExitingStairs", false);
            }
            if (isInStairwell)
            {
                animationTimer = stairsAnimateDuration;
                sprender.enabled = true;
                isInStairwell = false;
                isExitingStairs = true;
                animator.SetBool("isEnteringStairs", false);
                animator.SetBool("isExitingStairs", true);
                transform.position = new Vector3(transform.position.x, team.fort.getFloorHeight(floorPos), transform.position.z);
                if(heldResource != null){
                    heldResource.GetComponent<SpriteRenderer>().enabled = true;
                    heldResource.level = floorPos;
                    heldResource.setY(transform.position.y);
                }
            }
            if (isEnteringStairs)
            {
                animationTimer = stairsInsideDuration;
                isInStairwell = true;
                isEnteringStairs = false;
                sprender.enabled = false;
                if (heldResource != null)
                {
                    heldResource.GetComponent<SpriteRenderer>().enabled = false;
                }
            }
        }

        //check pick-up and put-down
        if (Input.GetAxis(digButton) > 0 && animationTimer == 0)
        {
            if (heldResource == null) {
                //lift item
                if (game.RemoveResource(this))
                {
                    pickupSource.Play();
                    animationTimer = pickUpDuration;
                    isLiftingNotDropping = true;
                    animator.SetBool("isLifting", true); //do you even lift bro?
                }
            }
            else
            {
                //drop item
                putdownSource.Play();
                heldResource.Drop();
                game.AddResource(heldResource);
                heldResource = null;
                animationTimer = putDownDuration;
                isLiftingNotDropping = false;
                animator.SetBool("isLifting", false);
            }
        }

        //check going up/down stairs
        if (Input.GetAxis(stairsAxis) != 0 && animationTimer == 0 && team.fort.requestStairs(floorPos, box) != -1)
        {
            //go up or down
            if (Input.GetAxis(stairsAxis) > 0)
            {
                floorPos = team.fort.requestStairs(floorPos + 1, box);
            }
            else
            {
                floorPos = team.fort.requestStairs(floorPos - 1, box);
            }
            //set animation/position
            animationTimer = stairsAnimateDuration;
            isEnteringStairs = true;
            animator.SetBool("isEnteringStairs", true);
            box.x = team.fort.doorBox.x + 3;
        }

        //check walk if we're not animating
        if (animationTimer == 0)
        {
            animator.SetBool("isLifting", false);
            //input
            float walkDir = Input.GetAxis(walkAxis);
            //physics
            OneDBox next = new OneDBox(box.x, box.width, walkDir * walkSpeed);
            if (game.IsValidMove(team,next) && (floorPos == 0 || next.overlapAmount(team.fort.floorBox) == next.width))
            {
                box.velocity = next.velocity;
            }
            else
            {
                box.velocity = 0;
            }
            //animation
            if (walkDir != 0)
            {
                animator.SetBool("isWalking", true);
                if (walkDir < 0)
                {
                    transform.localScale = new Vector3(1, 1, 1);
                } else if (walkDir > 0)
                {
                    transform.localScale = new Vector3(-1, 1, 1);
                }
            } else
            {
                animator.SetBool("isWalking", false);
            }
        }
        else
        {
            box.velocity = 0;
            animator.SetBool("isWalking", false);
        }

        //final animator information
        animator.SetFloat("animTimer", animationTimer);
        animator.SetBool("isHolding", heldResource != null);
    }
 // Use this for initialization
 void Start()
 {
     box      = new OneDBox(transform.position.x - (width / 2), width, 0);
     mobQueue = new Queue <Resource>();
 }
	// Use this for initialization
	void Start () {
        box = new OneDBox(transform.position.x - (width / 2), width, 0);
        mobQueue = new Queue<Resource>();
	}
示例#20
0
	// Use this for initialization
	void Start () {
        box = new OneDBox(transform.position.x - (width / 2), width, 0);
	}