Skip to content

Commit

Permalink
-Finished Block GUI.
Browse files Browse the repository at this point in the history
-All block work completed.  Customizations and modifications can be made to fit the 'stackability' requirement in the meantime.
  • Loading branch information
mlee094 committed Mar 31, 2013
1 parent a5882fe commit a974ad4
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 24 deletions.
119 changes: 111 additions & 8 deletions SiegeDefenseCode/Assets/BlockGUIScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,134 @@
using System.Collections;

public class BlockGUIScript : MonoBehaviour {


public int optionBoxStartX;
public int optionBoxStartY;
public int optionBoxLength;
public int optionBoxWidth;

public int buttonStartX;
public int buttonStartY;
public int buttonLength;
public int buttonWidth;

public int buttonSpacing;

public int maxCost;
int cost;
// Use this for initialization
void Start () {

cost = maxCost;
}

// Update is called once per frame
void Update () {

}

void OnGUI()
{
GUI.Box (new Rect(optionBoxStartX, optionBoxStartY, optionBoxLength,optionBoxWidth), "Blocks");
GUI.Label (new Rect(optionBoxStartX, optionBoxStartY + optionBoxWidth+10, 70,20), "Count: " + cost);

if(GUI.Button(new Rect(buttonStartX, buttonStartY,buttonLength,buttonWidth), "Line Piece")) {
//string path = AssetDatabase.GetAssetPath(TBlock);

if(cost - 4 > 0)
{
GameObject.Instantiate (Resources.Load ("BlockTypes/LineBlock"));
cost = cost - 4;
}
else
{
}
//Application.LoadLevel(1);
}

if(GUI.Button(new Rect(buttonStartX+(buttonSpacing+buttonLength),buttonStartY, buttonLength, buttonWidth), "T Block")) {

if(cost - 4 > 0)
{
GameObject.Instantiate (Resources.Load ("BlockTypes/TBlock"));
cost = cost-4;
}
else
{
}
}

if(GUI.Button(new Rect(buttonStartX+2*(buttonSpacing+buttonLength),buttonStartY, buttonLength, buttonWidth), "Big T Block")) {

if(cost - 6 > 0)
{
GameObject.Instantiate (Resources.Load ("BlockTypes/RealDBlock"));
cost = cost-6;
}
else
{
}
}
if(GUI.Button(new Rect(buttonStartX+3*(buttonSpacing+buttonLength),buttonStartY, buttonLength, buttonWidth), "D Block")) {
if(cost - 5 > 0)
{
GameObject.Instantiate (Resources.Load ("BlockTypes/DBlock"));
cost = cost-5;
}
else
{
}
}
if(GUI.Button(new Rect(buttonStartX+4*(buttonSpacing+buttonLength),buttonStartY, buttonLength, buttonWidth), "Square")) {
if(cost - 4 >0)
{
GameObject.Instantiate (Resources.Load ("BlockTypes/SquareBlock"));
cost = cost-4;
}
else
{
}
}
}

void resetCost(int newCost)
{
cost = newCost;
}

/*void OnGUI()
{
GUI.Box(new Rect(10,10,100,90), "Blocks");
GUI.Box(new Rect(10,10,450,50), "Blocks");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if(GUI.Button(new Rect(20,40,80,20), "Linepiece")) {
GameObject.Instantiate (Resources.Load ("")
if(GUI.Button(new Rect(20,40,80,20), "Line Piece")) {
//string path = AssetDatabase.GetAssetPath(TBlock);
GameObject.Instantiate (Resources.Load ("BlockTypes/LineBlock"));
//Application.LoadLevel(1);
}
// Make the second button.
if(GUI.Button(new Rect(20,70,80,20), "DBlock")) {
// Make the second button
if(GUI.Button(new Rect(110,40,80,20), "D Block")) {
//Application.LoadLevel(2);
GameObject.Instantiate (Resources.Load ("BlockTypes/DBlock"));
}
if(GUI.Button(new Rect(200,40,80,20), "T Block")) {
//Application.LoadLevel(2);
GameObject.Instantiate (Resources.Load ("BlockTypes/TBlock"));
}
if(GUI.Button(new Rect(290,40,80,20), "Big T Block")) {
//Application.LoadLevel(2);
GameObject.Instantiate (Resources.Load ("BlockTypes/RealDBlock"));
}
if(GUI.Button(new Rect(380,40,80,20), "Square")) {
//Application.LoadLevel(2);
GameObject.Instantiate (Resources.Load ("BlockTypes/SquareBlock"));
}
}
*/
*/

}
62 changes: 46 additions & 16 deletions SiegeDefenseCode/Assets/BlockScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,35 @@
public class BlockScript : MonoBehaviour {
Vector3 screenPoint;
Vector3 offset;
public int price;
public int cost;
bool destroy;
bool hasBeenHit;
bool isAttackState;
bool mouseDown = false;
bool isStable; //Stability will be based on phase. Build phase is stable, attack is unstable.

// Use this for initialization
void Start () {
hasBeenHit = false;
destroy = false;
isAttackState = false;
isStable = true;
}

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

if(Input.GetKeyDown("space"))
{
Debug.Log ("Space pressed.");
isStable = false;
}
else if(Input.GetKeyDown ("v"))
{
isStable = true;
}
/*if(Input.GetKeyDown("space"))
{
Debug.Log ("Space pressed.");
destroy = true;
Expand All @@ -27,8 +41,8 @@ void Update () {
{
Debug.Log ("Z pressed.");
destroy = false;
}
if(Input.GetKeyDown ("x"))
}*/
/*if(Input.GetKeyDown ("x"))
{
isAttackState = true;
transform.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
Expand All @@ -38,13 +52,37 @@ void Update () {
if(Input.GetKeyDown ("c"))
{
isAttackState = false;
}*/

/*if(!mouseDown)
{
transform.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
transform.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX|RigidbodyConstraints.FreezeRotationY|RigidbodyConstraints.FreezePositionZ;
}
mouseDown = false;
*/

transform.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
if(isStable) //No rotations.
{
transform.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX|RigidbodyConstraints.FreezeRotationY|RigidbodyConstraints.FreezePositionZ;
}
else //Rotation along Z-axis.
{

transform.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX|RigidbodyConstraints.FreezeRotationY|RigidbodyConstraints.FreezePositionZ;

}
}

