mirror of
https://github.com/p08dev/Tetrys.git
synced 2026-06-19 05:03:49 +02:00
Added comments
This commit is contained in:
@ -10,29 +10,20 @@ public class Grid : MonoBehaviour
|
||||
public static Transform[,] grid = new Transform[w, h];
|
||||
public static int count = 0;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Round Vector to full numbers
|
||||
public static Vector2 roundVec2(Vector2 v)
|
||||
{
|
||||
return new Vector2(Mathf.Round(v.x), Mathf.Round(v.y));
|
||||
}
|
||||
|
||||
// Check if group is inside borders
|
||||
public static bool insideBorder(Vector2 pos)
|
||||
{
|
||||
// (x >= 0) and (x < w) and (y >= 0)
|
||||
return ((int)pos.x >= 0 && (int)pos.x < w && (int)pos.y >= 0);
|
||||
}
|
||||
|
||||
// Deletes a row
|
||||
public static void deleteRow(int y)
|
||||
{
|
||||
count++;
|
||||
@ -42,18 +33,13 @@ public class Grid : MonoBehaviour
|
||||
grid[x, y] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void decreaseRowsAbove(int y)
|
||||
{
|
||||
for (int i = y; i < h; ++i)
|
||||
decreaseRow(i);
|
||||
}
|
||||
|
||||
|
||||
// Move row one down
|
||||
public static void decreaseRow(int y)
|
||||
{
|
||||
for(int x = 0; x < w; ++x)
|
||||
for (int x = 0; x < w; ++x)
|
||||
{
|
||||
if(grid[x,y] != null)
|
||||
if (grid[x, y] != null)
|
||||
{
|
||||
grid[x, y - 1] = grid[x, y];
|
||||
grid[x, y] = null;
|
||||
@ -63,6 +49,14 @@ public class Grid : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// For all rows, call decrease row
|
||||
public static void decreaseRowsAbove(int y)
|
||||
{
|
||||
for (int i = y; i < h; ++i)
|
||||
decreaseRow(i);
|
||||
}
|
||||
|
||||
// Check if the row is full
|
||||
public static bool isRowFull(int y)
|
||||
{
|
||||
for (int x = 0; x < w; ++x)
|
||||
@ -71,6 +65,7 @@ public class Grid : MonoBehaviour
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the row is full, remove it, decrease all above and increase fall speed
|
||||
public static void deleteFullRows()
|
||||
{
|
||||
for (int y = 0; y < h; ++y)
|
||||
|
||||
@ -28,9 +28,7 @@ public class Group : MonoBehaviour
|
||||
Color randomColor = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
print("Foreach loop: " + child);
|
||||
rend = child.GetComponent<Renderer>();
|
||||
|
||||
rend.material.color = randomColor;
|
||||
}
|
||||
}
|
||||
@ -120,6 +118,7 @@ public class Group : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Check if position in grid is valid
|
||||
bool isValidGridPos()
|
||||
{
|
||||
foreach (Transform child in transform)
|
||||
@ -139,6 +138,7 @@ public class Group : MonoBehaviour
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update the grid
|
||||
void updateGrid()
|
||||
{
|
||||
// Remove old childs from grid
|
||||
|
||||
@ -28,10 +28,12 @@ public class Spawner : MonoBehaviour
|
||||
{
|
||||
if (Input.GetKey(KeyCode.Escape))
|
||||
{
|
||||
// End the game
|
||||
Application.Quit();
|
||||
}
|
||||
if (Input.GetKey(KeyCode.F1))
|
||||
{
|
||||
// Restart the game
|
||||
restart();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user