From 99867606f695ef711b40845a11b19731910ac63c Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Fri, 26 Apr 2019 23:46:33 +0200 Subject: Added background and level scrolling --- nGJ2019/Assets/Scripts.meta | 8 +++ nGJ2019/Assets/Scripts/LevelScrolling.cs | 66 +++++++++++++++++++++++ nGJ2019/Assets/Sprites.meta | 8 +++ nGJ2019/Assets/Sprites/bg.png | Bin 0 -> 529233 bytes nGJ2019/Assets/Sprites/bg.png.meta | 90 +++++++++++++++++++++++++++++++ nGJ2019/Assets/Sprites/longcat.png | Bin 0 -> 202556 bytes nGJ2019/Assets/Sprites/longcat.png.meta | 90 +++++++++++++++++++++++++++++++ 7 files changed, 262 insertions(+) create mode 100644 nGJ2019/Assets/Scripts.meta create mode 100644 nGJ2019/Assets/Scripts/LevelScrolling.cs create mode 100644 nGJ2019/Assets/Sprites.meta create mode 100644 nGJ2019/Assets/Sprites/bg.png create mode 100644 nGJ2019/Assets/Sprites/bg.png.meta create mode 100644 nGJ2019/Assets/Sprites/longcat.png create mode 100644 nGJ2019/Assets/Sprites/longcat.png.meta diff --git a/nGJ2019/Assets/Scripts.meta b/nGJ2019/Assets/Scripts.meta new file mode 100644 index 0000000..8ce1629 --- /dev/null +++ b/nGJ2019/Assets/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d40e59778bbb441d29ef2b013583c511 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/nGJ2019/Assets/Scripts/LevelScrolling.cs b/nGJ2019/Assets/Scripts/LevelScrolling.cs new file mode 100644 index 0000000..dd413f8 --- /dev/null +++ b/nGJ2019/Assets/Scripts/LevelScrolling.cs @@ -0,0 +1,66 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LevelScrolling : MonoBehaviour +{ + public int updateRate = 1; + public Transform longcat; + public Transform background; + + private Vector3 initialBgPos; + private float[] backgroundSize; + + // Start is called before the first frame update + void Start() + { + ResizeBackground(); + } + + // Update is called once per frame + void Update() + { + + } + + void FixedUpdate() + { + MoveBackground(); + MoveLongcat(); + } + + private void ResizeBackground() + { + var sr = background.GetComponent(); + if (sr == null) return; + + background.localScale = new Vector3(1, 1, 1); + + var width = sr.sprite.bounds.size.x; + var height = sr.sprite.bounds.size.y; + + var worldScreenHeight = Camera.main.orthographicSize * 2.0; + var worldScreenWidth = worldScreenHeight / Screen.height * Screen.width; + + var finalHeight = (float)(worldScreenHeight / height); + var finalWidth = (float)(worldScreenWidth / width); + + background.localScale = new Vector3(finalHeight, finalHeight, 1); + + var viewportX = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, 0)).x; + background.position = new Vector3(viewportX * -1, 0, 0); + initialBgPos = background.position; + } + + private void MoveLongcat() + { + longcat.Translate(new Vector2(0.1f * updateRate, 0)); + } + + private void MoveBackground() + { + if (background.position.x > -initialBgPos.x) + background.Translate(new Vector2(0.1f * updateRate, 0)); + else background.position = initialBgPos; + } +} diff --git a/nGJ2019/Assets/Sprites.meta b/nGJ2019/Assets/Sprites.meta new file mode 100644 index 0000000..49c60d8 --- /dev/null +++ b/nGJ2019/Assets/Sprites.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c601bba674d654ddbb9a933a31821269 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/nGJ2019/Assets/Sprites/bg.png b/nGJ2019/Assets/Sprites/bg.png new file mode 100644 index 0000000..2205025 Binary files /dev/null and b/nGJ2019/Assets/Sprites/bg.png differ diff --git a/nGJ2019/Assets/Sprites/bg.png.meta b/nGJ2019/Assets/Sprites/bg.png.meta new file mode 100644 index 0000000..9263b00 --- /dev/null +++ b/nGJ2019/Assets/Sprites/bg.png.meta @@ -0,0 +1,90 @@ +fileFormatVersion: 2 +guid: f961209db19f64f58a67ad7f0554c561 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 10 + 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 + 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 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: b7532254506b94714a087a332a95f2b3 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/nGJ2019/Assets/Sprites/longcat.png b/nGJ2019/Assets/Sprites/longcat.png new file mode 100644 index 0000000..e688f50 Binary files /dev/null and b/nGJ2019/Assets/Sprites/longcat.png differ diff --git a/nGJ2019/Assets/Sprites/longcat.png.meta b/nGJ2019/Assets/Sprites/longcat.png.meta new file mode 100644 index 0000000..9beb047 --- /dev/null +++ b/nGJ2019/Assets/Sprites/longcat.png.meta @@ -0,0 +1,90 @@ +fileFormatVersion: 2 +guid: f0c6b650c6eb34367a41045093051665 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 10 + 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 + 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 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: b040b8360c8964439871fd5251c4bd74 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.2.3