Exemple #1
0
    public static void Instantiate()
    {
        _Instance = new World();
        MainLoop.GetInstance().RegisterLoopes(_Instance);
        System.Random r = new System.Random();
        PlayerPos = new Int3(r.Next(-1000, 1000), 120, r.Next(-1000, 1000));
        PP        = Int3.ToVector3(PlayerPos);

        if (Serializer.CheckFileExists(FileManager.GetPlayerSaveFileName(1)))
        {
            PlayerSettings.PrepareGame(Serializer.Deserialize_From_File <float[]>(FileManager.GetPlayerSaveFileName(1)));
        }

        if (Serializer.CheckFileExists(FileManager.GetPlayerSaveFileName(2)))
        {
            PlayerSettings.PrepareGame(Serializer.Deserialize_From_File <int[]>(FileManager.GetPlayerSaveFileName(2)));
            PP        = PlayerSettings.Position;
            PlayerPos = new Int3(PP);
        }

        if (Serializer.CheckFileExists(FileManager.GetSaveDirectory() + "game.dat"))
        {
            int[] tmpData = Serializer.Deserialize_From_File <int[]>(FileManager.GetSaveDirectory() + "game.dat");
            GameTime.Initialize((float)tmpData[0], tmpData[1]);
        }
        else
        {
            GameTime.Initialize();
        }
    }
Exemple #2
0
        public VoxelRayCollisionResult(Int3 absoluteVoxelIndex, Int3 direction, VoxelDefinition definition, Voxel voxel)
        {
            AbsoluteVoxelIndex = absoluteVoxelIndex;
            Direction          = direction;
            Definition         = definition;
            Voxel = voxel;
            var position = absoluteVoxelIndex.ToVector3() + definition.Offset;

            var size = definition.Size / 2 + new Vector3(.005f);

            BoundingBox = new BoundingBox(position - size, position + size);
        }
