Пример #1
0
    private void FixedUpdate()
    {
        switch (state)
        {
        case pickup_state.carrying_object:
            if (was_pickup_pressed)
            {
                drop_object();
            }
            break;

        case pickup_state.constraining_object:
            //Transfering object to another grid.
            MatchThreeObject m3_object = carried_item.GetComponent <MatchThreeObject>();
            if (m3_object.grid != placement_grid)
            {
                m3_object.RemoveMyself();
                m3_object.grid = placement_grid;
                //m3_object.match3_grid = structure;
                m3_object.AddMyself(true);
                m3_object.transform.SetParent(placement_grid.transform);
            }
            item_rigidbody             = carried_item.GetComponent <Rigidbody>();
            item_rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
            state        = pickup_state.no_object_targeted;
            carried_item = null;
            break;
        }
    }
Пример #2
0
 public matchThreeObjectInfo(MatchThreeObject obj)
 {
     name     = obj.name;
     type     = obj.match3Type;
     group    = (int)obj.match3_group_id;
     position = new vector3S(obj.transform.position);
     room     = obj.grid.name;
 }
Пример #3
0
    public static void readSave(Save save)
    {
        //Clear existing objects
        ClearMatchThreeObjects();
        ClearAmmoObjects();
        DestroyCharacter();
        //Create Player
        playerInfo playerInfo = save.player;

        player = Instantiate(CharacterObject).GetComponent <MyCharacterController>();
        player.transform.position = playerInfo.position.GetPosition();
        Vector3 orientation = playerInfo.orientation.GetOrientation();

        player.my_camera.GetComponent <camMouseLook>().Look(orientation);
        player.SetCrouchState(playerInfo.crouched, true);
        player.health = playerInfo.health;
        GunController gunController = player.my_pickup.gunController;

        for (int i = 0; i < playerInfo.ammo.Length; ++i)
        {
            gunController.arsenal[i].gun.ammo      = playerInfo.ammo[i];
            gunController.arsenal[i].is_in_arsenal = playerInfo.inArse[i];
        }
        gunController.equip_gun((GunController.gun_type)playerInfo.equip);
        //Create Match Threes
        foreach (matchThreeObjectInfo obj in save.matchThreeObjectInfos)
        {
            GameObject       newObj   = Instantiate(matchThreeObjectTypes.types[obj.type], GameObject.Find(obj.room).transform);
            MatchThreeObject newObjM3 = newObj.GetComponent <MatchThreeObject>();
            newObj.name = obj.name;
            newObj.transform.position = obj.position.GetPosition();
            newObjM3.match3_group_id  = (MatchThreeObject.match3_group_id_names)obj.group;
            newObjM3.apply_color();
        }
        //Create Ammo Pickups
        foreach (ammoInfo obj in save.ammoInfos)
        {
            GameObject            newObj     = Instantiate(AmmoObject);
            PickupAmmoInteraction newObjAmmo = newObj.GetComponent <PickupAmmoInteraction>();
            newObj.name = obj.name;
            newObj.transform.position    = obj.position.GetPosition();
            newObj.transform.eulerAngles = obj.rotation.GetOrientation();
            newObjAmmo.gun    = (GunController.gun_type)obj.type;
            newObjAmmo.amount = obj.amount;
        }
        //Set Door Parameters
        foreach (doorInfo obj in save.doorInfos)
        {
            DoorInteraction door = GameObject.Find(obj.name).GetComponentInChildren <DoorInteraction>();
            door.twistLock(obj.locked);
            door.swingDoor(obj.open, false);
        }
        //Temporary code for setting references
        foreach (GameObject tutorial in tutorials)
        {
            tutorial.GetComponent <Tutorial>().GetUIComponents(player.gameObject);
        }
    }
    public int GetStackWeight()
    {
        MatchThreeObject neighbor = match3_grid?.Get(coord[0] + Vector3Int.up)?[0]?.GetComponent <MatchThreeObject>();

        if (neighbor != null)
        {
            return(weight + neighbor.GetStackWeight());
        }
        else
        {
            return(weight);
        }
    }
    //Returns a list of matching neighbors
    public List <MatchThreeObject> GetMatchingNeighbors()
    {
        List <MatchThreeObject> matching_neigbors = new List <MatchThreeObject>();

        is_being_checked = true;
        for (int i = 0; i < coord.Length; ++i)
        {
            for (int j = 0; j < neighbor_local_coords.Length; ++j)
            {
                //Iterate through all neighbors
                if (was_neighbor_checked[j] == true)
                {
                    //Skip this neighbor (because this neighbor made the recursive call)
                    continue;
                }
                //Get neighbor from match3_grid
                GameObject[] neighbor_game_objects = match3_grid.Get(coord[i] + neighbor_local_coords[j]);

                if (neighbor_game_objects != null)
                {
                    for (int k = 0; k < neighbor_game_objects.Length; ++k)
                    {
                        //Neighbor exists
                        MatchThreeObject neighbor = neighbor_game_objects[k].GetComponent <MatchThreeObject>();
                        if (!neighbor.is_being_checked && neighbor.match3_group_id == match3_group_id)
                        {
                            //Neighbor is of the same group
                            //Check if neighbor is close enough
                            if (Vector3.Distance(neighbor.transform.position + center_local_transform, transform.position + center_local_transform) < 1.3f)
                            {
                                neighbor.was_neighbor_checked[neighbor_local_coords.Length - (j + 1)] = true;
                                was_neighbor_checked[j] = true;
                                neighbor.GetMatchingNeighborsHelper(matching_neigbors);
                            }
                        }
                    }
                }
            }
        }
        matching_neigbors.Add(this);
        foreach (MatchThreeObject obj in matching_neigbors)
        {
            obj.ResetChecked();
        }

        return(matching_neigbors);
    }
