public static void PlaySound(Clip clip) { AudioClip audioClip = null; switch (clip) { case Clip.Jump: audioClip = GameAssets.GetInstance().BirdJumpClip; break; case Clip.Hit: audioClip = GameAssets.GetInstance().BirdHitClip; break; case Clip.Died: audioClip = GameAssets.GetInstance().BirdDeathClip; break; case Clip.Score: audioClip = GameAssets.GetInstance().BirdScoreClip; break; } GameObject gameObject = new GameObject("Sound", typeof(AudioSource)); AudioSource audioSource = gameObject.GetComponent <AudioSource>(); audioSource.PlayOneShot(audioClip); Object.Destroy(gameObject, 1); }
private void MoveGround() { /* * Gives the ground a moving animation by changing the offset of the material */ offset = new Vector2(0, ySpeed); GameAssets.GetInstance().ground.GetComponent<Renderer>().material.mainTextureOffset += offset * Time.fixedDeltaTime; }
private void ObstacleMovement() { for (int i = 0; i < obstacleList.Count; i++) { Obstacle obstacle = obstacleList[i]; bool toRightOfPlayer = obstacle.getXPos() > PlayerControl.GetInstance().GetPlayerPos(); obstacle.move(); if (toRightOfPlayer && obstacle.getXPos() <= PlayerControl.GetInstance().GetPlayerPos()) { // Score track and printer GameAssets.GetInstance().increaseScore(); } // Destory obstacles if player dodges them and they move too far to the left if (obstacle.getXPos() < OBSTACLE_DESTROY_POSITION) { // Destroy Obstacle obstacle.selfDestruct(); Debug.Log("Obstacle Destroyed"); // Remove object from list and decrement index so that we do not skip // any obstacles in the list above when one gets destroyed obstacleList.Remove(obstacle); i--; } } }
public static void CreatePipe(float height, float xPosition, List <Pipe> pipeList) { // set up pipe head Transform pipeHead = Instantiate(GameAssets.GetInstance().pfPipeHead); float pipeHeadYPosition; pipeHeadYPosition = -MyGlobals.CAMERA_ORTHO_SIZE + height - PIPE_HEAD_HEIGHT * .5f; pipeHead.position = new Vector3(xPosition, pipeHeadYPosition); // set up pipe body Transform pipeBody = Instantiate(GameAssets.GetInstance().pfPipeBody); float PipeBodyYPosition; PipeBodyYPosition = -MyGlobals.CAMERA_ORTHO_SIZE; pipeBody.position = new Vector3(xPosition, PipeBodyYPosition); SpriteRenderer pipeBodySpriteRenderer = pipeBody.GetComponent <SpriteRenderer>(); pipeBodySpriteRenderer.size = new Vector2(PIPE_WIDTH, height); BoxCollider2D pipeBodyBoxCollider = pipeBody.GetComponent <BoxCollider2D>(); pipeBodyBoxCollider.size = new Vector2(PIPE_WIDTH, height); pipeBodyBoxCollider.offset = new Vector2(0f, height * .5f); Pipe pipe = new Pipe(pipeHead, pipeBody); pipeList.Add(pipe); }
public static void CreateInitialReef(float yPosition, List <Reef> reefList) { float leftMostReef = MyGlobals.SPAWN_X_POSITION; //Creation of the initial reef line while (leftMostReef > MyGlobals.DESTROY_X_POSITION) { Transform[] reefTransformsArray = GameAssets.GetInstance().pfReefArray; Transform reefTransform = Instantiate(reefTransformsArray[Random.Range(0, reefTransformsArray.Length)]); reefTransform.position = new Vector3(leftMostReef, yPosition); SpriteRenderer reefSpriteRenderer = reefTransform.GetComponent <SpriteRenderer>(); reefSpriteRenderer.size = new Vector2(MyGlobals.REEF_DIMENSION, MyGlobals.REEF_DIMENSION); CircleCollider2D reefCircleCollider = reefTransform.GetComponent <CircleCollider2D>(); reefCircleCollider.radius = MyGlobals.REEF_DIMENSION * .4f; Transform[] reefArray = { reefTransform }; Reef reef = new Reef(reefArray); reefList.Add(reef); leftMostReef -= MyGlobals.REEF_DIMENSION * 0.75f; } }
// private Vector2 screenBounds; public static void CreateSpeedRing(float xPosition, List <SpeedRing> speedRingList) { bool canSpawnHere = false; // screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z)); float yPosition; Transform speedRingTransform = Instantiate(GameAssets.GetInstance().pfSpeedRing); while (!canSpawnHere) { // yPosition = Random.Range(-screenBounds.y, screenBounds.y); yPosition = Random.Range(MyGlobals.MAX_HEIGHT_GROUND, MyGlobals.SURFACE_POSITION); speedRingTransform.position = new Vector3(xPosition - 20f, yPosition); SpeedRing ring = new SpeedRing(speedRingTransform); canSpawnHere = PreventSpawnOverlap(ring.speedRingTransform); if (canSpawnHere) { speedRingList.Add(ring); break; } } }
private void SpawnInitialGround() { groundList.Add(Instantiate(GameAssets.GetInstance().PFGround, new Vector3(0f, GROUND_SPAWN_Y_POSITION, 0f), Quaternion.identity)); groundList.Add(Instantiate(GameAssets.GetInstance().PFGround, new Vector3(91.5f, GROUND_SPAWN_Y_POSITION, 0f), Quaternion.identity)); groundList.Add(Instantiate(GameAssets.GetInstance().PFGround, new Vector3(-91.5f, GROUND_SPAWN_Y_POSITION, 0f), Quaternion.identity)); groundList.Add(Instantiate(GameAssets.GetInstance().PFGround, new Vector3(183f, GROUND_SPAWN_Y_POSITION, 0f), Quaternion.identity)); }
void CreatePipe(float height, float xPosition, bool isBottom) { int multipler = isBottom ? 1 : -1; // Setup pipe Head Transform pipeHead = Instantiate(GameAssets.GetInstance().pfPipeHead); pipeHead.position = new Vector3(xPosition, multipler * (-CAMERA_ORTHO_SIZE + height - PIPE_HEAD_HEIGHT * .5f)); //pipesList.Add(pipeHead); // Setup pipe Body Transform pipeBody = Instantiate(GameAssets.GetInstance().pfPipeBody); pipeBody.position = new Vector3(xPosition, multipler * -CAMERA_ORTHO_SIZE); pipeBody.localScale = new Vector3(1, multipler, 1); SpriteRenderer pipeBodySR = pipeBody.GetComponent <SpriteRenderer>(); pipeBodySR.size = new Vector2(PIPE_WIDTH, height); BoxCollider2D pipeBodyBC2D = pipeBody.GetComponent <BoxCollider2D>(); pipeBodyBC2D.size = pipeBodySR.size; pipeBodyBC2D.offset = new Vector2(0, height * .5f); //pipesList.Add(pipeBody); Pipe pipe = new Pipe(pipeHead, pipeBody, isBottom); pipesList.Add(pipe); }
/** * Method to create a middle pipe. **/ private void CreateMiddlePipes(float height, float xPosition) { // Set up Pipe Head Transform pipeHeadTop = Instantiate(GameAssets.GetInstance().pfPipeHead); Transform pipeHeadBottom = Instantiate(GameAssets.GetInstance().pfPipeHead); float pipeHeadYPositionTop; float pipeHeadYPositionBottom; pipeHeadYPositionTop = 5 - PIPE_HEAD_HEIGHT * .5f; pipeHeadYPositionBottom = -5 + PIPE_HEAD_HEIGHT * .5f; pipeHeadTop.position = new Vector3(xPosition, pipeHeadYPositionTop); pipeHeadBottom.position = new Vector3(xPosition, pipeHeadYPositionBottom); // Set up Pipe Body Transform pipeBody = Instantiate(GameAssets.GetInstance().pfPipeBody); pipeBody.position = new Vector3(xPosition, -5f); SpriteRenderer pipeBodySpriteRenderer = pipeBody.GetComponent <SpriteRenderer>(); pipeBodySpriteRenderer.size = new Vector2(PIPE_WIDTH, height); BoxCollider2D pipeBodyBoxCollider = pipeBody.GetComponent <BoxCollider2D>(); pipeBodyBoxCollider.size = new Vector2(PIPE_WIDTH, height); pipeBodyBoxCollider.offset = new Vector2(0f, height * .5f); MiddlePipe middlePipe = new MiddlePipe(pipeHeadTop, pipeHeadBottom, pipeBody); middlePipeList.Add(middlePipe); }
private Transform GetTowerTop(TowerTypes towerType) { Transform towerBase; switch (towerType) { case TowerTypes.DefaultTower: towerBase = GameAssets.GetInstance().defaultTowerTop; break; case TowerTypes.MagicTower: towerBase = GameAssets.GetInstance().magicTowerTop; break; case TowerTypes.SniperTower: towerBase = GameAssets.GetInstance().sniperTowerTop; break; case TowerTypes.MachineGunTower: towerBase = GameAssets.GetInstance().machineGunTowerTop; break; default: towerBase = GameAssets.GetInstance().defaultTowerTop; break; } return(towerBase); }
// Start is called before the first frame update void Start() { Debug.Log("GameStart"); GameObject gameObject = new GameObject("Pipe", typeof(SpriteRenderer)); gameObject.GetComponent <SpriteRenderer>().sprite = GameAssets.GetInstance().Topocastelo; }
private void MoveBorder() { /* * Gives the border a moving animation by changing the offset of the material */ offset = new Vector2(0, ySpeed/8); GameAssets.GetInstance().borderLeft.GetComponent<Renderer>().material.mainTextureOffset += offset * Time.fixedDeltaTime; GameAssets.GetInstance().borderRight.GetComponent<Renderer>().material.mainTextureOffset += offset * Time.fixedDeltaTime; }
// Start is called before the first frame update private void Start() { Debug.Log("GameHandler.Start"); GameObject gameObject = new GameObject("Pipe", typeof(SpriteRenderer)); gameObject.GetComponent <SpriteRenderer>().sprite = GameAssets.GetInstance().pipeHeadSprite; // receive access to gamesprite object }
//TREE BODY private void CreateTreeBodyRightLeft() { //set up tree body Transform treeBodyRight = Instantiate(GameAssets.GetInstance().pfTreeBodyRight, new Vector3((float)(GetCameraHalfWidth() - (TREE_BODY_WIDTH * 0.5)), 0, 0), Quaternion.identity); Transform treeBodyLeft = Instantiate(GameAssets.GetInstance().pfTreeBodyLeft, new Vector3((float)(-GetCameraHalfWidth() + (TREE_BODY_WIDTH * 0.5)), 0, 0), Quaternion.identity); }
public AudioClip GetAudioClip(Sounds sounds) { foreach (GameAssets.SoundAudioClip clip in GameAssets.GetInstance().clips) { if (clip.sounds == sounds) { return(clip.clip); } } return(null); }
private static AudioClip GetAudioClip(Sound sound) { foreach (GameAssets.SoundAudioClip soundAudioClip in GameAssets.GetInstance().soundAudioClipArray) { if (soundAudioClip.sound == sound) { return(soundAudioClip.audioClip); } } return(null); }
private static AudioClip GetAudioClip(Sounds sound) { foreach (GameAssets.SoundAudioClip item in GameAssets.GetInstance().soundAudioClips) { if (item.sound == sound) { return(item.audioClip); } } return(null); }
private void HandleBackGroundSpawn() { backgroundList = new List <Transform>(); Transform ground; float backGroundY = 1.74f; float backGroundX = 22; ground = Instantiate(GameAssets.GetInstance().backGround, new Vector3(backGroundX, backGroundY, 0f), Quaternion.identity); backgroundList.Add(ground); ground = Instantiate(GameAssets.GetInstance().backGround, new Vector3(backGroundX * 4.9f, backGroundY, 0f), Quaternion.identity); backgroundList.Add(ground); }
private void CreatePipe(float height, float xPosition, bool createBottom) { // Set up Pipe Head Transform pipeHead = Instantiate(GameAssets.GetInstance().pfPipeHead); float pipeHeadYPosition; if (createBottom) { pipeHeadYPosition = -CAMERA_ORTHO_SIZE + height - PIPE_HEAD_HEIGHT * .5f; } else { pipeHeadYPosition = +CAMERA_ORTHO_SIZE - height + PIPE_HEAD_HEIGHT * .5f; } pipeHead.position = new Vector3(xPosition, pipeHeadYPosition); // Set up Body Transform pipeBody = Instantiate(GameAssets.GetInstance().pfPipeBody); float pipeBodyYPosition; if (createBottom) { pipeBodyYPosition = -CAMERA_ORTHO_SIZE; } else { pipeBodyYPosition = +CAMERA_ORTHO_SIZE; pipeBody.localScale = new Vector3(1, -1, 1); } pipeBody.position = new Vector3(xPosition, pipeBodyYPosition); // Making sure the width and height of every pipe is the same. SpriteRenderer pipeBodySpriteRender = pipeBody.GetComponent <SpriteRenderer>(); pipeBodySpriteRender.size = new Vector2(PIPE_WIDTH, height); BoxCollider2D pipeBodyBoxCollider = pipeBody.GetComponent <BoxCollider2D>(); pipeBodyBoxCollider.size = new Vector2(PIPE_WIDTH, height); pipeBodyBoxCollider.offset = new Vector2(0f, height * .5f); Pipe pipe = new Pipe(pipeHead, pipeBody, createBottom); pipeList.Add(pipe); }
private void SpawnInitialPlaftorm() { Transform plaformTransform; plaformTransform = Instantiate(GameAssets.GetInstance().platform_ground_array[0].transform, new Vector3(0, 0, 0), Quaternion.identity); plaformTransform.transform.parent = GameObject.Find("Level").transform; PlatformControllerList = new List <PlatformController>(); PlatformController platformController = new PlatformController(plaformTransform, GameAssets.GetInstance().platform_ground_array[0].tilemap); PlatformControllerList.Add(platformController); }
private void SpawnInitialGround() { GroundList = new List <Transform>(); Transform groundTr; groundTr = Instantiate(GameAssets.GetInstance().Ground_Pref, new Vector3(0, GROUND_HEIGHT, 0), Quaternion.identity); GroundList.Add(groundTr); groundTr = Instantiate(GameAssets.GetInstance().Ground_Pref, new Vector3(GROUND_WIDTH, GROUND_HEIGHT, 0), Quaternion.identity); GroundList.Add(groundTr); groundTr = Instantiate(GameAssets.GetInstance().Ground_Pref, new Vector3(GROUND_WIDTH * 2, GROUND_HEIGHT, 0), Quaternion.identity); GroundList.Add(groundTr); }
private static AudioClip GetAudioClip(Sound sound) { foreach (GameAssets.SoundAudioClip soundAudioClip in GameAssets.GetInstance().soundAudioClipArray) { if (soundAudioClip.sound == sound) { return(soundAudioClip.audioClip); } } Debug.LogError("Sound " + sound + " not found!"); return(null); }
private Transform GetCloudPrefabTransform() { switch (Random.Range(0, 3)) { case 0: return(GameAssets.GetInstance().PFCloud1); case 1: return(GameAssets.GetInstance().PFCloud2); case 2: return(GameAssets.GetInstance().PFCloud3); } return(GameAssets.GetInstance().PFCloud1); }
private Transform GetCloudPrefabTransform() { switch (Random.Range(0, 3)) { default: case 0: return(GameAssets.GetInstance().pfClouds_1); case 1: return(GameAssets.GetInstance().pfClouds_2); case 2: return(GameAssets.GetInstance().pfClouds_3); } }
private AudioClip GetAudioClip(SoundEffect sound) { foreach (GameAssets.SoundEffectAudioClip soundEffectAudioClip in GameAssets.GetInstance().soundEffectAudioClipArray) { if (soundEffectAudioClip.sound == sound) { return(soundEffectAudioClip.audioClip); } } Debug.Log("Sound: " + sound + "not found!"); return(null); }
private AudioSource GetAudioSource(SoundBackground sound) { foreach (GameAssets.SoundBackgroundAudioSource soundBackgroundAudioSource in GameAssets.GetInstance().soundBackgroundAudioSourceArray) { if (soundBackgroundAudioSource.sound == sound) { return(soundBackgroundAudioSource.audioSource); } } Debug.Log("Sound: " + sound + "not found!"); return(null); }
private void SpawnPlaftorm(float xPos, float yPos, int platform) { Transform plaformTransform; plaformTransform = Instantiate(GameAssets.GetInstance().platform_ground_array[platform].transform, new Vector3(20, yPos, 0), Quaternion.identity); plaformTransform.transform.parent = GameObject.Find("Level").transform; PlatformController platformController = new PlatformController(plaformTransform, GameAssets.GetInstance().platform_ground_array[platform].tilemap); PlatformControllerList.Add(platformController); plaformTransform.position = new Vector3((xPos + platformController.GetWidth() / 2), yPos, 0); // print("ADDED"); }
private void OnCollisionEnter2D(Collision2D other) { if (other.collider.name.Equals("Ground")) { // Update Animations animator.SetBool("Landed", true); animator.SetBool("Jump", false); // After Diving if (isDiving) { updatePlayerLocationBasedOnHealth(true); // Resets player position } // Update Player Status isJumping = false; isDiving = false; } // The Collision is an "Enemy" if (other.gameObject.CompareTag("Enemy")) { try { JumpSound[1].Play(); } catch { Debug.Log("Audio not founded"); } health = GameAssets.GetInstance().reducehealth(); other.gameObject.transform.position = new Vector2(-100f, -100f); if (health <= 0) { body.bodyType = RigidbodyType2D.Static; if (OnDeath != null) { OnDeath(this, EventArgs.Empty); } PlayerPrefs.SetInt("Score", GameAssets.GetInstance().getScore()); SceneManager.LoadScene("GameOverMenu"); PlayerPrefs.SetInt("Score", GameAssets.GetInstance().getScore()); } else { updatePlayerLocationBasedOnHealth(true); isDiving = false; isJumping = false; isDucking = false; animator.SetBool("Jump", false); animator.SetBool("Ducking", false); animator.SetBool("Landed", true); } } }
private void SpawnInitialGround() { groundList = new List <Transform>(); Transform groundTransform; float groundY = -43.84f; float groundWidth = 179f; groundTransform = Instantiate(GameAssets.GetInstance().pfGround, new Vector3(0, groundY, 0), Quaternion.identity); groundList.Add(groundTransform); groundTransform = Instantiate(GameAssets.GetInstance().pfGround, new Vector3(groundWidth, groundY, 0), Quaternion.identity); groundList.Add(groundTransform); //groundTransform = Instantiate(GameAssets.GetInstance().pfGround, new Vector3(groundWidth * 2f, groundY, 0), Quaternion.identity); //groundList.Add(groundTransform); }
private void CreatePipe() { float lowerPipeY = UnityEngine.Random.Range(GAP_LOWER_Y, GAP_HEIGHT_Y); Transform pipeUp = Instantiate(GameAssets.GetInstance().pfPipeUp); pipeUp.position = new Vector2(PIPE_SPAWN_X, lowerPipeY); Transform pipeDown = Instantiate(GameAssets.GetInstance().pfPipeDown); pipeDown.position = new Vector2(PIPE_SPAWN_X, 4.9f + lowerPipeY + PIPE_SPACE_GAP); Transform box2D = Instantiate(GameAssets.GetInstance().pfBoxTrigger); box2D.position = new Vector2(PIPE_SPAWN_X + BOX_COLLIDER_SPAWN_X, lowerPipeY + 2.7f); pairs.Add(new Pair(pipeUp, pipeDown, box2D)); }