Esempio n. 1
0
    override protected void Update()
    {
        base.Update();

        if (!alreadyhit)
        {
            Vector3 testposition = transform.position + new Vector3(0.5f, 0.5f, 0.5f);
            bool    IsHit        = World._instance.BlockCollision(testposition);

            if (IsHit)
            {
                alreadyhit = true;
                Vector3 newpos = new Vector3(Mathf.FloorToInt(testposition.x), Mathf.FloorToInt(testposition.y), Mathf.FloorToInt(testposition.z));
                for (int x = -explosionsize; x <= explosionsize; ++x)
                {
                    for (int y = -explosionsize; y <= explosionsize; ++y)
                    {
                        for (int z = -explosionsize; z <= explosionsize; ++z)
                        {
                            Vector3 deltapos = new Vector3(x, y, z);
                            if (deltapos.magnitude < explosionsize + 0.5f)
                            {
                                Vector3 DeleteBlockPos = newpos + deltapos;
                                MathHelper.AddBlock(DeleteBlockPos, Block.Air);
                            }
                        }
                    }
                }
                Instantiate <Transform>(Resources.Load <Transform>("SMGExplosion"), transform.position, Quaternion.identity);
                IsDead = true;
            }
        }
        transform.position += transform.forward.normalized * (velocity / 100);
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            Add.transform.GetComponent <MeshRenderer>().enabled = true;

            Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 30))
            {
                Vector3 rawposition     = hit.point + hit.normal.Cap() - new Vector3(0.005f, 0.005f, 0.005f);
                Vector3 roundedposition = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                Add.transform.position = roundedposition;
                MathHelper.AddBlock(roundedposition, Block.Stone);
            }
        }
        else
        {
            if (Add.transform.GetComponent <MeshRenderer>().enabled == true)
            {
            }
            Add.transform.GetComponent <MeshRenderer>().enabled = false;
        }
        if (Input.GetMouseButtonUp(1))
        {
            Delete.transform.GetComponent <MeshRenderer>().enabled = true;

            Ray        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 30))
            {
                Vector3 rawposition     = hit.point - hit.normal.Cap() + new Vector3(0.005f, 0.005f, 0.005f);
                Vector3 roundedposition = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                Delete.transform.position = roundedposition;
                MathHelper.AddBlock(roundedposition, Block.Air);
            }
        }
        else
        {
            if (Delete.transform.GetComponent <MeshRenderer>().enabled == true)
            {
            }
            Delete.transform.GetComponent <MeshRenderer>().enabled = false;
        }
    }
Esempio n. 3
0
    override protected void Update()
    {
        base.Update();
        if (!alreadyhit)
        {
            Vector3 testposition = transform.position + new Vector3(0.5f, 0.5f, 0.5f);
            bool    IsHit        = World._instance.BlockCollision(testposition);

            if (IsHit)
            {
                alreadyhit = true;
                Vector3 newpos = new Vector3(Mathf.FloorToInt(testposition.x), Mathf.FloorToInt(testposition.y), Mathf.FloorToInt(testposition.z));
                for (int x = -explosionsize; x <= explosionsize; ++x)
                {
                    for (int y = -explosionsize; y <= explosionsize; ++y)
                    {
                        for (int z = -explosionsize; z <= explosionsize; ++z)
                        {
                            Vector3 deltapos = new Vector3(x, y, z);
                            if (deltapos.magnitude < explosionsize + 0.5f)
                            {
                                Vector3 DeleteBlockPos = newpos + deltapos;
                                MathHelper.AddBlock(DeleteBlockPos, Block.Air);
                            }
                        }
                    }
                }
                Instantiate <Transform>(Resources.Load <Transform>("FireballExplosion"), transform.position, Quaternion.identity);
                Destroy(gameObject);
            }
        }
        if (!DoneRotating)
        {
            fallingacceleration *= 1 + 1.2f * Time.deltaTime;
            transform.Rotate(new Vector3(-fallingacceleration, 0, 0));

            if (transform.rotation.eulerAngles.x > 80 && transform.rotation.eulerAngles.x < 100)
            {
                DoneRotating = true;
            }
        }
        transform.position += transform.forward.normalized * (velocity / 100);
    }
