示例#1
0
        public void TryUi32Test1()
        {
            uint      test   = 0x12345678;
            MemoryObj memory = new MemoryObj(8);

            // 例外が起きず失敗できるか
            Assert.IsFalse(memory.TrySetUi32(10, 0), "設定できないのに,設定できてます");
            Assert.IsFalse(memory.TryGetUi32(10, out uint _), "取得できないのに,取得できてます");

            // 成功するか
            Assert.IsTrue(memory.TrySetUi32(0, 0), "設定できるのに,設定できてません");
            Assert.IsTrue(memory.TryGetUi32(0, out uint _), "取得できるのに,取得できてません");

            // 設定,取得できるか
            memory = new MemoryObj(8);
            uint result;

            if (!memory.TrySetUi32(0, test))
            {
                Assert.Fail("設定に失敗しました");
            }
            if (!memory.TryGetUi32(0, out result))
            {
                Assert.Fail("取得に失敗しました");
            }
            Assert.AreEqual(
                test,
                result,
                "取得はできたが,取得内容に差異があります");
        }
示例#2
0
        private void SetFromVmStatus(VmStatus status)
        {
            IsEnd  = status.isEnd;
            IsZero = status.isZero;
            IsSign = status.isSign;

            _memory    = new MemoryObj(status.memory);
            _registers = new Register[status.registers.Length];
            Array.Copy(status.registers, _registers, status.registers.Length);
        }
示例#3
0
 public void CollectItem(MemoryObj itemFound)
 {
     SoundManager.instance.playCollect();
     itemsRemaining--;
     foreach (ObjTemplate ob in objects)
     {
         if (ob.memoryObject == itemFound)
         {
             ob.found = true;
             PlayerPrefs.SetInt(ob.name, 1);
         }
     }
     if (itemsRemaining <= 0)
     {
         GameOver();
     }
 }
示例#4
0
    // Start is called before the first frame update
    void Start()
    {
        target = God.instance.GetClosestObject().position;

        if (target == null)
        {
            Destroy(gameObject);
            God.instance.ghostDestroyed();
            followingTarget = false;
        }
        else
        {
            followingTarget = true;
            followingPlayer = false;
            obj             = target.gameObject.GetComponent <MemoryObj>();
            obj.hasGhost    = true;
        }
    }
示例#5
0
        public void Init(BytecodeStream code, object instance = null)
        {
            _code   = code;
            _memory = new MemoryObj(MEM_SIZE);
            _errors.Clear();

            _registers = new Register[REG_SIZE];
            for (int i = 0; i < REG_SIZE; ++i)
            {
                _registers[i] = new Register();
            }
            _registers[BASE_PTR][0]  = MEM_SIZE;
            _registers[STACK_PTR][0] = MEM_SIZE;

            _instance = instance;
            _methods.Clear();
            RegisterBuildMethods();
        }
示例#6
0
 public void DestroyItem(MemoryObj itemDestroyed)
 {
     SoundManager.instance.playItemLost();
     itemsRemaining--;
     foreach (ObjTemplate ob in objects)
     {
         if (ob.memoryObject == itemDestroyed)
         {
             ob.destroyed     = false;
             ob.UIImage.color = Color.black;
             PlayerPrefs.SetFloat(ob.name, 0);
         }
     }
     if (itemsRemaining <= 0)
     {
         GameOver();
     }
 }
示例#7
0
    void ToggleFollowing()
    {
        followingTarget = !followingTarget;
        if (followingTarget)
        {
            transform.parent = God.instance.transform;
            God.instance.player.GetComponent <Player>().carryingGhost = false;
            col.enabled     = true;
            followingPlayer = false;

            obj.hasGhost = false;
            target       = God.instance.GetClosestObject().position;
            obj          = target.gameObject.GetComponent <MemoryObj>();
            obj.hasGhost = true;
        }
        else
        {
            transform.parent = God.instance.player;
            position         = transform.localPosition;
            God.instance.player.GetComponent <Player>().carryingGhost = true;
            col.enabled     = false;
            followingPlayer = true;
        }
    }
示例#8
0
    // Update is called once per frame
    void Update()
    {
        if (Vector2.Distance(transform.position, God.instance.player.position) < range && Input.GetKeyDown(KeyCode.Space))
        {
            ToggleFollowing();
            Vector3 dir = target.position - transform.position;
            float   distanceThisFrame = 10;

            if (dir.magnitude <= distanceThisFrame)
            {
                //hitTarget();
            }
        }
        else if (Vector2.Distance(transform.position, God.instance.player.position) < blowRange && Input.GetMouseButtonDown(0))
        {
            SoundManager.instance.playHit();

            Vector3 dir = target.position - transform.position;
            God.instance.player.GetComponent <Player>().playBlow(transform.position - dir);
            transform.Translate(-dir.normalized * kickBack, Space.World);
        }
        if (followingTarget)
        {
            {
                if (target == null)
                {
                    if (God.instance.GetClosestObject() == null)
                    {
                        followingTarget = false;
                        Destroy(gameObject);
                        God.instance.ghostDestroyed();
                    }
                    else
                    {
                        target = God.instance.GetClosestObject().position;

                        float dist = Vector3.Distance(transform.position, target.position);
                        if (dist > maxDistance)
                        {
                            Debug.Log("Distance Too great");
                            followingTarget = false;
                            Destroy(gameObject);
                            God.instance.ghostDestroyed();
                        }
                        else
                        {
                            obj          = God.instance.GetClosestObject().memoryObject;
                            obj.hasGhost = true;
                        }
                    }
                }
                else
                {
                    Vector3 dir = target.position - transform.position;
                    float   distanceThisFrame = speed * Time.deltaTime;

                    line.enabled = true;
                    line.SetPosition(0, transform.position);
                    line.SetPosition(1, target.position);
                    if (dir.magnitude <= distanceThisFrame)
                    {
                        hitTarget();
                    }
                    else
                    {
                        transform.Translate(dir.normalized * distanceThisFrame, Space.World);
                    }
                }
            }
        }
        else
        {
            line.enabled            = false;
            transform.localPosition = position;
        }
    }