public bool GetCharacterBlocked(CharacterNameType charID, BlockInfo.BlockType typeToCheck, int minRequired = 1) { int number = 0; foreach (BlockInfo blockInfo in blocks) { if (blockInfo.characterWhoBlocked.CharInfo.CharacterID == charID) { if (typeToCheck == BlockInfo.BlockType.either) { number++; } else if (blockInfo.blockType == typeToCheck) { number++; } } } if (number < minRequired) { return(false); } else { return(true); } }
public bool GetBlocksHappened(BlockInfo.BlockType typeToCheck, int minRequired = 1) { int number = 0; if (blocks.Count != 0) { if (typeToCheck == BlockInfo.BlockType.either) { number = blocks.Count; } else { foreach (BlockInfo blockInfo in blocks) { if (blockInfo.blockType == typeToCheck) { number++; } } } } if (number < minRequired) { return(false); } else { return(true); } }
public void AddBlock(BaseCharacter charID, BlockInfo.BlockType blockType) { BlockInfo thisBlock = new BlockInfo(charID, blockType); blocks.Add(thisBlock); blocksLastFrame.Add(thisBlock); StartCoroutine(ResetBlockFromLastFrame(thisBlock)); }
public void RegisterNew(string ID, string name, BlockInfo.BlockType type, GameObject obj) { BlockInfo block = new BlockInfo(); block.BlockID = ID; block.BlockObj = obj; block.BlockName = name; block.Type = type; Debug.Log(ID); blockList.Add(block); }
public GameObject GetBlockByIDAndType(string ID, BlockInfo.BlockType type) { foreach (BlockInfo bl in blockList) { if (bl.BlockID == ID) { if (bl.Type == type) { return(bl.BlockObj); } } } return(null); }
// Non Physics based player control. private void PlayerControlAndResponse() { // Head Movement //TODO: Could Lerp here for smoothness? Optionally? float new_rotation_x = head.transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * Config.LOOK_SENSITIVITY; float new_rotation_y = head.transform.localEulerAngles.y + Input.GetAxis("Mouse X") * Config.LOOK_SENSITIVITY; // Enforce limits // 0 == Straight Ahead // 90 == Down etc. if (new_rotation_x < 275.0f && new_rotation_x > 150.0f) { new_rotation_x = 275.0f; } if (new_rotation_x > 85.0f && new_rotation_x < 150.0f) { new_rotation_x = 85.0f; } head.transform.localEulerAngles = new Vector3(new_rotation_x, new_rotation_y, 0.0f); // // If not holding freelook key, rotate body with head around y axis if (!Input.GetKey(Config.FREE_HEAD)) { transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y + head.transform.localEulerAngles.y, 0.0f); head.transform.localEulerAngles = new Vector3(head.transform.localEulerAngles.x, 0.0f, 0.0f); } // Block Manipulation if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetKeyDown(Config.PIPETTE) || Input.GetMouseButton(2)) { if (Input.GetMouseButton(2)) { if (Time.realtimeSinceStartup - time_of_last_paint < 0.1f) { return; } else { time_of_last_paint = Time.realtimeSinceStartup; } } // Debug Ray Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * Config.PLAYER_REACH, Color.magenta, 1.0f); // Define ray forwards through camera Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); RaycastHit hit_data; // Raycast, and return true if an object in layer 'Blocks' was hit within range if (Physics.Raycast(ray, out hit_data, Config.PLAYER_REACH, LayerMask.GetMask("Blocks"))) { // Get position of hit block Vector3 hit_block_pos = GetHitBlock(hit_data.normal, hit_data.point); // Round to get hit chunk Vector2Int hit_chunk = new Vector2Int(Mathf.FloorToInt(hit_block_pos.x / World.CHUNK_SIZE), Mathf.FloorToInt(hit_block_pos.z / World.CHUNK_SIZE)); // Get origin (position) of hit chunk in world Vector2 chunk_pos = hit_chunk * World.CHUNK_SIZE; // Get coords of hit block within parent chunk Vector3Int hit_block = new Vector3Int(Mathf.FloorToInt(hit_block_pos.x - chunk_pos.x), Mathf.FloorToInt(hit_block_pos.y), Mathf.FloorToInt(hit_block_pos.z - chunk_pos.y)); // Block Building (Right Click) if (Input.GetMouseButtonDown(1)) { int new_block_x = hit_block.x + (int)hit_data.normal.x; int new_block_y = hit_block.y + (int)hit_data.normal.y; int new_block_z = hit_block.z + (int)hit_data.normal.z; int new_chunk_x = hit_chunk.x; int new_chunk_z = hit_chunk.y; // Positive X Edge if (new_block_x >= World.CHUNK_SIZE) { new_chunk_x++; new_block_x = 0; } // Negative X Edge else if (new_block_x < 0) { new_chunk_x--; new_block_x = World.CHUNK_SIZE - 1; } // Positive Z Edge if (new_block_z >= World.CHUNK_SIZE) { new_chunk_z++; new_block_z = 0; } // Negative Z Edge else if (new_block_z < 0) { new_chunk_z--; new_block_z = World.CHUNK_SIZE - 1; } // Height Limit if (new_block_y >= World.WORLD_HEIGHT) { return; // Disregard blocks placed above world limit. Could play sound effect here. } // Apply changes Vector3Int new_block_pos = new Vector3Int( new_block_x, new_block_y, new_block_z ); Vector2Int new_chunk_pos = new Vector2Int(new_chunk_x, new_chunk_z); // Check if block will be inside player // If not, place block. Could play sound effect on 'else' Bounds new_block_bounds = new Bounds(hit_block_pos + hit_data.normal, new Vector3(1.0f, 1.0f, 1.0f)); if (!body.GetComponent <BoxCollider>().bounds.Intersects(new_block_bounds)) { // Place block chunk_manager.SetBlock((int)brush, new_chunk_pos, new_block_pos); } else { Debug.Log("PLAYER BLOCKING PLACEMENT!"); } } // Block Breaking (Left Click) else if (Input.GetMouseButtonDown(0)) { chunk_manager.SetBlock((int)BlockInfo.BlockType.Air, hit_chunk, hit_block); } // Paint else if (Input.GetMouseButton(2)) { chunk_manager.SetBlock((int)brush, hit_chunk, hit_block); } else if (Input.GetKeyDown(Config.PIPETTE)) { brush = (BlockInfo.BlockType)chunk_manager.Chunks[hit_chunk].blocks[hit_block.x, hit_block.y, hit_block.z].type; } } } }