Exemple #3
0
 private bool IsEnemyAtHitPosition()
 {
     foreach (GameObject e in Enemies)
     {
         Vector3 EnemyPos = new Vector3(Mathf.FloorToInt(e.transform.position.x), MathHelper.MyRoundingFunctionToInt(e.transform.position.y), Mathf.FloorToInt(e.transform.position.z));
         if (EnemyPos == Int3.ToVector3(HitPoint) || EnemyPos == Int3.ToVector3(HitPoint) - Vector3.up)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #4
0
 private GameObject GetAttackedEnemy()
 {
     foreach (GameObject e in Enemies)
     {
         Vector3 EnemyPos = new Vector3(Mathf.FloorToInt(e.transform.position.x), MathHelper.MyRoundingFunctionToInt(e.transform.position.y), Mathf.FloorToInt(e.transform.position.z));
         if (EnemyPos == Int3.ToVector3(HitPoint) || EnemyPos == Int3.ToVector3(HitPoint) - Vector3.up)
         {
             return(e);
         }
     }
     return(new GameObject());
 }
Exemple #5
0
    public static void Debugging()
    {
        if (Player._Instance.DebugStatus)
        {
            Chunk  c            = World._Instance.GetChunk(Player._Instance.ChunkPos.x, Player._Instance.ChunkPos.y, Player._Instance.ChunkPos.z);
            string ChunkErrored = "";
            string LookingAtStr = "";

            if (c.GetType().Equals(typeof(ErroredChunk)))
            {
                ChunkErrored = " (Errored Chunk)";
            }

            if (Player._Instance.LookingAtBlock)
            {
                string[] tmp = MathHelper.GetBlockNameIDFromHitPointPosition(Int3.ToVector3(Player._Instance.HitPoint));
                LookingAtStr  = "Looking at: " + string.Format("{0} {1} {2}\n", Player._Instance.HitPoint.x, Player._Instance.HitPoint.y, Player._Instance.HitPoint.z);
                LookingAtStr += "Block type: " + tmp[0] + " (" + tmp[1] + ")";
            }

            string gamemode = (GameManager._Instance.ModeOfTheGame == GameManager.GameMode.CREATIVE) ? "Creative" : "Survival";

            string gameInfo = string.Format("Welcome {0} in MineBattle\nCurrent Save: {1}\nCurrent GameMode: {2}", FileManager.PlayerName, FileManager.GameName, gamemode);
            GameManager._Instance.DbgText.text = string.Format(
                gameInfo + "\n\n" + GameTime.ToString() +
                "\nXYZ: {0:F3} / {1:F3} / {2:F3}\n" +
                "Block: {3} {4} {5}\n" +
                "Chunk: {6} {7} {8} in {9} {10} {11}" +
                ChunkErrored + "\nFacing: " + GenFacing() + LookingAtStr,
                Player._Instance.PlayerIOPosition.x, Player._Instance.PlayerIOPosition.y, Player._Instance.PlayerIOPosition.z,
                Player._Instance.BlockIOPosition.x, Player._Instance.BlockIOPosition.y, Player._Instance.BlockIOPosition.z,
                Player._Instance.BlockIOPosition.x - Player._Instance.ChunkPos.x * Chunk.ChunkWidth,
                Player._Instance.BlockIOPosition.y - Player._Instance.ChunkPos.y * Chunk.ChunkHeight,
                Player._Instance.BlockIOPosition.z - Player._Instance.ChunkPos.z * Chunk.ChunkWidth,
                Player._Instance.ChunkPos.x, Player._Instance.ChunkPos.y, Player._Instance.ChunkPos.z
                );
        }
    }
Exemple #6
0
            public void Init(Int3 centerMin, Int3 centerMax, int dir)
            {
                Vector3 min = centerMin.ToVector3(-0.5f);
                Vector3 max = centerMax.ToVector3(0.5f);

                Direction = (Direction)dir;

                switch (Direction)
                {
                default:

                case Direction.Left:                        // x min

                    A = min;
                    B = new Vector3(min.x, min.y, max.z);
                    C = new Vector3(min.x, max.y, max.z);
                    D = new Vector3(min.x, max.y, min.z);

                    SizeU = (int)(max.z - min.z);                            // z
                    SizeV = (int)(max.y - min.y);                            // y
                    IsLUB = true;
                    break;

                case Direction.Down:                        // y min

                    A = min;
                    B = new Vector3(max.x, min.y, min.z);
                    C = new Vector3(max.x, min.y, max.z);
                    D = new Vector3(min.x, min.y, max.z);

                    SizeU = (int)(max.z - min.z);                            // z
                    SizeV = (int)(max.x - min.x);                            // x
                    IsLUB = false;
                    break;

                case Direction.Back:                        // z min
                    A = min;
                    B = new Vector3(min.x, max.y, min.z);
                    C = new Vector3(max.x, max.y, min.z);
                    D = new Vector3(max.x, min.y, min.z);

                    SizeU = (int)(max.y - min.y);                            // y
                    SizeV = (int)(max.x - min.x);                            // x
                    IsLUB = true;
                    break;

                case Direction.Right:                        // x max
                    A = new Vector3(max.x, min.y, min.z);
                    B = new Vector3(max.x, max.y, min.z);
                    C = max;
                    D = new Vector3(max.x, min.y, max.z);

                    SizeU = (int)(max.z - min.z);                            // z
                    SizeV = (int)(max.y - min.y);                            // y
                    IsLUB = false;
                    break;

                case Direction.Up:                        // y max

                    A = new Vector3(min.x, max.y, min.z);
                    B = new Vector3(min.x, max.y, max.z);
                    C = max;
                    D = new Vector3(max.x, max.y, min.z);

                    SizeU = (int)(max.z - min.z);                            // z
                    SizeV = (int)(max.x - min.x);                            // x
                    IsLUB = true;
                    break;

                case Direction.Front:                        // z max

                    A = new Vector3(min.x, min.y, max.z);
                    B = new Vector3(max.x, min.y, max.z);
                    C = max;
                    D = new Vector3(min.x, max.y, max.z);

                    SizeU = (int)(max.y - min.y);                            // y
                    SizeV = (int)(max.x - min.x);                            // x
                    IsLUB = false;
                    break;
                }
            }
Exemple #7
0
        public static void ApplyPlayerPhysics(Camera camera, ChunkManager chunkManager, float realElapsedTime)
        {
            var position = camera.Position;
            var velocity = camera.Velocity;


            var min = WorldSettings.PlayerMin + position; // + Vector3.UnitY * 0.05f;
            var max = WorldSettings.PlayerMax + position;

            var playerBoundingBox = new BoundingBox(min, max);

            var minInd = playerBoundingBox.Minimum.Round();
            var maxInd = playerBoundingBox.Maximum.Round();

            var totalPenetration = Vector3.Zero;
            var resultVelocity   = velocity;

            for (var i = minInd.X; i <= maxInd.X; i++)
            {
                for (var j = minInd.Y; j <= maxInd.Y; j++)
                {
                    for (var k = minInd.Z; k <= maxInd.Z; k++)
                    {
                        var absoluteIndex = new Int3(i, j, k);
                        if (!chunkManager.TryGetVoxelAddress(absoluteIndex, out var address))
                        {
                            return;
                        }

                        if (j >= address.Chunk.CurrentHeight)
                        {
                            continue;
                        }

                        var voxel = address.Chunk.GetVoxel(address.RelativeVoxelIndex);

                        var voxelDefinition = voxel.GetDefinition();

                        if (!voxelDefinition.IsPermeable)
                        {
                            var voxelPosition = absoluteIndex.ToVector3() + voxelDefinition.Offset;
                            var voxelHalfSize = voxelDefinition.Size / 2f;

                            var voxelBoundingBox = new BoundingBox(voxelPosition - voxelHalfSize, voxelPosition + voxelHalfSize);

                            var penetration = GetFirstPenetration(absoluteIndex, playerBoundingBox, voxelBoundingBox, velocity, chunkManager, realElapsedTime * 5);
                            if (penetration != null)
                            {
                                if (Math.Abs(penetration.Value.X) > Math.Abs(totalPenetration.X))
                                {
                                    totalPenetration = new Vector3(penetration.Value.X, totalPenetration.Y, totalPenetration.Z);
                                    resultVelocity   = new Vector3(0, resultVelocity.Y, resultVelocity.Z);
                                }

                                if (Math.Abs(penetration.Value.Y) > Math.Abs(totalPenetration.Y))
                                {
                                    if (penetration.Value.Y < 0)
                                    {
                                        camera.IsInAir = false;
                                    }

                                    totalPenetration = new Vector3(totalPenetration.X, penetration.Value.Y, totalPenetration.Z);
                                    resultVelocity   = new Vector3(resultVelocity.X, 0, resultVelocity.Z);
                                }

                                if (Math.Abs(penetration.Value.Z) > Math.Abs(totalPenetration.Z))
                                {
                                    totalPenetration = new Vector3(totalPenetration.X, totalPenetration.Y, penetration.Value.Z);
                                    resultVelocity   = new Vector3(resultVelocity.X, resultVelocity.Y, 0);
                                }
                            }
                        }
                    }
                }
            }

            camera.Position -= totalPenetration * 1.05f;
            camera.Velocity  = resultVelocity;
        }
Exemple #8
0
    public void Update()
    {
        if (!PlayerInitialized && GameManager.PlayerLoaded())
        {
            Eyes = GameObject.Find("Player(Clone)/Camera").GetComponent <Camera>();
            PStatus.SetHands();
            GameManager._Instance.DbgText.gameObject.SetActive(true);
            GameManager._Instance.Toolbar.SetActive(true);
            SetToolbarItems();
            PlayerInitialized = true;
            GameManager._Instance.BackgroundIMG.SetActive(false);
            EventHandler.RegisterEvent(HandleF3Event, KeyCode.F3);
            EventHandler.RegisterEvent(HandleEEvent, KeyCode.E);
            EventHandler.RegisterEvent(HandleQEvent, KeyCode.Q);
            //EventHandler.RegisterEvent(HandleREvent, KeyCode.R);
            //EventHandler.RegisterEvent(HandlePEvent, KeyCode.P);
            PlayerGUI.UpdateHealth();
        }

        if (PStatus.Died)
        {
            SinceDeath += Time.deltaTime;

            if (SinceDeath > 5f)
            {
                GameManager._Instance.ModeOfTheGame = GameManager.GameMode.CREATIVE;
                SinceDeath = 0f;
                GameManager._Instance.BackgroundIMG.SetActive(false);
                GameManager._Instance.DiedText.SetActive(false);
                PStatus.Died = false;
            }
        }

        if (!CanPlaceABlock)
        {
            LastBlock += Time.deltaTime;

            if (LastBlock > 0.14f)
            {
                CanPlaceABlock = true;
                LastBlock      = 0f;
            }
        }

        if (!CanRemoveABlock)
        {
            LastBlockRem += Time.deltaTime;

            if (LastBlockRem > 0.14f)
            {
                CanRemoveABlock = true;
                LastBlockRem    = 0f;
            }
        }

        if (!CanAttack)
        {
            LastAttack += Time.deltaTime;

            if (LastAttack > 1f)
            {
                CanAttack  = true;
                LastAttack = 0f;
            }
        }

        if (!CanEnemyAttack)
        {
            LastEnemyAtack += Time.deltaTime;

            if (LastEnemyAtack > 1.5f)
            {
                CanEnemyAttack = true;
                LastEnemyAtack = 0f;
            }
        }

        if (PlayerInitialized)
        {
            if (Input.GetMouseButton(0))
            {
                LeftMousePressed = true;
            }
            else
            {
                breakingTimeLeft = 0f;
                LeftMousePressed = false;
            }

            if (Input.GetMouseButton(1))
            {
                RightMousePressed = true;
            }
            else
            {
                RightMousePressed = false;
            }

            if (LeftMousePressed || RightMousePressed)
            {
                PStatus.GetActiveHand().GetComponent <Animation>().Play("Arm");
            }
            else
            {
                PStatus.GetActiveHand().GetComponent <Animation>().Stop();
            }

            PlayerIOPosition    = GameManager._Instance.PlayerPosition;
            PlayerIOPosition.y -= 1f;
            //BlockIOPosition = new Vector3(Mathf.FloorToInt(PlayerIOPosition.x), Mathf.FloorToInt(PlayerIOPosition.y), Mathf.FloorToInt(PlayerIOPosition.z));
            BlockIOPosition = new Vector3(Mathf.FloorToInt(PlayerIOPosition.x), MathHelper.MyRoundingFunctionToInt(PlayerIOPosition.y), Mathf.FloorToInt(PlayerIOPosition.z));
            ChunkPos        = new Int3(Mathf.FloorToInt(BlockIOPosition.x / Chunk.ChunkWidth), Mathf.FloorToInt(BlockIOPosition.y / Chunk.ChunkHeight), Mathf.FloorToInt(BlockIOPosition.z / Chunk.ChunkWidth));

            GenerateHitPoints();
            PlayerGUI.Debugging();
            PlayerGUI.ItemSelecting(ref PStatus.CurrentItem);
            CheckRegeneration();
            CheckEnemies();

            if (LookingAtBlock)
            {
                if (IsEnemyAtHitPosition())
                {
                    Select.transform.GetComponent <MeshRenderer>().enabled = false;
                    Attack();
                }
                else
                {
                    Select.transform.GetComponent <MeshRenderer>().enabled = true;
                    Select.transform.position = new Vector3(HitPoint.x + 0.5f, HitPoint.y + 0.5f, HitPoint.z + 0.5f);

                    Block destBlock = MathHelper.GetBlockAtPosition(Int3.ToVector3(HitPoint));
                    if (RightMousePressed && destBlock.GetBlockName().Equals("Craftingtable"))
                    {
                        CratingTable();
                    }
                    else if (!(!DayNightCycle.DNCycle.IsDay && GameManager._Instance.ModeOfTheGame == GameManager.GameMode.SURVIVAL))
                    {
                        BreakingAndPlacing();
                    }
                }
            }
            else
            {
                Select.transform.GetComponent <MeshRenderer>().enabled = false;
            }
        }
    }
Exemple #9
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;
                            }
                        }
                    }
                }
            }
        }
    }
 /// <summary>
 /// Update Saber Rotation
 /// </summary>
 internal static void UpdateSaberRotation()
 {
     Grip.RotLeft  = Quaternion.Euler(Int3.ToVector3(GripCfg.RotLeft)).eulerAngles;
     Grip.RotRight = Quaternion.Euler(Int3.ToVector3(GripCfg.RotRight)).eulerAngles;
 }
 /// <summary>
 /// Update Saber Position
 /// </summary>
 internal static void UpdateSaberPosition()
 {
     Grip.PosLeft  = Int3.ToVector3(GripCfg.PosLeft) / 1000f;
     Grip.PosRight = Int3.ToVector3(GripCfg.PosRight) / 1000f;
 }
Exemple #12
0
 /// <summary>
 /// Update Saber Offset
 /// </summary>
 internal static void UpdateSaberOffset()
 {
     Grip.OffsetLeft  = Int3.ToVector3(GripCfg.OffsetLeft) / 1000f;
     Grip.OffsetRight = Int3.ToVector3(GripCfg.OffsetRight) / 1000f;
 }
Exemple #13
0
 private Vector3 GetU3DScale()
 {
     return(scale.ToVector3());
 }
Exemple #14
0
    private Vector3 GetU3DForwards()
    {
        Int3 perform = FixMath.DecomposeAngle(1000, angle);

        return(perform.ToVector3());
    }