Пример #6
0
    public override void fire1(Ray ray)
    {
        RaycastHit hit_info;
        bool       object_found = Physics.Raycast(ray, out hit_info, float.MaxValue, LayerMask.GetMask("Default", "InteractSolid"));

        if (object_found && hit_info.transform.tag == "Interactable")
        {
            MatchThreeObject matchThreeObject = hit_info.transform.gameObject.GetComponent <MatchThreeObject>();
            string           message          = "Coords: \n";
            for (int i = 0; i < matchThreeObject.coord.Length; ++i)
            {
                message += matchThreeObject.coord[i];
                message += "\n";
            }
            Debug.Log(message);
        }
    }
Пример #7
0
    private void OnCollisionEnter(Collision collision)
    {
        number_of_adjacent_colliders += 1;
        if (number_of_adjacent_colliders > 1)
        {
            my_rigidbody.useGravity = false;
            //Debug.Log("Fake gravity engaged");
        }
        float point = collision.GetContact(0).point.y;

        //Fall damage
        if (point < transform.position.y - 0.9f)
        {
            float   impact    = (highestY - transform.position.y);
            float[] threshold = new float[5]
            {
                0.5f,
                1.5f,
                6.5f,
                9.5f,
                18f,
            };
            if (impact > threshold[0])
            {
                Debug.Log(impact);
            }

            if (threshold[0] <= impact && impact < threshold[1])
            {
                Debug.Log("Soft Landing");
            }
            else if (threshold[1] <= impact && impact < threshold[2])
            {
                Debug.Log("Medium Landing");
            }
            else if (threshold[2] <= impact && impact < threshold[3])
            {
                //Hard land sound
                Debug.Log("Hard Landing");
                int damage = (int)((impact - threshold[2]) / (threshold[3] - threshold[2]) * 10);
                Debug.Log("Damage Dealt: " + damage);
                dealDamage(damage);
            }
            else if (threshold[3] <= impact && impact < threshold[4])
            {
                Debug.Log("Really Hard Landing");
                int damage = (int)((impact - threshold[2]) / (threshold[3] - threshold[2]) * 10);
                Debug.Log("Damage Dealt: " + damage);
                dealDamage(damage);
            }
            else if (threshold[4] <= impact)
            {
                Debug.Log("Fatal Landing");
                killCharacter();
            }
            highestY = transform.position.y;
        }
        else if (point > (transform.position.y + 0.8f))
        {
            MatchThreeObject obj = collision.gameObject.GetComponent <MatchThreeObject>();
            if (obj != null)
            {
                //Possibly Crushed
                int weight = obj.GetStackWeight();
                Debug.Log(weight);
                int[] threshold = new int[3]
                {
                    1,
                    2,
                    3,
                };
                if (threshold[0] <= weight && weight < threshold[1])
                {
                    Debug.Log("Small Crush");
                    dealDamage(10);
                }
                else if (threshold[1] <= weight && weight < threshold[2])
                {
                    Debug.Log("Medium Crush");
                    dealDamage(15);
                }
                else if (threshold[2] <= weight)
                {
                    Debug.Log("Crushed");
                    killCharacter();
                }
            }
        }
    }