void Update() { var player = Context.Data.Player; if (player.IsDead) { return; // if player is dead don't do anything } if (Input.GetKeyDown(KeyCode.Space) && !player.IsMagic && !player.IsJumping) { player.StartJumping(); //jumping } else if (Input.GetKeyDown(KeyCode.Alpha1)) { Fire(Garbages.Metal); //cast spell made of metal } else if (Input.GetKeyDown(KeyCode.Alpha2)) { Fire(Garbages.Paper); //cast spell made of paper } else if (Input.GetKeyDown(KeyCode.Alpha3)) { Fire(Garbages.Plastic); // cast spell made of plastic } else if ((Input.GetKeyDown(KeyCode.RightArrow) || (Input.GetKeyDown(KeyCode.LeftArrow))) && player.CanTurn) { if (Input.GetKeyDown(KeyCode.RightArrow)) { player.Turn("right"); //choose the right road } else { player.Turn("left"); // choose the left road } //tell the world generator which way the character is facing GenerateWorld.dummyTraveller.transform.forward = -player.transform.forward; //build the next platform GenerateWorld.RunDummy(); //if we are in a T shape platform, don't make the next platform and wait for the player to decide if (GenerateWorld.lastPlatform.tag != "platformTSection") { GenerateWorld.RunDummy(); } } else if (Input.GetKeyDown(KeyCode.A)) { //move player slightly to the left player.transform.Translate(-this.MovementAmount, 0, 0); } else if (Input.GetKeyDown(KeyCode.D)) { // move player slightly to the right player.transform.Translate(this.MovementAmount, 0, 0); } else if (Input.GetKeyDown(KeyCode.Escape)) { //pause the game PauseGame(); } }
/// <summary> /// Adds another platform ahead of the player so that it can't see the platforms being spawned. /// </summary> private void AddAnotherPlatform() { if (!GenerateWorld.lastPlatform.CompareTag("platformTSection")) { GenerateWorld.RunDummy(); } }
private void OnTriggerEnter(Collider other) { if (other is BoxCollider) { GenerateWorld.RunDummy(0, GameManager.Instance.tutorial); } }
// Start is called before the first frame update void Start() { animator = this.GetComponent <Animator>(); player = this.gameObject; startPosition = player.transform.position; GenerateWorld.runDummy(); rBody = this.GetComponent <Rigidbody>(); magicRBody = magic.GetComponent <Rigidbody>(); isDead = false; livesLeft = PlayerPrefs.GetInt("lives"); for (int i = 0; i < icons.Length; i++) { if (i >= livesLeft) { icons[i].texture = deadIcon; } } if (PlayerPrefs.HasKey("highestScore")) { highestScore.text = $"Highest : {PlayerPrefs.GetInt("highestScore")}"; } else { highestScore.text = $"Highest : 0"; } }
// Update is called once per frame void Update() { if (PlayerController.isDead) { return; } if (Input.GetKeyDown(KeyCode.Space) && anim.GetBool("isMagic") == false) { anim.SetBool("isJumping", true); rb.AddForce(Vector3.up * 200); } else if (Input.GetKeyDown(KeyCode.F) && anim.GetBool("isJumping") == false) { anim.SetBool("isMagic", true); } else if (Input.GetKeyDown(KeyCode.RightArrow) && canTurn) { this.transform.Rotate(Vector3.up * 90); GenerateWorld.dummyTraveller.transform.forward = -this.transform.forward; GenerateWorld.RunDummy(); if (GenerateWorld.lastPlatform.tag != "platformTSection") { GenerateWorld.RunDummy(); } this.transform.position = new Vector3(startPosition.x, this.transform.position.y, startPosition.z); } else if (Input.GetKeyDown(KeyCode.LeftArrow) && canTurn) { this.transform.Rotate(Vector3.up * -90); GenerateWorld.dummyTraveller.transform.forward = -this.transform.forward; GenerateWorld.RunDummy(); if (GenerateWorld.lastPlatform.tag != "platformTSection") { GenerateWorld.RunDummy(); } this.transform.position = new Vector3(startPosition.x, this.transform.position.y, startPosition.z); } else if (Input.GetKeyDown(KeyCode.A)) { this.transform.Translate(-0.3f, 0, 0); } else if (Input.GetKeyDown(KeyCode.D)) { this.transform.Translate(0.3f, 0, 0); } }
void Start() { //Anim will ne null if no animator anim = this.GetComponent <Animator>(); rb = this.GetComponent <Rigidbody>(); mRb = magic.GetComponent <Rigidbody>(); sfx = GameObject.FindWithTag("gamedata").GetComponentsInChildren <AudioSource>(); player = this.gameObject; startPosition = player.transform.position; GenerateWorld.RunDummy(); if (PlayerPrefs.HasKey("highscore")) { highScore.text = "High Score :" + PlayerPrefs.GetInt("highscore"); } else { highScore.text = "High Score :0"; } isDead = false; livesLeft = PlayerPrefs.GetInt("lives"); for (int i = 0; i < icons.Length; i++) { if (i >= livesLeft) { icons[i].texture = deadIcon; } } }
// Update is called once per frame void Update() { if (isDead) { return; } if (Input.GetKeyDown(KeyCode.Space)) { animator.SetBool("isJumping", true); rBody.AddForce(Vector3.up * 80000); } else if (Input.GetKeyDown(KeyCode.M)) { animator.SetBool("isMagic", true); } else if (Input.GetKeyDown(KeyCode.RightArrow) && canTurn) { this.transform.Rotate(0, 90, 0); GenerateWorld.dummyTraveller.transform.forward = -this.transform.forward; GenerateWorld.runDummy(); player.transform.position = new Vector3(startPosition.x, player.transform.position.y, startPosition.z); } else if (Input.GetKeyDown(KeyCode.LeftArrow) && canTurn) { this.transform.Rotate(0, -90, 0); GenerateWorld.dummyTraveller.transform.forward = -this.transform.forward; GenerateWorld.runDummy(); player.transform.position = new Vector3(startPosition.x, player.transform.position.y, startPosition.z); } else if (Input.GetKeyDown(KeyCode.A)) { this.transform.Translate(-0.4f, 0, 0); } else if (Input.GetKeyDown(KeyCode.D)) { this.transform.Translate(0.4f, 0, 0); } PlayerPrefs.SetInt("lastScore", PlayerPrefs.GetInt("score")); if (PlayerPrefs.HasKey("highestScore")) { if (PlayerPrefs.GetInt("highestScore") < PlayerPrefs.GetInt("score")) { PlayerPrefs.SetInt("highestScore", PlayerPrefs.GetInt("score")); } } else { PlayerPrefs.SetInt("highestScore", PlayerPrefs.GetInt("score")); } if (PlayerPrefs.HasKey("highestScore")) { highestScore.text = $"Highest : {PlayerPrefs.GetInt("highestScore")}"; } else { highestScore.text = $"Highest : 0"; } }
void Start() { anim = GetComponent <Animator>(); sfx = GameObject.FindWithTag("gameData").GetComponentsInChildren <AudioSource>(); player = this.gameObject; GenerateWorld.RunDummy(); startPosition = player.transform.position; rb = GetComponent <Rigidbody>(); spellRG = m_Spell.GetComponent <Rigidbody>(); isDead = false; m_livesLeft = PlayerPrefs.GetInt("lives"); for (int i = 0; i < icons.Length; i++) { if (i >= m_livesLeft) { icons[i].texture = deadIcon; } else { icons[i].texture = aliveIcon; } } }
public void Attract(Transform body) { world = worldGO.GetComponent("GenerateWorld") as GenerateWorld; Vector3 gravityUp = (body.position - CalculateCenterOfWorld(world.GetSizeWorld())).normalized; Vector3 localUp = body.up; body.GetComponent <Rigidbody>().AddForce(-gravityUp * gravity); body.rotation = Quaternion.FromToRotation(localUp, gravityUp) * body.rotation; }
// Start is called before the first frame update void Start() { player = this.gameObject; rb = GetComponent <Rigidbody>(); for (int i = 0; i < GameManager.Instance.flatStartSegments; i++) { GenerateWorld.RunDummy(0, true); } }
public Quaternion ComputeRotationForPlacement( GenerateWorld World, BlockSpawner spawner, Vector3 normalOfPlacementSurface, Vector3 curDir, BlockIndex futureIndex) { Quaternion output = Quaternion.identity; //Gets the block prefab so we can check its properties: var block = spawner.SpawnType; //We only care about the direction, not the inclination: curDir.y = 0; curDir.Normalize(); //Due to gimbal lock that can happen along a wall, we use a different axis and then rotate into the axis we want! //Thus the 270 rotation. Quaternion wallDirectionAxis = Quaternion.FromToRotation( Vector3.up, normalOfPlacementSurface); Quaternion upDirectionAxis = Quaternion.FromToRotation( Vector3.right, normalOfPlacementSurface) * Quaternion.Euler(0,270,0); Quaternion rotationTowardDown = wallDirectionAxis * upDirectionAxis ; //Is it going on the floor/ceiling: 0.2f episilon if ( normalOfPlacementSurface.y < -0.2f || normalOfPlacementSurface.y > 0.2f) { float angle = Vector3.Angle(Vector3.forward, curDir); var side = Vector3.Cross( Vector3.up, curDir); angle *= (side.z < 0) ? 1 : -1; upDirectionAxis = Quaternion.AngleAxis( angle, normalOfPlacementSurface); var upDirEuler = upDirectionAxis.eulerAngles; rotationTowardDown = wallDirectionAxis * upDirectionAxis ; //This adds the special rotation that the object gets when its on the floor or ceiling. //This exists because different objects act differently when placed. This covers most cases! if ( block.SpecialRotateX90) { rotationTowardDown = rotationTowardDown * Quaternion.Euler(90,0,0); } if ( block.SpecialRotateY90) { rotationTowardDown = rotationTowardDown * Quaternion.Euler(0,90,0); } if ( block.SpecialRotateZ90) { rotationTowardDown = rotationTowardDown * Quaternion.Euler(0,0,0); } if ( block.SpecialRotateX270) { rotationTowardDown = rotationTowardDown * Quaternion.Euler(270,0,0); } if ( block.SpecialRotateY270) { rotationTowardDown = rotationTowardDown * Quaternion.Euler(0,270,0); } if ( block.SpecialRotateZ270) { rotationTowardDown = rotationTowardDown * Quaternion.Euler(0,0,270); } } Vector3 rot = rotationTowardDown.eulerAngles; //If the object is designed to sit only on the floor remove the x and z rotations: if( block.RotatesTowardWalls == false ) { //Take only the y rotation. rot.x = 0; rot.z = 0; } output = Quaternion.Euler(rot); return output; }
private void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } instance = this; DontDestroyOnLoad(this.gameObject); }
void OnTriggerEnter(Collider other) { if (other is BoxCollider && GenerateWorld.lastPlatform.tag != "platformTSection" && (other.gameObject.tag.StartsWith("platform") || other.gameObject.tag.StartsWith("stair"))) { GenerateWorld.RunDummy(); // if the road is straight then keep generating it } if (other is SphereCollider) { CanTurn = true; // the sphere collider is located in the platform with two roads, so it means we can turn } }
private void OnTriggerEnter(Collider other) { if (other is BoxCollider && GenerateWorld.lastPlatform.tag != "platformTSection") { GenerateWorld.RunDummy(); } if (other is SphereCollider) { canTurn = true; } }
// Use this for initialization void Start() { grid = Grid2D.instance; noise = noiseTex.GetPixels(); instance = this; elevationList = new List <float>(); GenerateNewMap(); //GenerateNewMap(); //colorRamp = new List<Texture2D>(10); //Color[] ramp = colorRamp.GetPixels(); }
private void Start() { _animator = GetComponent <Animator>(); _rigidbody = GetComponent <Rigidbody>(); // Starting position of player. player = gameObject; _startPosition = player.transform.position; // creates the first platform attached to the start point. GenerateWorld.RunDummy(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); GenerateWorld myScript = (GenerateWorld)target; if (!myScript.generateJapaneseTower) { myScript.generateHouses = false; } //if (myScript.generateHouses && !myScript.generateJapaneseTower) // myScript.generateJapaneseTower = true; }
/// <summary> /// When the collider is touched, generate another platform. /// </summary> /// <param name="other"></param> private void OnTriggerEnter(Collider other) { if (other is BoxCollider && !GenerateWorld.lastPlatform.CompareTag("platformTSection")) { GenerateWorld.RunDummy(); } // The only sphere collider on the T-section to only enable turning there. if (other is SphereCollider) { _canTurn = true; } }
void OnTriggerEnter(Collider other) { if (other is BoxCollider && GenerateWorld.lastPlatform.tag != "platformTSection") { GenerateWorld.RunDummy(); } //no sphere colliders besides the one on the T platforms, that's how it's differentiated if (other is SphereCollider) { canTurn = true; } }
// Use this for initialization private void Start() { world = worldGO.GetComponent("GenerateWorld") as GenerateWorld; mesh = GetComponent <MeshFilter>().mesh; col = GetComponent <MeshCollider>(); IsSmoothMeshMode = world.isSmoothMeshMode; if (IsSmoothMeshMode) { GenerateMeshSmooth(); } else { GenerateMesh(); } }
void SplitforceInitialised(bool isFailed, Hashtable additionalData) { var _didInit = !isFailed; // You can check if everything is correct if (isFailed) { Debug.Log("SPLITFORCE: Init FAILED" + additionalData.ToString(), gameObject); } else { Debug.Log("SPLITFORCE: Init SUCCESS", gameObject); } // Experiment GamePhysics UnitySplitForce.SFVariation v = UnitySplitForce.SFManager.Instance.initExperiment("GamePhysics"); if (v != null) { this.birdColor = v.VariationData("color").DataToColor32(); this.gravity = v.VariationData("gravity").DataToFloat(gravity); this.jump = v.VariationData("jump").DataToFloat(jump); this.gapPipe = v.VariationData("gap pipe").DataToFloat(gapPipe); Debug.Log("Setting SF stuff (color: " + this.birdColor + ")"); } GenerateWorld world = camera.GetComponent <GenerateWorld> (); world.gapPipe = this.gapPipe; world.maintenance(this.transform.position.x); this.renderer.material.color = this.birdColor; // Experiment #2 string buttonText = "Default Text"; UnitySplitForce.SFVariation b = UnitySplitForce.SFManager.Instance.initExperiment("Experiment #2"); if (b != null) { this.buttonText = b.VariationData("Button Text").DataToString(); } }
public override void OnInspectorGUI() { GenerateWorld createTiles = (GenerateWorld)target; DrawDefaultInspector(); if (GUILayout.Button("Test")) { createTiles.TestFunction(); } if (GUILayout.Button("Clear World")) { createTiles.ClearWorld(); } if (GUILayout.Button("Generate Tiles")) { createTiles.GenerateTiles(); } }
// Start is called before the first frame update void Start() { anim = this.GetComponent <Animator>(); rb = this.GetComponent <Rigidbody>(); mRb = magic.GetComponent <Rigidbody>(); player = this.gameObject; startPosition = player.transform.position; GenerateWorld.RunDummy(); isDead = false; livesLeft = PlayerPrefs.GetInt("Lives"); for (int i = 0; i < icons.Length; i++) { if (i >= livesLeft) { icons[i].texture = deadIcon; } } }
/// <summary> /// Handles the players movement. and jump mechanism. /// </summary> private void UserMovement() { if (Input.GetKeyDown(key: KeyCode.Space)) { IsJumping(true); _rigidbody.AddForce(Vector3.up * _jumpForce, ForceMode.Impulse); } else if (Input.GetKeyDown(key: KeyCode.RightArrow) && _canTurn) { RotatePlayer(Vector3.up); RelocateDummyPosition(); GenerateWorld.RunDummy(); AddAnotherPlatform(); StabilizePlayer(); } else if (Input.GetKeyDown(key: KeyCode.LeftArrow) && _canTurn) { RotatePlayer(Vector3.down); RelocateDummyPosition(); GenerateWorld.RunDummy(); AddAnotherPlatform(); StabilizePlayer(); } else if (Input.GetKeyDown(key: KeyCode.A)) { transform.Translate(Vector3.left); } else if (Input.GetKeyDown(key: KeyCode.D)) { transform.Translate(Vector3.right); } else { IsJumping(false); } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Deactivation") { StartCoroutine(DeactivatePlatform(other.gameObject)); } else if (other.gameObject.tag == "Activation" && GenerateWorld.lastPlatform.tag != "platformTSection") { GenerateWorld.RunDummy(); } else if (other.gameObject.tag == "TurnPoint") { canTurn = true; } else if (other.gameObject.tag == "Sand" && !isDead) { SandDeath(); } else if (other.gameObject.tag == "Water" && !isDead) { WaterDead(); } }
public void GenerateNewWorld() { canvas.SetActive(false); gameObject.GetComponent <Rigidbody>().isKinematic = false; float ChunkX = 8 + (chunks.GetLength(0) / 2 - 1) * 16 + (gameObject.transform.position.x - (gameObject.transform.position.x % 16)); float ChunkZ; // j == z i == x for (int i = 0; i < chunks.GetLength(0); i++) { ChunkZ = 8 + (chunks.GetLength(1) / 2 - 1) * 16 + (gameObject.transform.position.z - (gameObject.transform.position.z % 16)); for (int j = 0; j < chunks.GetLength(1); j++) { chunks[i, j] = (GameObject)Instantiate(ChunkCreator, new Vector3(ChunkX, 0, ChunkZ), Quaternion.identity); GenerateWorld DW = chunks[i, j].GetComponent <GenerateWorld>(); int X = (int)chunks[i, j].transform.position.x; int Z = (int)chunks[i, j].transform.position.z; //ThreadStart myThreadDelegate = delegate //{ // DW.CreateChunk(X, Y); //};//new ThreadStart(chunks[i, j].GetComponent<GenerateWorld>().CreateChunk((int)chunks[i,j].transform.position.x, (int)chunks[i, j].transform.position.y)); //Thread myThread = new Thread(myThreadDelegate); //myThread.Start(); chunks[i, j].GetComponent <GenerateWorld>().CreateChunk(X, Z); chunks[i, j].GetComponent <GenerateWorld>().DrawChunk(); //StartCoroutine(chunks[i, j].GetComponent<GenerateWorld>().CreateChunk()); ChunkZ -= 16; } ChunkX -= 16; } x = gameObject.transform.position.x; z = gameObject.transform.position.z; XCompare = x; ZCompare = z; Instantiate(Sun, new Vector3(0, 0, 0), Quaternion.identity); InGame = true; }
// Use this for initialization public override void Start() { base.Start(); var worldObj = GameObject.FindGameObjectWithTag("World"); World = worldObj.GetComponent<GenerateWorld>(); if ( this.ProjectilePrefab != null ) { //Remove the preview objects, we want the real deal ( the prefab ) for ( int i = gameObject.transform.childCount-1; i >= 0 ; i--) { Destroy(gameObject.transform.GetChild(i).gameObject); } GameObject newKids = Instantiate(ProjectilePrefab, this.transform.position, this.transform.rotation) as GameObject; newKids.transform.parent = this.transform; newKids.transform.localScale = this.transform.localScale; if ( newKids.collider != null ) { Physics.IgnoreCollision(newKids.collider, GameObject.FindGameObjectWithTag("Player").collider); } } }
// Use this for initialization private void Start() { world = gameObject.GetComponent("GenerateWorld") as GenerateWorld; cameraGO = GameObject.FindGameObjectWithTag("MainCamera"); }
//public GameObject numTroopsInputObject; void Awake() { instance = this; }
private void SemiUpdate() { if (UpdateTurn) { GameObject LoadChunk = null; for (int i = 0; i < chunks.GetLength(0); i++) { for (int j = 0; j < chunks.GetLength(1); j++) { if (!chunks[i, j].GetComponent <GenerateWorld>().IsChunkShowen() && !chunks[i, j].GetComponent <GenerateWorld>().IsReady()) { //chunks[i, j].GetComponent<GenerateWorld>().CreateChunk(); //return; if (LoadChunk == null) { LoadChunk = chunks[i, j]; } else if (Vector2.Distance(new Vector2(gameObject.transform.position.x, gameObject.transform.position.z), new Vector2(LoadChunk.transform.position.x, LoadChunk.transform.position.z)) > Vector2.Distance(new Vector2(gameObject.transform.position.x, gameObject.transform.position.z), new Vector2(chunks[i, j].transform.position.x, chunks[i, j].transform.position.z))) { LoadChunk = chunks[i, j]; } } } } if (LoadChunk != null) { //StartCoroutine(LoadChunk.GetComponent<GenerateWorld>().CreateChunk()); //ThreadStart myThreadDelegate = new ThreadStart(LoadChunk.GetComponent<GenerateWorld>().CreateChunk); GenerateWorld DW = LoadChunk.GetComponent <GenerateWorld>(); int X = (int)(LoadChunk.transform.position.x); int Z = (int)(LoadChunk.transform.position.z); ThreadStart myThreadDelegate = delegate { DW.CreateChunk(X, Z); //DW.DrawChunk(); };//new ThreadStart(chunks[i, j].GetComponent<GenerateWorld>().CreateChunk((int)chunks[i,j].transform.position.x, (int)chunks[i, j].transform.position.y)); Thread myThread = new Thread(myThreadDelegate); myThread.Start(); //chunks[i, j].GetComponent<GenerateWorld>().DrawChunk(); } for (int i = 0; i < chunks.GetLength(0); i++) { for (int j = 0; j < chunks.GetLength(1); j++) { if (!chunks[i, j].GetComponent <GenerateWorld>().IsChunkShowen() && chunks[i, j].GetComponent <GenerateWorld>().IsReady()) { chunks[i, j].GetComponent <GenerateWorld>().DrawChunk(); break; } } } } else { if (!DeleteQueue.IsEmpty()) { DeleteQueue.Remove().GetComponent <GenerateWorld>().DestroyChunk(); } } UpdateTurn = !UpdateTurn; }
public void Run() //it starts generating platforms { GenerateWorld.RunDummy(); }
// Use this for initialization void Start() { World = this; Screen.lockCursor = true; Screen.showCursor = false; //Store prefabs of all blocks we know about into a map by name: foreach ( var prefab in AvailbleBlocks ) { BlockObject block = prefab.GetBlock(); if ( block != null ) { BlockTypes[block.ObjectID] = prefab; } } //HACKY, removes the window border using PInvoke. { Util.GoFullscreenBorderless(); } WorldCubeData = new VoxelCube(); //When a cell is removed, destroy it! WorldCubeData.CellRemoved += (obj) => { Destroy(obj.Block); }; LoadLevel(); }
// Update is called once per frame void Update() { if (PlayerController.isDead) { return; } if (currentPlatform != null) { if (this.transform.position.y < (currentPlatform.transform.position.y - 5)) { falling = true; OnCollisionEnter(null); } } if (Input.GetKeyDown(KeyCode.Space) && anim.GetBool("isMagic") == false && anim.GetBool("isJumping") == false) { anim.SetBool("isJumping", true); rb.AddForce(Vector3.up * 200); sfx[2].Play(); } else if (Input.GetKeyDown(KeyCode.M) && anim.GetBool("isJumping") == false) { anim.SetBool("isMagic", true); } else if (Input.GetKeyDown(KeyCode.RightArrow) && canTurn) { this.transform.Rotate(Vector3.up * 90); GenerateWorld.dummyMapper.transform.forward = -this.transform.forward; GenerateWorld.RunDummy(); if (GenerateWorld.lastPlatform.tag != "platformTSection") { GenerateWorld.RunDummy(); } this.transform.position = new Vector3(startPosition.x, this.transform.position.y, startPosition.z); } else if (Input.GetKeyDown(KeyCode.LeftArrow) && canTurn) { this.transform.Rotate(Vector3.up * -90); GenerateWorld.dummyMapper.transform.forward = -this.transform.forward; GenerateWorld.RunDummy(); if (GenerateWorld.lastPlatform.tag != "platformTSection") { GenerateWorld.RunDummy(); } this.transform.position = new Vector3(startPosition.x, this.transform.position.y, startPosition.z); } else if (Input.GetKeyDown(KeyCode.A)) { this.transform.Translate(-0.5f, 0, 0); } else if (Input.GetKeyDown(KeyCode.D)) { this.transform.Translate(0.5f, 0, 0); } }
void Awake() { instance = this; countCoins = length / 3.0F; x = 0; y = 0; z = 0; newBlock = ObjectPool.Instance.GetBlockZ(new Vector3(0, 0, 0)); objectList.Add (newBlock); // rot = new Quaternion(0, 0, 0, 0); z += length; newBlock = ObjectPool.Instance.GetBlockZ(new Vector3(x, y, z)); objectList.Add (newBlock); z += length; }