footballjoe789
footballjoe789
CC#
Created by anF on 12/30/2023 in #help
C# Code Help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Tetromino : MonoBehaviour
{
float fall = 0;
public float fallsSpeed = 1;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
CheckUserInput();
}

void CheckUserInput()
{
if (Input.GetKey(KeyCode.RightArrow))
{
transform.position += new Vector3(1, 0, 0);

if (!CheckIsValidPosition())
{
transform.position += new Vector3(-1, 0, 0);
}
}
else if (Input.GetKey(KeyCode.LeftArrow))
{
transform.position += new Vector3(-1, 0, 0);

if (!CheckIsValidPosition())
{
transform.position += new Vector3(1, 0, 0);
}
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
// Try rotating
transform.Rotate(0, 0, 90);

// Check if the new position is valid
if (!CheckIsValidPosition())
{
// If not, rotate back
transform.Rotate(0, 0, -90);
}
}
else if (Input.GetKeyDown(KeyCode.DownArrow) || Mathf.Round(Time.time) - fall >= fallsSpeed)
{
transform.position += new Vector3(0, -1, 0);

if (!CheckIsValidPosition())
{
transform.position += new Vector3(0, 1, 0);
}

fall = Mathf.Round(Time.time);
}
}

bool CheckIsValidPosition()
{
foreach (Transform mino in transform)
{
Vector2 pos = FindObjectOfType<Game>().Round(mino.position);

if (!FindObjectOfType<Game>().CheckInsideGrid(pos))
{
return false;
}
}

return true;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Tetromino : MonoBehaviour
{
float fall = 0;
public float fallsSpeed = 1;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
CheckUserInput();
}

void CheckUserInput()
{
if (Input.GetKey(KeyCode.RightArrow))
{
transform.position += new Vector3(1, 0, 0);

if (!CheckIsValidPosition())
{
transform.position += new Vector3(-1, 0, 0);
}
}
else if (Input.GetKey(KeyCode.LeftArrow))
{
transform.position += new Vector3(-1, 0, 0);

if (!CheckIsValidPosition())
{
transform.position += new Vector3(1, 0, 0);
}
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
// Try rotating
transform.Rotate(0, 0, 90);

// Check if the new position is valid
if (!CheckIsValidPosition())
{
// If not, rotate back
transform.Rotate(0, 0, -90);
}
}
else if (Input.GetKeyDown(KeyCode.DownArrow) || Mathf.Round(Time.time) - fall >= fallsSpeed)
{
transform.position += new Vector3(0, -1, 0);

if (!CheckIsValidPosition())
{
transform.position += new Vector3(0, 1, 0);
}

fall = Mathf.Round(Time.time);
}
}

bool CheckIsValidPosition()
{
foreach (Transform mino in transform)
{
Vector2 pos = FindObjectOfType<Game>().Round(mino.position);

if (!FindObjectOfType<Game>().CheckInsideGrid(pos))
{
return false;
}
}

return true;
}
}
12 replies
CC#
Created by anF on 12/30/2023 in #help
C# Code Help
Also, in discord you can use the
`
`
key to denote that something is a code snippet Like this. You can even use a code block (three of the
`
`
key at the top and bottom of your code) to make your code look like this:
12 replies
CC#
Created by Jaynix on 12/30/2023 in #help
Are there multiple types of compiled code? Can I get a simplified explanation of what it is?
(only complaint is that C is a lower level language)
24 replies
CC#
Created by Jaynix on 12/30/2023 in #help
Are there multiple types of compiled code? Can I get a simplified explanation of what it is?
Have you looked into how assembly code works?
24 replies
CC#
Created by Jaynix on 12/30/2023 in #help
Are there multiple types of compiled code? Can I get a simplified explanation of what it is?
Which is why code obfuscation is a must for comercial C# apps.
24 replies
CC#
Created by Jaynix on 12/30/2023 in #help
Are there multiple types of compiled code? Can I get a simplified explanation of what it is?
So in Java, the Java script(s) are compiled to a Java Intermediate Language (JIL), which can be interpreted by a Java Runtime Environment (JRE) that is built for a specific processor architecture. And if you want to build a java app that doesn't need a JRE installed to work, it can be compiled to that OS's app structure. CIL in .NET follows a similar structure.
24 replies
CC#
Created by Jaynix on 12/30/2023 in #help
Are there multiple types of compiled code? Can I get a simplified explanation of what it is?
Have you looked into the history of Java and why that programing language was a game changer in the 90s?
24 replies
CC#
Created by Jaynix on 12/30/2023 in #help
Are there multiple types of compiled code? Can I get a simplified explanation of what it is?
Are there different types of compiled code?
Yes. An app compiled to run on x86-64 cannot run on a ARM-based device without emulation at a software level.
24 replies