Exemplo n.º 1
0
 public void AddInstruction(EInstruction instruction, int position, bool user)
 {
     this.instructions.Insert(position, instruction);
     this.ui.AddInstruction(instruction, position, user);
     if (position < NextInstruction)
     {
         NextInstruction++;
     }
 }
Exemplo n.º 2
0
    private void Update()
    {
        if (!isTransitioning)
        {
            this.CurrentTimer += Time.deltaTime;
            if (CurrentTimer > timer)
            {
                if (!isAlive)
                {
                    this.ResetPlayer();
                }
                else
                {
                    EInstruction instruction = this.instructions[NextInstruction++];
                    this.CurrentTimer = 0;
                    this.StepCounter++;

                    switch (instruction)
                    {
                    case EInstruction.FWD:
                    case EInstruction.BWD: this.ExecuteMoveInstruction(instruction); break;

                    case EInstruction.Left:
                    case EInstruction.Right: this.ExecuteTurnInstruction(instruction); break;

                    case EInstruction.Kill: StartCoroutine(CreateParticle(explosion)); this.ResetPlayer(); break;
                    }
                }
            }
        }
        else
        {
            transitionTimer += Time.deltaTime * 10 / (nextTransitionPoint - lastTransitionPoint).magnitude;
            if (transform.position != nextTransitionPoint)
            {
                transform.position = Vector3.Lerp(lastTransitionPoint, nextTransitionPoint, transitionTimer);
            }
            else
            {
                transitionTimer = 0;
                if (currentPathIndex < levels[level].nextLevelPath.Length - 1)
                {
                    currentPathIndex++;
                    lastTransitionPoint = nextTransitionPoint;
                    nextTransitionPoint = levels[level].nextLevelPath[currentPathIndex].transform.position;
                }
                else
                {
                    this.Spawn(this.level + 1);
                    StartCoroutine(CreateParticle(despawn));
                    this.trail.SetActive(false);
                    this.sprite.SetActive(true);
                }
            }
        }
    }
Exemplo n.º 3
0
    public void AddItem(EInstruction item)
    {
        GameObject obj = Instruction.Create(item, transform);

        obj.AddComponent <CanvasGroup>();
        DragInstruction ins = obj.AddComponent <DragInstruction>();

        ins.instruction = item;
        items.Add(ins);
    }
Exemplo n.º 4
0
    public void AddInstruction(EInstruction instruction, int position, bool user)
    {
        GameObject obj = Instruction.Create(instruction, content);

        this.instructions.Insert(position, obj);
        obj.transform.SetSiblingIndex(position);
        (this.content.parent as RectTransform).sizeDelta = new Vector2(0, this.instructions.Count * height);
        if (user)
        {
            GameObject x = Instantiate(buttonX, obj.transform);
            x.GetComponent <DeleteInstruction>().index = position;
        }
    }
Exemplo n.º 5
0
 public static GameObject Create(EInstruction instruction, Transform parent)
 {
     if (prefabs[0] == null)
     {
         prefabs[0] = Resources.Load("Instruction/ButtonMove") as GameObject;
         prefabs[1] = Resources.Load("Instruction/ButtonBWD") as GameObject;
         prefabs[2] = Resources.Load("Instruction/ButtonLeft") as GameObject;
         prefabs[3] = Resources.Load("Instruction/ButtonRight") as GameObject;
         prefabs[4] = Resources.Load("Instruction/ButtonDash") as GameObject;
         prefabs[5] = Resources.Load("Instruction/ButtonKill") as GameObject;
     }
     return(Instantiate(prefabs[(int)instruction], parent));
 }
