Code cleanup!

This commit is contained in:
Kaj Forney 2022-10-07 13:18:54 -06:00
parent 03bdc2f92f
commit 15e5bb8c04
Signed by: kforney
GPG key ID: 3AB4E2E04CEF656F
10 changed files with 70 additions and 19 deletions

View file

@ -12,7 +12,7 @@ public class GroundCheck : MonoBehaviour
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.collider.tag == "Ground" || collision.collider.tag == "Platform" || collision.collider.tag == "Tetromino")
if (collision.collider.CompareTag("Ground") || collision.collider.CompareTag("Platform") || collision.collider.CompareTag("Tetromino"))
{
Debug.Log("Now standing on "+ collision.collider.name);
Player.GetComponent<Movement2D>().isGrounded = true;
@ -21,7 +21,7 @@ public class GroundCheck : MonoBehaviour
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.collider.tag == "Ground" || collision.collider.tag == "Platform" || collision.collider.tag == "Tetromino")
if (collision.collider.CompareTag("Ground") || collision.collider.CompareTag("Platform") || collision.collider.CompareTag("Tetromino"))
{
if (GetComponent<BoxCollider2D>().IsTouchingLayers(solidLayer) == false)
{

View file

@ -17,7 +17,7 @@ public class Movement2D : MonoBehaviour
{
Jump();
Vector3 movement = new Vector3(Input.GetAxis("platformerHorizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * moveSpeed;
transform.position += movement * (Time.deltaTime * moveSpeed);
if (Input.GetAxis("platformerHorizontal") > 0)
{

View file

@ -20,6 +20,7 @@ public class PlatformManager : MonoBehaviour
platforms = GameObject.FindGameObjectsWithTag("Platform"); // Creates an array of all objects with the tag platform
index = Random.Range(0, platforms.Length); // randomly selects one platform
currentPlatform = platforms[index]; // registers random platform as the one the player must get to
coin.transform.position = new Vector2(currentPlatform.transform.position.x, currentPlatform.transform.position.y + 2f);
var position = currentPlatform.transform.position;
coin.transform.position = new Vector2(position.x, position.y + 2f);
}
}

View file

@ -5,7 +5,7 @@ public class goal : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.tag == "Player")
if (other.collider.CompareTag("Player"))
{
Debug.Log("You win!!!");
GetComponent<AudioSource>().Play();

View file

@ -1,4 +1,3 @@
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

View file

@ -1,12 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class startTrigger : MonoBehaviour
{
private tetrominoSpawnManager TetrominoSpawnManager;
private bool gameStarted = false;
private bool gameStarted;
// Start is called before the first frame update
void Start()
@ -21,6 +18,7 @@ public class startTrigger : MonoBehaviour
GetComponent<AudioSource>().Play();
TetrominoSpawnManager.spawnTetromino();
gameStarted = true;
gameObject.SetActive(false);
}
}
}

View file

@ -1,4 +1,3 @@
using System;
using UnityEngine;
using Random = UnityEngine.Random;
@ -13,12 +12,12 @@ public class tetrominoSpawnManager : MonoBehaviour
public GameObject tetrominoT;
public GameObject tetrominoZ;
private int nextTetromino = 0;
private int nextTetromino;
private GameObject[] nextTetrominoSequence = new GameObject[14];
public void Start()
{
nextTetrominoSequence = new GameObject[14]
nextTetrominoSequence = new GameObject[]
{
tetrominoL, tetrominoL,
tetrominoLine, tetrominoLine,

View file

@ -63,7 +63,7 @@ public class tetrominoUserControl : MonoBehaviour
activeTetromino = null;
}
public bool checkMoveCollisions(Vector2 direction)
private bool checkMoveCollisions(Vector2 direction)
{
bool wouldCollide = false;
@ -77,7 +77,7 @@ public class tetrominoUserControl : MonoBehaviour
}
if (wouldCollide == true)
if (wouldCollide)
{
return true;
}
@ -87,7 +87,7 @@ public class tetrominoUserControl : MonoBehaviour
}
}
public void checkRotateCollisions(int degrees)
private void checkRotateCollisions(int degrees)
{
bool wouldCollide = false;
Collider2D[] results = new Collider2D[10];
@ -115,7 +115,7 @@ public class tetrominoUserControl : MonoBehaviour
}
}
//If we collided, undo the rotation.
if (wouldCollide == true)
if (wouldCollide)
{
activeTetromino.gameObject.transform.Rotate(0,0,degrees * -1,Space.World);
}

View file

@ -3,7 +3,7 @@ guid: 7b89d79c35a61e0dfa97b02fbaca389b
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
@ -24,6 +24,7 @@ TextureImporter:
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
@ -62,6 +63,7 @@ TextureImporter:
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
@ -111,6 +113,30 @@ TextureImporter:
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
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: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
@ -124,6 +150,7 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

View file

@ -3,7 +3,7 @@ guid: d539f32dbccc14dcdb47ae762cf0af6f
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
@ -24,6 +24,7 @@ TextureImporter:
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
@ -62,6 +63,7 @@ TextureImporter:
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
@ -111,6 +113,30 @@ TextureImporter:
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
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: []
@ -124,6 +150,7 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0