15 Replies
here is my current code
using UnityEngine;
public class Tetromino : MonoBehaviour
{
float fall = 0;
public float fallSpeed = 1;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
CheckUserInput();
}
void CheckUserInput()
{
if (Input.GetKeyDown(KeyCode.RightArrow))
{
SafeMove(new Vector3(1, 0, 0));
}
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
SafeMove(new Vector3(-1, 0, 0));
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
SafeRotate(90);
}
else if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - fall >= fallSpeed)
{
SafeMove(new Vector3(0, -1, 0));
fall = Time.time;
}
}
void SafeMove(Vector3 vec)
{
transform.position += vec;
if (!CheckIsValidPosition())
{
transform.position -= vec;
}
}
void SafeRotate(float degree)
{
transform.Rotate(0, 0, degree);
if (!CheckIsValidPosition())
{
transform.Rotate(0, 0, -degree);
}
}
bool CheckIsValidPosition()
{
foreach (Transform mino in transform) { Vector2 pos = FindObjectOfType<Game>().Round(mino.position); if (!FindObjectOfType<Game>().CheckInsideGrid(pos)) { return false; } } return true; } }
foreach (Transform mino in transform) { Vector2 pos = FindObjectOfType<Game>().Round(mino.position); if (!FindObjectOfType<Game>().CheckInsideGrid(pos)) { return false; } } return true; } }
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/why is what happening exactly?
so I am making a tetris game and my block is phasing through the bottom part of the grid I am trying to make boundrys that the block cant past
the two sides are fine its just this bottom part
how is checkInsideGrid coded?
tbh it doesnt look like ur checking every square of the tetromino
your tetromino has 4 squares
each square should have its own position
yeah
i just started c sharp today
that must be it hmmm
oh no, ur gonna have a super hard time
learn the basics first, then Unity later
$helloworld
my teacher is making me do a multimedia system where I gotta make a game its so dumb cuz she hasent even shown us how to use any programs its a big assighment
will look at that
I have been following this video serires and copying what the guy does
The Weekly Coder
YouTube
How to make a game like Tetris in Unity 5 - Part 3 - Tetromino Grid...
►►► Project Source Code is available to our patrons. Head over to our Patreon page https://www.patreon.com/bePatron?u=2811576 and show support to get access to all project source code which is just one of the many benefits of being a patron.
► Source Code
http://weeklycoder.com/product/tetris-clone-bundle/
*** SPECIAL FOR YOUTUBE SUBSCRIBERS...
its kinda out dated tho cuz his code aint even working
well you need to know what ur doing, copying code wont help you
yeah
I ended up fixing my problem
buy playing around with some stuff