diff --git a/Blocktest/.vscode/launch.json b/Blocktest/.vscode/launch.json new file mode 100644 index 0000000..8282399 --- /dev/null +++ b/Blocktest/.vscode/launch.json @@ -0,0 +1,54 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Unity Editor", + "type": "unity", + "path": "./Library/EditorInstance.json", + "request": "launch" + }, + { + "name": "Windows Player", + "type": "unity", + "request": "launch" + }, + { + "name": "OSX Player", + "type": "unity", + "request": "launch" + }, + { + "name": "Linux Player", + "type": "unity", + "request": "launch" + }, + { + "name": "iOS Player", + "type": "unity", + "request": "launch" + }, + { + "name": "Android Player", + "type": "unity", + "request": "launch" + }, + { + "name": "Xbox One Player", + "type": "unity", + "request": "launch" + }, + { + "name": "PS4 Player", + "type": "unity", + "request": "launch" + }, + { + "name": "SwitchPlayer", + "type": "unity", + "request": "launch" + } + ] +} \ No newline at end of file diff --git a/Blocktest/Assets/Scenes/MainScene.unity b/Blocktest/Assets/Scenes/MainScene.unity index f9e56ee..3c693e3 100644 --- a/Blocktest/Assets/Scenes/MainScene.unity +++ b/Blocktest/Assets/Scenes/MainScene.unity @@ -532,6 +532,7 @@ RectTransform: m_Children: - {fileID: 1892915112} - {fileID: 2088312331} + - {fileID: 1771384453} m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1096,7 +1097,11 @@ MonoBehaviour: maxX: 255 maxY: 255 foregroundTilemap: {fileID: 1983780303} + backgroundTilemap: {fileID: 1505424472} blockManager: {fileID: 1372863295} + stonePercentage: 70 + generatorSeed: 0 + intensity: 10 --- !u!1 &1505424469 GameObject: m_ObjectHideFlags: 0 @@ -1369,6 +1374,85 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1672933304} m_CullTransparentMesh: 1 +--- !u!1 &1771384452 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1771384453} + - component: {fileID: 1771384455} + - component: {fileID: 1771384454} + m_Layer: 5 + m_Name: Version + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1771384453 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1771384452} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 750836953} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 0.5} + m_AnchorMax: {x: 1, y: 0.5} + m_AnchoredPosition: {x: -80, y: 251} + m_SizeDelta: {x: 160, y: 30} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1771384454 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1771384452} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 1 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: Blocktest alpha-0.0.1 +--- !u!222 &1771384455 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1771384452} + m_CullTransparentMesh: 1 --- !u!1 &1877863276 GameObject: m_ObjectHideFlags: 0 @@ -1732,6 +1816,7 @@ MonoBehaviour: groundLayer: serializedVersion: 2 m_Bits: 512 + perlinNoise: 0 --- !u!95 &1910289006 Animator: serializedVersion: 3 diff --git a/Blocktest/Assets/Scripts/BlockManager.cs b/Blocktest/Assets/Scripts/BlockManager.cs index b47adfe..6d9bf33 100644 --- a/Blocktest/Assets/Scripts/BlockManager.cs +++ b/Blocktest/Assets/Scripts/BlockManager.cs @@ -19,7 +19,7 @@ public class BlockManager : MonoBehaviour { [SerializeField] Dropdown selectionDropdown; - private void Start() + private void Awake() { // Initialise allBlocks array. allBlocks = new Block[allBlockTypes.Length]; diff --git a/Blocktest/Assets/Scripts/BuildSystem.cs b/Blocktest/Assets/Scripts/BuildSystem.cs index 70caed9..8e65168 100644 --- a/Blocktest/Assets/Scripts/BuildSystem.cs +++ b/Blocktest/Assets/Scripts/BuildSystem.cs @@ -95,20 +95,23 @@ void Update() currentRenderer.color = new Color(0.5f, 1f, 0.5f, 0.7f); // Otherwise, normal coloring } - if (canBuildForeground && Input.GetMouseButton(0)) - { - PlaceBlock(currentBlock, true, Camera.main.ScreenToWorldPoint(Input.mousePosition)); - } - if (canBuildBackground && Input.GetMouseButton(1)) - { - PlaceBlock(currentBlock, false, Camera.main.ScreenToWorldPoint(Input.mousePosition)); + if (canBuildForeground && Input.GetMouseButton(0)) { + BuildBlock(currentBlock, true, Camera.main.ScreenToWorldPoint(Input.mousePosition)); + } + else if (canBuildBackground && Input.GetMouseButton(1)) { + BuildBlock(currentBlock, false, Camera.main.ScreenToWorldPoint(Input.mousePosition)); } } - if(!buildMode && Input.GetMouseButton(0)) + if(!buildMode) { - BreakBlock(Camera.main.ScreenToWorldPoint(Input.mousePosition)); + if(Input.GetMouseButton(0)) { + BreakBlock(true, Camera.main.ScreenToWorldPoint(Input.mousePosition)); + } else if(Input.GetMouseButton(1)) { + BreakBlock(false, Camera.main.ScreenToWorldPoint(Input.mousePosition)); + } + } } @@ -158,28 +161,95 @@ private void InitializeCursor() } } - public void BreakBlock(Vector2 position) + public void BreakBlock(bool foreground, Vector2 position) { Vector3Int tilePosition = foregroundTilemap.WorldToCell(position); - if(foregroundTilemap.HasTile(tilePosition)) { + if(foreground && foregroundTilemap.HasTile(tilePosition)) { foregroundTilemap.SetTile(tilePosition, null); - } else if (backgroundTilemap.HasTile(tilePosition)) { + } else if (!foreground && backgroundTilemap.HasTile(tilePosition)) { backgroundTilemap.SetTile(tilePosition, null); } } - public void PlaceBlock(Block toPlace, bool foreground, Vector2 position) + // + // Summary: + // The method called whenever a PLAYER places an object. + // Parameters: + // toPlace: + // The block type to place. + // foreground: + // Whether or not the block should be placed in the foreground. + // position: + // The position of the placed block (world coords) + private void BuildBlock(Block toPlace, bool foreground, Vector2 position) + { + audioSource.PlayOneShot(currentBlock.placeSound); + PlaceBlockWorld(toPlace, foreground, position); + } + + // + // Summary: + // The method called whenever a block is placed. + // Parameters: + // toPlace: + // The block type to place. + // foreground: + // Whether or not the block should be placed in the foreground. + // position: + // The position of the placed block + public void PlaceBlockWorld(Block toPlace, bool foreground, Vector2 position) + { + PlaceBlockCell(toPlace, foreground, foregroundTilemap.WorldToCell(position)); + } + + // + // Summary: + // The method called whenever a block is placed. + // Parameters: + // toPlace: + // The block type to place. + // foreground: + // Whether or not the block should be placed in the foreground. + // position: + // The position of the placed block + public void PlaceBlockCell(Block toPlace, bool foreground, Vector3Int tilePosition) { - Vector3Int tilePosition = foregroundTilemap.WorldToCell(position); BlockTile newTile = BlockTile.CreateInstance(); newTile.sourceBlock = toPlace; newTile.sprite = toPlace.blockSprite; newTile.name = toPlace.blockName; - audioSource.PlayOneShot(currentBlock.placeSound); if(foreground) { + Debug.Log(tilePosition); newTile.colliderType = Tile.ColliderType.Grid; + foregroundTilemap.SetTile(tilePosition, newTile); + } else { + newTile.color = new Color(0.5f, 0.5f, 0.5f, 1f); + backgroundTilemap.SetTile(tilePosition, newTile); + } + } + + // + // Summary: + // The method called whenever a block is placed. + // Parameters: + // toPlace: + // The block type to place. + // foreground: + // Whether or not the block should be placed in the foreground. + // position: + // The position of the placed block + public void PlaceBlockCell(Block toPlace, bool foreground, Vector2 position) + { + Vector3Int tilePosition = new Vector3Int(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y), 0); + BlockTile newTile = BlockTile.CreateInstance(); + newTile.sourceBlock = toPlace; + newTile.sprite = toPlace.blockSprite; + newTile.name = toPlace.blockName; + + if(foreground) { Debug.Log(tilePosition); + newTile.colliderType = Tile.ColliderType.Grid; foregroundTilemap.SetTile(tilePosition, newTile); } else { newTile.color = new Color(0.5f, 0.5f, 0.5f, 1f); diff --git a/Blocktest/Assets/Scripts/WorldGen.cs b/Blocktest/Assets/Scripts/WorldGen.cs index 1038cfa..d0b8925 100644 --- a/Blocktest/Assets/Scripts/WorldGen.cs +++ b/Blocktest/Assets/Scripts/WorldGen.cs @@ -5,41 +5,73 @@ public class WorldGen : MonoBehaviour { - [SerializeField] int maxX = 255; - [SerializeField] int maxY = 255; [SerializeField] Tilemap foregroundTilemap; + [SerializeField] Tilemap backgroundTilemap; [SerializeField] BlockManager blockManager; + [SerializeField] BuildSystem buildSystem; + + [SerializeField] int stonePercentage; + /// The type of block used on the lowest layer. + public Block stoneBlock; + /// The type of block used on the middle layer. public Block dirtBlock; + /// The type of block used on the topmost layer. public Block grassBlock; - // Start is called before the first frame update + + /// The terrain seed used. + public float worldSeed; + /// The "intensity" of the generated area's elevation changes + [SerializeField] float intensity = 10.0f; + ///Progress of the generator on the generation + + public float progress = 0.0f; + void Start() { - // TODO: use Mathf.PerlinNoise() + blockManager = GetComponent(); + buildSystem = GetComponent(); + + worldSeed = Random.Range(0.0f, 1000000.0f); + Generate(255, 255, worldSeed); + } + + public void Generate(int maxX = 255, int maxY = 255, float generatorSeed = 0.0f) + { + if(generatorSeed == 0.0f) { + generatorSeed = Random.Range(0.0f, 1000000.0f); + } + dirtBlock = blockManager.allBlocks[0]; // TODO: Find a way to dynamically reserve certain blocks grassBlock = blockManager.allBlocks[1]; stoneBlock = blockManager.allBlocks[2]; + + progress = 0.0f; + for (int xi = 0; xi < maxX; xi++) { + float x = (float)xi / 10; + float result = Mathf.PerlinNoise(x * intensity + generatorSeed, generatorSeed); + int height = Mathf.RoundToInt(result * maxY); // Gets the height of the column + int stoneHeight = Mathf.RoundToInt((float)height * ((float)stonePercentage / 100)); + for (int yi = 0; yi < maxY; yi++) { Block toPlace; - if(yi < 30) { + if(yi < stoneHeight) { toPlace = stoneBlock; } - else if(yi < 40) { + else if(yi < height) { toPlace = dirtBlock; } - else if(yi == 40) { + else if(yi == height) { toPlace = grassBlock; } else { continue; } - BlockTile newTile = BlockTile.CreateInstance(); - newTile.sourceBlock = toPlace; - newTile.sprite = toPlace.blockSprite; - newTile.name = toPlace.blockName; - foregroundTilemap.SetTile(new Vector3Int(xi, yi, 0), newTile); + buildSystem.PlaceBlockCell(toPlace, true, new Vector2(xi, yi)); + buildSystem.PlaceBlockCell(toPlace, false, new Vector2(xi, yi)); + //progress += 1.0f / ((float)maxX + (float)maxY); // Add progress to the progress var } } } diff --git a/Blocktest/Assets/Sprites/delete.gif b/Blocktest/Assets/Sprites/delete.gif deleted file mode 100644 index c9fb417..0000000 Binary files a/Blocktest/Assets/Sprites/delete.gif and /dev/null differ diff --git a/Blocktest/Assets/Sprites/delete.gif.meta b/Blocktest/Assets/Sprites/delete.gif.meta deleted file mode 100644 index 2919993..0000000 --- a/Blocktest/Assets/Sprites/delete.gif.meta +++ /dev/null @@ -1,96 +0,0 @@ -fileFormatVersion: 2 -guid: 5e855f5984d115b41be840d32bb59031 -TextureImporter: - internalIDToNameTable: [] - externalObjects: {} - serializedVersion: 11 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - sRGBTexture: 1 - linearTexture: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapsPreserveCoverage: 0 - alphaTestReferenceValue: 0.5 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - streamingMipmaps: 0 - streamingMipmapsPriority: 0 - vTOnly: 0 - grayScaleToAlpha: 0 - generateCubemap: 6 - cubemapConvolution: 0 - seamlessCubemap: 0 - textureFormat: 1 - maxTextureSize: 2048 - textureSettings: - serializedVersion: 2 - filterMode: -1 - aniso: -1 - mipBias: -100 - wrapU: 1 - wrapV: 1 - wrapW: 1 - nPOTScale: 0 - lightmap: 0 - compressionQuality: 50 - spriteMode: 1 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spritePixelsToUnits: 100 - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spriteGenerateFallbackPhysicsShape: 1 - alphaUsage: 1 - alphaIsTransparency: 1 - spriteTessellationDetail: -1 - textureType: 8 - textureShape: 1 - singleChannelComponent: 0 - flipbookRows: 1 - flipbookColumns: 1 - maxTextureSizeSet: 0 - compressionQualitySet: 0 - textureFormatSet: 0 - ignorePngGamma: 0 - applyGammaDecoding: 0 - platformSettings: - - serializedVersion: 3 - buildTarget: DefaultTexturePlatform - maxTextureSize: 2048 - resizeAlgorithm: 0 - textureFormat: -1 - textureCompression: 1 - compressionQuality: 50 - crunchedCompression: 0 - allowsAlphaSplitting: 0 - overridden: 0 - androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 0 - spriteSheet: - serializedVersion: 2 - sprites: [] - outline: [] - physicsShape: [] - bones: [] - spriteID: 5e97eb03825dee720800000000000000 - internalID: 0 - vertices: [] - indices: - edges: [] - weights: [] - secondaryTextures: [] - spritePackingTag: - pSDRemoveMatte: 0 - pSDShowRemoveMatteOption: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Blocktest/Assets/Sprites/log.png.meta b/Blocktest/Assets/Sprites/log.png.meta index 2f200ae..f930ac7 100644 --- a/Blocktest/Assets/Sprites/log.png.meta +++ b/Blocktest/Assets/Sprites/log.png.meta @@ -32,7 +32,7 @@ TextureImporter: maxTextureSize: 2048 textureSettings: serializedVersion: 2 - filterMode: -1 + filterMode: 0 aniso: -1 mipBias: -100 wrapU: 1 @@ -46,7 +46,7 @@ TextureImporter: spriteMeshType: 1 alignment: 0 spritePivot: {x: 0.5, y: 0.5} - spritePixelsToUnits: 100 + spritePixelsToUnits: 16 spriteBorder: {x: 0, y: 0, z: 0, w: 0} spriteGenerateFallbackPhysicsShape: 1 alphaUsage: 1 @@ -75,6 +75,42 @@ TextureImporter: overridden: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Windows Store Apps + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: serializedVersion: 2 sprites: [] diff --git a/Blocktest/ProjectSettings/ProjectSettings.asset b/Blocktest/ProjectSettings/ProjectSettings.asset index 2c87ad1..a6ab596 100644 --- a/Blocktest/ProjectSettings/ProjectSettings.asset +++ b/Blocktest/ProjectSettings/ProjectSettings.asset @@ -127,7 +127,7 @@ PlayerSettings: 16:10: 1 16:9: 1 Others: 1 - bundleVersion: 1.0 + bundleVersion: alpha-0.0.1 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0 @@ -256,7 +256,14 @@ PlayerSettings: AndroidMinifyDebug: 0 AndroidValidateAppBundleSize: 1 AndroidAppBundleSizeToValidate: 150 - m_BuildTargetIcons: [] + m_BuildTargetIcons: + - m_BuildTarget: + m_Icons: + - serializedVersion: 2 + m_Icon: {fileID: 2800000, guid: 6353d084c91515a49b3cee53c7a59502, type: 3} + m_Width: 128 + m_Height: 128 + m_Kind: 0 m_BuildTargetPlatformIcons: [] m_BuildTargetBatching: [] m_BuildTargetGraphicsJobs: @@ -562,8 +569,8 @@ PlayerSettings: apiCompatibilityLevelPerPlatform: {} m_RenderingPath: 1 m_MobileRenderingPath: 1 - metroPackageName: 2D_BuiltInRenderer - metroPackageVersion: + metroPackageName: 2DBuiltInRenderer + metroPackageVersion: 1.0.0.0 metroCertificatePath: metroCertificatePassword: metroCertificateSubject: @@ -571,7 +578,7 @@ PlayerSettings: metroCertificateNotAfter: 0000000000000000 metroApplicationDescription: 2D_BuiltInRenderer wsaImages: {} - metroTileShortName: + metroTileShortName: Blocktest metroTileShowName: 0 metroMediumTileShowName: 0 metroLargeTileShowName: 0 @@ -616,7 +623,14 @@ PlayerSettings: XboxOneOverrideIdentityName: XboxOneOverrideIdentityPublisher: vrEditorSettings: {} - cloudServicesEnabled: {} + cloudServicesEnabled: + Analytics: 1 + Build: 0 + Collab: 0 + Game Performance: 0 + Purchasing: 0 + UDP: 0 + Unity Ads: 0 luminIcon: m_Name: m_ModelFolderPath: @@ -630,11 +644,11 @@ PlayerSettings: m_VersionName: apiCompatibilityLevel: 6 activeInputHandler: 0 - cloudProjectId: + cloudProjectId: f3478007-0196-4685-998e-fcb16e599411 framebufferDepthMemorylessMode: 0 qualitySettingsNames: [] - projectName: - organizationId: + projectName: Blocktest + organizationId: bigrat-monster cloudEnabled: 0 legacyClampBlendShapeWeights: 0 virtualTexturingSupportEnabled: 0 diff --git a/Blocktest/ProjectSettings/TimelineSettings.asset b/Blocktest/ProjectSettings/TimelineSettings.asset new file mode 100644 index 0000000..b4fbdb0 --- /dev/null +++ b/Blocktest/ProjectSettings/TimelineSettings.asset @@ -0,0 +1,15 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &1 +MonoBehaviour: + m_ObjectHideFlags: 61 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a287be6c49135cd4f9b2b8666c39d999, type: 3} + m_Name: + m_EditorClassIdentifier: + assetDefaultFramerate: 60 diff --git a/Blocktest/ProjectSettings/UnityConnectSettings.asset b/Blocktest/ProjectSettings/UnityConnectSettings.asset index fa0b146..b169ebd 100644 --- a/Blocktest/ProjectSettings/UnityConnectSettings.asset +++ b/Blocktest/ProjectSettings/UnityConnectSettings.asset @@ -19,7 +19,7 @@ UnityConnectSettings: m_Enabled: 0 m_TestMode: 0 UnityAnalyticsSettings: - m_Enabled: 0 + m_Enabled: 1 m_TestMode: 0 m_InitializeOnStartup: 1 UnityAdsSettings: