Esempio n. 1
0
	public void handleLogic(float x, float z, float action, float action2)
	{
		if ((inputBlocked) || (paralysed) || (LevelFinishedController.instance.isStopped()))
		{
			return;
		}

		if (lighthouseEntered)
		{
			if ((action > InputController.BUTTON_DURATION) || (action2 > InputController.BUTTON_DURATION))
			{
				Vector3 movement = Vector3.zero;
				if (!gameObject.name.Equals("Player5"))
				{
					movement = new Vector3(0,0,2.0f);
					GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
				}
				else
				{
					if ((LevelFinishedController.instance.isPickingUpEnabled() || LevelFinishedController.instance.isSmashingEnabled()) && (!CraneController.instance.isEntered()))
					{
						movement = new Vector3(3.0f,0,-0.5f);
						//transform.position = cranePosition;
						EnterCrane();
					}
					else if ((LevelFinishedController.instance.isTeleportEnabled() || LevelFinishedController.instance.isStunGunEnabled()) && (!DroneController.instance.isEntered()))
					{
						movement = new Vector3(-3.0f,0,-0.5f);
						//transform.position = dronePosition;
						EnterPortalGun();
					}
				}
				if (!movement.Equals(Vector3.zero))
				{
					lighthouseEntered = false;
					AudioController.instance.Play("012_LightOffB");
					TopLightController.instance.TurnOff();
					gameObject.transform.Translate(movement);
				}
			}

			if ((action > 0) && (action <= InputController.BUTTON_DURATION))
			{
				TopLightController.instance.AttractMonster();
			}

			if ((action > InputController.MIN_BUTTON_DURATION) || (action2 > InputController.MIN_BUTTON_DURATION))
			{
				MachineDoorsController.instance.OpenLightDoor();
			}

			if ((action > InputController.MIN_BUTTON_DURATION) && (action < InputController.BUTTON_DURATION) 
				|| (action2 > InputController.MIN_BUTTON_DURATION) && (action2 < InputController.BUTTON_DURATION) )
			{
				MachineDoorsController.instance.CloseLightDoor();
			}
			
			if ((action2 > 0) && (action2 <= InputController.BUTTON_DURATION))
			{
				TopLightController.instance.ActivateItems();
			}

			if(x < 0)
			{
				LightController.instance.gameObject.SendMessage("MoveLeft");
			}
			
			if(x > 0)
			{
				LightController.instance.gameObject.SendMessage("MoveRight");
			}

			idle = true;
			Idle();

		}
		else if (craneEntered)
		{
			if ((action > InputController.BUTTON_DURATION) || (action2 > InputController.BUTTON_DURATION))
			{
				Vector3 movement = Vector3.zero;
				if (!gameObject.name.Equals("Player5"))
				{
					movement = new Vector3(0,0,2.0f);
					GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
				}
				else
				{
					if ((LevelFinishedController.instance.isTeleportEnabled() || LevelFinishedController.instance.isStunGunEnabled()) && (!DroneController.instance.isEntered()))
					{
						movement = new Vector3(-6.0f,0,0);
						//transform.position = dronePosition;
						EnterPortalGun();
					} 
					else if (!TopLightController.instance.isEntered())
					{
						movement = new Vector3(-3.0f,0,0.5f);
						//transform.position = lightPosition;
						EnterLighthouse();
					}
				}
				if (!movement.Equals(Vector3.zero))
				{
					craneEntered = false;
					CraneController.instance.TurnOff();
					gameObject.transform.Translate(movement);
					AudioController.instance.Play("012_LightOffB");
				}
			}

			if ((action > 0) && (action <= InputController.BUTTON_DURATION))
			{
				CraneController.instance.PickUp();
			}

			if ((action2 > 0) && (action2 <= InputController.BUTTON_DURATION))
			{
				CraneController.instance.SmashWall();
			}

			if ((x != 0) || (z != 0))
			{
				CraneController.instance.Move(new Vector3(x,action,z));
			}

			if ((action > InputController.MIN_BUTTON_DURATION) || (action2 > InputController.MIN_BUTTON_DURATION))
			{
				MachineDoorsController.instance.OpenCraneDoor();
			}
			
			if ((action > InputController.MIN_BUTTON_DURATION) && (action < InputController.BUTTON_DURATION) 
			    || (action2 > InputController.MIN_BUTTON_DURATION) && (action2 < InputController.BUTTON_DURATION) )
			{
				MachineDoorsController.instance.CloseCraneDoor();
			}

			idle = true;
			Idle();
		}
		else if (portalGunEntered)
		{
			if ((action > InputController.BUTTON_DURATION) || (action2 > InputController.BUTTON_DURATION))
			{
				Vector3 movement = Vector3.zero;
				if (!gameObject.name.Equals("Player5"))
				{
					movement = new Vector3(0,0,2.0f);
					GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
				}
				else
				{
					if (!TopLightController.instance.isEntered())
					{
						movement = new Vector3(3.0f,0,0.5f);
						//transform.position = lightPosition;
						EnterLighthouse();
					}
					else if ((LevelFinishedController.instance.isPickingUpEnabled() || LevelFinishedController.instance.isSmashingEnabled()) && (!CraneController.instance.isEntered()))
					{
						movement = new Vector3(6.0f,0,0);
						//transform.position = cranePosition;
						EnterCrane();
					} 
				}
				if (!movement.Equals(Vector3.zero))
				{
					portalGunEntered = false;
					DroneController.instance.TurnOff();
					gameObject.transform.Translate(movement);
					AudioController.instance.Play("012_LightOffB");
				}
			}
			
			DroneController.instance.Move(new Vector3(x,action,z));

			if ((action > 0) && (action <= InputController.BUTTON_DURATION))
			{
				DroneController.instance.Shoot();
			}

			if ((action2 > 0) && (action2 <= InputController.BUTTON_DURATION))
			{
				DroneController.instance.UseStunGun();
			}

			if ((action > InputController.MIN_BUTTON_DURATION) || (action2 > InputController.MIN_BUTTON_DURATION))
			{
				MachineDoorsController.instance.OpenDroneDoor();
			}
			
			if ((action > InputController.MIN_BUTTON_DURATION) && (action < InputController.BUTTON_DURATION) 
			    || (action2 > InputController.MIN_BUTTON_DURATION) && (action2 < InputController.BUTTON_DURATION) )
			{
				MachineDoorsController.instance.CloseDroneDoor();
			}

			idle = true;
			Idle();
		}
		else if (levelChangeEntered != null)
		{
			if (x * levelChangeEntered.change > 0)
			{
				levelChangeEntered.Change();
			}
			else
			{
				if (x * levelChangeEntered.change < 0 || z != 0)
				{
					levelChangeEntered = null;
				}
			}
		}
		else
		{
			if (Application.loadedLevel != 0)
			{
				if (action > 0)
				{
					Color newColor;
					//green player 1
					if (gameObject.name == "Player1")
					{
						newColor = new Color(0.4f,0.8f,0.3f);
					}
					//blue player 2
					else if (gameObject.name == "Player2")
					{
						newColor = new Color(0.15f,0.6f,1);
					}
					//pink player 3
					else if (gameObject.name == "Player3")
					{
						newColor = new Color(0.83f,0.32f,0.5f);
					}
					//yellow player 4
					else 
					{
						newColor = new Color(0.85f,0.82f,0.3f);
					}
					DeviceController.instance.Move(transform.position, newColor);

				}

				if (action2 > 0)
				{
					if (inventory.getInventoryItem() == null)
					{
						GameObject jumpItem = inventory.getAvailablItem();
						if (jumpItem != null)
						{
							JumpController.instance.addToBoxCollideCount();
							FloorInstructions.instance.ChangeInstructions();
							jumpItem.transform.localPosition = new Vector3(transform.localPosition.x,
							                                               transform.localPosition.y + 4,
							                                               transform.localPosition.z);
							jumpItem.transform.parent = gameObject.transform;
							jumpItem.GetComponent<Rigidbody>().isKinematic = true;
							jumpItem.SendMessage("Take");
							inventory.putItemIntoInventory();
							AudioController.instance.Play("005_PickUp");
						}
					}
					else
					{
						JumpController.instance.resetBoxCollideCount();
						inventory.getInventoryItem().transform.position = new Vector3(transform.localPosition.x,
						                                            					   1.5f,
						                                               					   transform.localPosition.z);
						inventory.getInventoryItem().transform.rotation = Quaternion.Euler(0,0,0);
						inventory.getInventoryItem().transform.parent = null;
						inventory.getInventoryItem().GetComponent<Rigidbody>().isKinematic = false;
						inventory.getInventoryItem().SendMessage("Leave");
						inventory.setAvailableItem(inventory.getInventoryItem());
						inventory.clearInventory();
						AudioController.instance.Play("006_Drop");
					}
				}
			}
			if ((x != 0) || (z != 0))
			{
				playerActive = true;
				GetComponent<Rigidbody>().velocity = new Vector3(x, 0, z).normalized * speed;
				transform.rotation = Quaternion.LookRotation(new Vector3(x, 0, z));

					// run animation
					idle = false;
					NotIdle();
			}
			else
			{
				if (playerActive)
				{
					playerActive = false;
					GetComponent<Rigidbody>().velocity = new Vector3(x, 0, z).normalized * speed;

						//idle animation
						idle = true;
						Idle();
				}
			}
		}
	}
Esempio n. 2
0
    LevelChangeController levelChangeController;        // Refference to levelChangeController

    void Awake()
    {
        levelChangeController = GameObject.FindGameObjectWithTag("T_LevelChange").GetComponent <LevelChangeController>();
    }
Esempio n. 3
0
	void OnCollisionEnter (Collision collision)
	{
		if(collision.collider.name == "Lighthouse")
		{
			if (!TopLightController.instance.isEntered())
			{
				freeze();
				GetComponent<Rigidbody>().transform.rotation = (Quaternion.Euler(0,0,0));
				EnterLighthouse();
			}
		}
		if(collision.collider.name == "Crane")
		{
			if (!CraneController.instance.isEntered())
			{
				freeze();
				GetComponent<Rigidbody>().transform.rotation = (Quaternion.Euler(0,0,0));
				EnterCrane();
			}
		}
		if(collision.collider.name == "PortalGun")
		{
			if (!DroneController.instance.isEntered())
			{
				freeze();
				GetComponent<Rigidbody>().transform.rotation = (Quaternion.Euler(0,0,0));
				EnterPortalGun();
			}
		}
		if(collision.collider.tag == "Monster")
		{
			if (!paralysed)
			{
				paralysed = true;
				idle = true;
				Idle();
				gameController.SendMessage("PlayerParalysed");
				AudioController.instance.Play("008_dead");
				transform.GetChild(0).transform.GetChild(0).gameObject.GetComponent<Renderer>().materials[0].SetColor("_Color", Color.grey);
				transform.GetChild(0).transform.GetChild(0).gameObject.GetComponent<Renderer>().materials[0].SetColor("_EmissionColor", Color.grey);
				GetComponent<Collider>().isTrigger = true;
				collision.collider.GetComponent<Rigidbody>().velocity = Vector3.zero;
				collision.collider.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
				if (GetComponent<Rigidbody>() != null)
				{
					GetComponent<Rigidbody>().velocity = Vector3.zero;
					GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
				}
				FloorInstructions.instance.ShowReviveInstructions();
				//collision.gameObject.SendMessage("Recalculate");
			}
		}
		if(collision.collider.name == "Platform")
		{
			levelChangeEntered = collision.collider.gameObject.GetComponent<LevelChangeController>();
			GetComponent<Rigidbody>().velocity = Vector3.zero;
			GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
		}
	}