//First mouse button press down.
void OnMouseDown()
{
Debug.Log ("DOWN!");
//Debug.Log ("DOWN!");
mouseDown = true;
transform.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX|RigidbodyConstraints.FreezeRotationY|
RigidbodyConstraints.FreezeRotationZ|RigidbodyConstraints.FreezePositionZ;
if(destroy)
{
if(!hasBeenHit)
Expand All @@ -58,7 +96,7 @@ void OnMouseDown()
foreach(Transform child in transform)
{
child.gameObject.AddComponent ("Rigidbody");
child.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX|RigidbodyConstraints.FreezeRotationY|RigidbodyConstraints.FreezePositionZ;
child.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX|RigidbodyConstraints.FreezeRotationY|RigidbodyConstraints.FreezeRotationZ|RigidbodyConstraints.FreezePositionZ;

}

Expand All @@ -67,14 +105,7 @@ void OnMouseDown()
}
else if(isAttackState)
{
/*foreach(Transform child in transform)
{
child.gameObject.AddComponent ("Rigidbody");
child.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationZ|RigidbodyConstraints.FreezePositionZ;
}*/

}
}
else
{
screenPoint = Camera.main.WorldToScreenPoint (transform.position);
Expand All @@ -85,6 +116,7 @@ void OnMouseDown()
//While object is being dragged.
void OnMouseDrag()
{
mouseDown = true;
if(!destroy)
{
Vector3 currentScreenPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Expand All @@ -105,14 +137,12 @@ void rotate()
if(Input.GetKeyDown (KeyCode.RightArrow))
{
Debug.Log ("ROTATING RIGHT!");
float rotation = transform.rotation.z;

transform.Rotate (new Vector3(0,0,-90));
//transform.gameObject.GetComponent<Rigidbody>().AddTorque (new Vector3(0,0,90));
}
else if(Input.GetKeyDown (KeyCode.LeftArrow))
{
float rotation = transform.rotation.z;

transform.Rotate (new Vector3(0,0,90));
//transform.gameObject.GetComponent<Rigidbody>().AddTorque(new Vector3(0,0,-90));
Expand All @@ -121,6 +151,6 @@ void rotate()

void destroyBlock()
{

Destroy (transform);
}
}
Binary file modified SiegeDefenseCode/Assets/BlockTestEnvironment.unity
Binary file not shown.
Binary file removed SiegeDefenseCode/Assets/BlockTypes/RealDBlock.prefab
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit a974ad4

Please sign in to comment.