Esempio n. 4
0
    //private List<Vector3> WaitingToAddBlocks = new List<Vector3>();
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();
        if (changing)
        {
            changing = false;
            return;
        }
        //Releasing left click
        //Places block at position
        if (Input.GetMouseButtonUp(0))
        {
            Add.transform.GetComponent <MeshRenderer>().enabled = false;

            Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 rawposition     = hit.point + hit.normal / 2;
                Vector3 roundedpostiion = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                MathHelper.AddBlock(roundedpostiion, BlockType);
            }
        }
        //Holding left click
        //Shows Add block on screen
        else if (Input.GetMouseButton(0))
        {
            Add.transform.GetComponent <MeshRenderer>().enabled = true;

            Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 rawposition     = hit.point + hit.normal / 2;
                Vector3 roundedpostiion = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                Add.transform.position = roundedpostiion;
            }
        }
        //not holding left click

        //Releasing right click
        //Deletes block at position
        if (Input.GetMouseButtonUp(1))
        {
            Delete.transform.GetComponent <MeshRenderer>().enabled = false;


            Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 rawposition     = hit.point - hit.normal / 2;
                Vector3 roundedpostiion = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                MathHelper.AddBlock(roundedpostiion, Block.Air);
            }
        }
        //Holding right click
        //Shows delete on screen
        else if (Input.GetMouseButton(1))
        {
            Delete.transform.GetComponent <MeshRenderer>().enabled = true;


            Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 rawposition     = hit.point - hit.normal / 2;
                Vector3 roundedpostiion = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                Delete.transform.position = roundedpostiion;
            }
        }
        //not holding right click
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            BlockType = Block.White;
        }

        //Change block
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            BlockType = Block.Gray;
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            BlockType = Block.Black;
        }
    }