Exemplo n.º 6
0
    private void ExecuteMoveInstruction(EInstruction instruction)
    {
        bool down  = (facing == Facing.Down && instruction == EInstruction.FWD) || (facing == Facing.Up && instruction == EInstruction.BWD);
        bool left  = (facing == Facing.Left && instruction == EInstruction.FWD) || (facing == Facing.Right && instruction == EInstruction.BWD);
        bool right = (facing == Facing.Right && instruction == EInstruction.FWD) || (facing == Facing.Left && instruction == EInstruction.BWD);

        Vector2 dir = new Vector2(0.5f, -0.5f);

        if (down)
        {
            this.state = CurrentAnimation.MoveDown;
            dir       += new Vector2(0, -1);
        }
        else if (left)
        {
            this.state = CurrentAnimation.MoveLeft;
            dir       += new Vector2(-1, 0);
        }
        else if (right)
        {
            this.state = CurrentAnimation.MoveRight;
            dir       += new Vector2(1, 0);
        }
        else
        {
            this.state = CurrentAnimation.MoveUp;
            dir       += new Vector2(0, 1);
        }

        Collider2D collider = Physics2D.OverlapBox(new Vector2(transform.position.x, transform.position.y) + dir, new Vector2(0.8f, 0.8f), 0, LayerMask.GetMask("Walls"));

        if (collider == null)
        {
            if (instruction == EInstruction.FWD)
            {
                this.animator.SetTrigger("Move");
            }
            else
            {
                this.animator.SetTrigger("MoveBwd");
            }
        }
        else
        {
            this.animator.SetTrigger("TryMove");
            this.state = CurrentAnimation.None;
        }
    }
Exemplo n.º 7
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name == "HazardTile")
        {
            this.isAlive = false;
            StartCoroutine(CreateParticle(explosion));
            transform.position = initialPosition;
            NextInstruction    = 0;
            DeathCounter++;
            inventory.ResetItems();
            int childReset = 0;
            switch (initialFacing)
            {
            case Facing.Down: childReset = -90; break;

            case Facing.Right: childReset = 0; break;

            case Facing.Up: childReset = 90; break;

            case Facing.Left: childReset = 180; break;
            }
            child.eulerAngles = new Vector3(0, 0, childReset);
        }
        else if (collision.name.EndsWith("Pickup"))
        {
            EInstruction ins = EInstruction.Kill;
            switch (collision.name)
            {
            case "TurnLeftPickup": ins = EInstruction.Left; break;

            case "TurnRightPickup": ins = EInstruction.Right; break;

            case "DashPickup": ins = EInstruction.Dash; break;

            case "BackwardsPickup": ins = EInstruction.BWD; break;
            }
            Inventory.Add(ins);
            inventory.AddItem(ins);
            collision.transform.GetChild(0).gameObject.SetActive(false);
            collision.GetComponent <BoxCollider2D>().enabled = false;
        }
        else if (collision.name == "GoalTile")
        {
            this.victory.Activate(levels[level]);
        }
    }
Exemplo n.º 8
0
 private void ExecuteTurnInstruction(EInstruction instruction)
 {
     if (instruction == EInstruction.Left)
     {
         this.facing = (Facing)(((int)facing + 1) % 4);
         this.animator.SetTrigger("TurnLeft");
         this.state = CurrentAnimation.TurnLeft;
     }
     else
     {
         this.facing = (Facing)((int)facing - 1);
         if (this.facing < 0)
         {
             this.facing = Facing.Left;
         }
         this.animator.SetTrigger("TurnRight");
         this.state = CurrentAnimation.TurnRight;
     }
 }
Exemplo n.º 9
0
 public Instruction(EInstruction type)
     : base(false)
 {
     Type = type;
 }
Exemplo n.º 10
0
 public void AddInstruction(EInstruction instruction, int position)
 {
     this.AddInstruction(instruction, position, false);
 }
Exemplo n.º 11
0
 private OpCode GetOpCode(EInstruction type)
 {
     return((OpCode)(typeof(OpCodes).GetField(type.ToString(), BindingFlags.Static | BindingFlags.Public).GetValue(null)));
 }
Exemplo n.º 12
0
 private bool IsBranch(EInstruction inst)
 {
     return(inst >= EInstruction.Beq && inst <= EInstruction.BrTrue_S);
 }