Esempio n. 5
0
    void BreakingAndPlacing()
    {
        if (GameManager._Instance.StateOfTheGame != GameManager.GameState.ININVENTORY)
        {
            if (GameManager._Instance.ModeOfTheGame == GameManager.GameMode.CREATIVE)
            {
                if (LeftMousePressed)
                {
                    if (CanRemoveABlock)
                    {
                        MathHelper.AddBlock(Int3.ToVector3(HitPoint), BlockRegistry.GetBlockFromBlockName("Air"));
                        CanRemoveABlock = false;
                    }
                }

                if (RightMousePressed)
                {
                    if (CanPlaceABlock)
                    {
                        int bID = PStatus.ToolBox9[PStatus.CurrentItem].BlockID;
                        if (bID != 0 && !(BlockRegistry.GetBlockFromID(bID).GetType().Equals(typeof(Tools)) || BlockRegistry.GetBlockFromID(bID).GetType().Equals(typeof(SpecialBlocks))))
                        {
                            Vector3 NewBlockPos = Int3.ToVector3(HitPoint) + HitNormal;
                            if (NewBlockPos != BlockIOPosition && NewBlockPos != BlockIOPosition + new Vector3(0f, 1f, 0f))
                            {
                                MathHelper.AddBlock(NewBlockPos, BlockRegistry.GetBlockFromID(bID), GetFacingDirection(), false, true);
                                CanPlaceABlock = false;
                            }
                        }
                    }
                }
            }
            else
            {
                if (LeftMousePressed)
                {
                    if (!HitBlockChanged)
                    {
                        breakingTimeLeft += GameTime.deltaTime;
                        Block destBlock = MathHelper.GetBlockAtPosition(Int3.ToVector3(HitPoint));
                        float lt        = BlockRegistry._RegisteredBlocks[PStatus.GetBlockIdFromToolbar()].GetBreakingTime(destBlock, PStatus.ToolBox9[PStatus.CurrentItem].Level);

                        PStatus.UpdateBreakingProgress(true, breakingTimeLeft / lt);

                        if (breakingTimeLeft >= lt)
                        {
                            breakingTimeLeft = 0f;
                            MathHelper.AddBlock(Int3.ToVector3(HitPoint), BlockRegistry.GetBlockFromBlockName("Air"), Block.Direction.NORTH, true);
                        }
                    }
                    else
                    {
                        breakingTimeLeft = 0f;
                    }
                }
                else
                {
                    PStatus.UpdateBreakingProgress(false);
                }

                if (RightMousePressed)
                {
                    if (CanPlaceABlock)
                    {
                        int bID = PStatus.ToolBox9[PStatus.CurrentItem].BlockID;
                        int cID = PStatus.ToolBox9[PStatus.CurrentItem].Count;

                        if (bID != 0 && cID != 0 && !(BlockRegistry.GetBlockFromID(bID).GetType().Equals(typeof(Tools)) || BlockRegistry.GetBlockFromID(bID).GetType().Equals(typeof(SpecialBlocks))))
                        {
                            Vector3 NewBlockPos = Int3.ToVector3(HitPoint) + HitNormal;
                            if (NewBlockPos != BlockIOPosition && NewBlockPos != BlockIOPosition + new Vector3(0f, 1f, 0f))
                            {
                                MathHelper.AddBlock(NewBlockPos, BlockRegistry.GetBlockFromID(bID), GetFacingDirection(), false, true);
                                PStatus.DropOneItem();
                                CanPlaceABlock = false;
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 6
0
    //private List<Vector3> WaitingToAddBlocks = new List<Vector3>();
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();
        foreach (Projectile p in new List <Projectile>(Bullets))
        {
            if (p.IsDead == true)
            {
                Bullets.Remove(p);
                Destroy(p.gameObject);
            }
        }
        //Releasing left click
        //Places block at position
        if (Input.GetMouseButtonUp(0))
        {
            Add.transform.GetComponent <MeshRenderer>().enabled = false;

            Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 rawposition     = hit.point + hit.normal / 2;
                Vector3 roundedpostiion = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                MathHelper.AddBlock(roundedpostiion, BlockType);
            }
        }
        //Holding left click
        //Shows Add block on screen
        else if (Input.GetMouseButton(0))
        {
            Add.transform.GetComponent <MeshRenderer>().enabled = true;

            Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 rawposition     = hit.point + hit.normal / 2;
                Vector3 roundedpostiion = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                Add.transform.position = roundedpostiion;
            }
        }
        //not holding left click

        //Releasing right click
        //Deletes block at position
        if (Input.GetMouseButtonUp(1))
        {
            Delete.transform.GetComponent <MeshRenderer>().enabled = false;


            Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 rawposition     = hit.point - hit.normal / 2;
                Vector3 roundedpostiion = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                MathHelper.AddBlock(roundedpostiion, Block.Air);
            }
        }
        //Holding right click
        //Shows delete on screen
        else if (Input.GetMouseButton(1))
        {
            Delete.transform.GetComponent <MeshRenderer>().enabled = true;


            Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 rawposition     = hit.point - hit.normal / 2;
                Vector3 roundedpostiion = new Vector3(Mathf.RoundToInt(rawposition.x), Mathf.RoundToInt(rawposition.y), Mathf.RoundToInt(rawposition.z));
                Delete.transform.position = roundedpostiion;
            }
        }
        //not holding right click
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            BlockType = Block.Dirt;
        }

        //Change block
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            BlockType = Block.Stone;
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            BlockType = Block.Cobblestone;
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            BlockType = Block.Sand;
        }


        if (Input.GetKey(KeyCode.E) && cooldown < 0)
        {
            Vector3 startpos = transform.position + new Vector3(0, 0.3f, 0);
            Bullets.Add(Instantiate(Resources.Load <Projectile>("Fireball"), startpos, Camera.main.transform.rotation));
            cooldown = firerate;
        }
        if (Input.GetKey(KeyCode.Q) && cooldown < 0)
        {
            Vector3 startpos = transform.position + new Vector3(0, 0.3f, 0);
            Bullets.Add(Instantiate(Resources.Load <Projectile>("SMGBullet"), startpos, Camera.main.transform.rotation));
            cooldown = firerate;
        }
        else
        {
            cooldown -= Time.deltaTime;
        }
    }