/// <summary> /// Set the Shoes's position to the position of the Guy if the collision delay timer is completed and the Guy and Shoes are not currently linked. /// </summary> /// <param name="shoes">A reference to the Shoes.</param> private void setShoesPositionToGuyUponCollisionIfPossible(Shoes shoes) { if (PositionRect.Intersects(shoes.PositionRect) && !delayCollisionWithShoesAndGuy && !areGuyAndShoesCurrentlyLinked) { velocity = new Vector2(0f, 0f); shoes.velocity = new Vector2(0f, 0f); shoes.Position = new Vector2(Position.X, Position.Y + 40); isGuyBeingShot = false; shoes.stopPlayerInput = true; idleAnimationLockIsOn = false; delayCollisionWithShoesAndGuy = true; areGuyAndShoesCurrentlyLinked = true; shoes.swapTexture(areGuyAndShoesCurrentlyLinked); SoundEffectHandler.stopShoesRunningEffect(); if (shoes.directionShoesAreRunning == State.Running_Left || shoes.directionShoesAreRunning == State.Idle_Left) { shoes.changeSpriteOfTheShoes("Idle_Left", true); changeSpriteOfTheGuy("Empty"); } else if (shoes.directionShoesAreRunning == State.Running_Right || shoes.directionShoesAreRunning == State.Idle_Right) { shoes.changeSpriteOfTheShoes("Idle_Right", true); changeSpriteOfTheGuy("Empty"); } } }
public void playInstance(AudioClip clip, int maxActive, float volume, bool startMuted = false) { if (!clip) { return; } List <SoundEffectHandler> handlerList = getHandlerList(clip, true); Assert.IsNotNull(handlerList); // Recycle an existing handler if we have already passed max amount of effects. // We grab the oldest one and use that (it later gets added to the back again) SoundEffectHandler handler = null; if (handlerList.Count >= maxActive) { handler = handlerList[0]; handlerList.RemoveAt(0); } if (!handler) { handler = spawnHandler(); } Assert.IsNotNull(handler); handlerList.Add(handler); handler.playClip(clip, volume, startMuted); }
/** * Creates one explosion per explodable enemy */ void Start() { soundEffects = FindObjectOfType <SoundEffectHandler>(); if (!soundEffects) { Debug.Log("SoundEffectHandler could not be found in scene."); } var count = GameObject.FindGameObjectsWithTag("Enemy").Length / 2; for (int i = 0; i < count; ++i) { if (i == 0) { explosions.Add(explosionAnimation); } else { explosions.Add((GameObject)(Instantiate(explosionAnimation))); } explosions[i].name = "Explosion" + i.ToString(); explosions[i].transform.parent = this.transform; explosions[i].SetActive(false); explosions[i].GetComponent <Animator>().enabled = false; } }
void Start() { soundEffects = FindObjectOfType <SoundEffectHandler>(); if (!soundEffects) { Debug.Log("SoundEffectHandler could not be found in scene."); } }
public void Setup() { _mockTwitchHub = new Mock <IChatWebPageHub>(); _mockHubClients = new Mock <IHubClients <IChatWebPageHub> >(); _mockHubClients.Setup(x => x.All).Returns(_mockTwitchHub.Object); _mockHub = new Mock <IHubContext <ChatWebPageHub, IChatWebPageHub> >(); _mockHub.Setup(x => x.Clients).Returns(_mockHubClients.Object); _handler = new SoundEffectHandler(_mockHub.Object); }
/// <summary> /// Plays the end of game sound effect if possible. /// </summary> private void playEndOfGameSoundEffectIfPossible() { if (shoes.stopPlayerInputDueToLevelCompletion && Level.currentLevel == 5 && !hasEndOfGameSoundEffectPlayed) { hasEndOfGameSoundEffectPlayed = true; SoundEffectHandler.playEndOfGameCompleteSoundEffect(); } }
// Use this for initialization void Start() { soundEffects = FindObjectOfType <SoundEffectHandler>(); if (!soundEffects) { Debug.Log("SoundEffectHandler could not be found in scene."); } renderer = GetComponent <SpriteRenderer>(); }
// Use this for initialization public override void Start() { base.Start(); dummySpring = GetComponent<SpringJoint2D>(); hook = GetComponent<DistanceJoint2D>(); if (soundEffectHandler == null) { soundEffectHandler = gameObject.GetComponent<SoundEffectHandler>(); } }
// Use this for initialization void Start() { body2D = GetComponent <Rigidbody2D>(); //InvokeRepeating("Fire", fireTime, fireTime); soundEffects = FindObjectOfType <SoundEffectHandler>(); if (!soundEffects) { Debug.Log("SoundEffectHandler could not be found in scene."); } }
// Use this for initialization void Start() { soundEffects = FindObjectOfType <SoundEffectHandler>(); if (!soundEffects) { Debug.Log("SoundEffectHandler could not be found in scene."); } nodes = GetComponentsInChildren <IslandDiscoveryNode>(); renderer = GetComponent <SpriteRenderer>(); renderer.enabled = false; }
void Start() { soundEffects = FindObjectOfType <SoundEffectHandler>(); if (!soundEffects) { Debug.Log("SoundEffectHandler could not be found in scene."); } CreateAnimations(explosionCount, explosions, explosionAnimation, "Explosion"); CreateAnimations(hitCount, hits, hitAnimation, "Hit"); CreateAnimations(splashCount, splashes, splashAnimation, "Splash"); }
private void onEffectFinished(SoundEffectHandler handler) { List <SoundEffectHandler> handlerList = getHandlerList(handler.clip, false); if (handlerList == null) { Debug.LogWarning("Manager listened for handler being destroyed that was not in its map"); return; } // Remove the list if no other sounds are active handlerList.Remove(handler); if (handlerList.Count == 0) { m_activeSoundEffects.Remove(handler.clip); } }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) { content = new ContentManager(ScreenManager.Game.Services, "Content"); } gameFont = content.Load <SpriteFont>("Fonts/gamefont"); // A real game would probably have more content than this sample, so // it would take longer to load. We simulate that by delaying for a // while, giving you a chance to admire the beautiful loading screen. Thread.Sleep(1000); // once the load has finished, we use ResetElapsedTime to tell the game's // timing mechanism that we have just finished a very long frame, and that // it should not try to catch up. ScreenManager.Game.ResetElapsedTime(); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = ScreenManager.SpriteBatch; // Create and load the level. level = new Level(content); // Load level and music. level.LoadLevel(); // Create the Shoes. shoes = new Shoes(level.getPlayerStartingPosition(), content.Load <Texture2D>("Sprites/Shoes32x48"), Character.State.Idle_Right, 0, 32, 48, 0, spriteBatch, 720, 1280, Keys.W, Keys.A, Keys.S, Keys.D, content); // Set the initial position of the player. shoes.Position = level.getPlayerStartingPosition(); // Create the Guy. guy = new Guy(content.Load <Texture2D>("Sprites/Guy32x48"), spriteBatch, 0, 0, 32, 48, 720, 1280, content); // Load the debug font. We use this for debugging purposes. debugFont = content.Load <SpriteFont>("Fonts/debugFont"); // Loads the sound effects that will be used in the game. SoundEffectHandler.LoadSoundEffects(content); mouseRect = new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 16, 16); }
/** * Places the enemy randomly within the game board */ void Start() { soundEffects = FindObjectOfType <SoundEffectHandler>(); if (!soundEffects) { Debug.Log("SoundEffectHandler could not be found in scene."); } bool foundPosition = false; float x = 0.0f; float y = 0.0f; var boardBounds = gameboard.GetComponent <SpriteRenderer> ().bounds; while (!foundPosition) { foundPosition = true; x = Random.Range(-boardBounds.extents.x + gameboardOffset, boardBounds.extents.x - gameboardOffset); y = Random.Range(-boardBounds.extents.y + gameboardOffset, boardBounds.extents.y - gameboardOffset); var islands = terrain.GetComponentsInChildren <SpriteRenderer>(); for (int i = 0; i < islands.Length; ++i) { var islandBounds = islands[i].bounds; if (x > islandBounds.center.x - islandBounds.extents.x && x < islandBounds.center.x + islandBounds.extents.x && y > islandBounds.center.y - islandBounds.extents.y && y < islandBounds.center.y + islandBounds.extents.y) { foundPosition = false; break; } } } float rotate = Random.Range(0.0f, 360.0f); transform.position = new Vector3(x, y, transform.position.z); transform.Rotate(new Vector3(0, 0, rotate)); forwardTime = Random.Range(minforwardTime, maxforwardTime); }
private SoundEffectHandler spawnHandler() { SoundEffectHandler effectHandler = null; if (m_handlerPrefab) { effectHandler = Instantiate(m_handlerPrefab); } else { GameObject handlerObject = new GameObject(); #if UNITY_EDITOR handlerObject.name = "SoundEffectHandlerInstance"; #endif effectHandler = handlerObject.AddComponent <SoundEffectHandler>(); } effectHandler.onEffectFinished += onEffectFinished; return(effectHandler); }
/// <summary> /// Plays one of the slapping sound effects based on a random number and if the player has gone for a new slap. /// </summary> private void handleSlappingSoundEffect() { if (mouseRect.Intersects(guy.PositionRect) && !slapEffectLocked) { Random randomizer = new Random(); int randomNumber = randomizer.Next(0, 2); slapEffectLocked = true; if (randomNumber == 0) { SoundEffectHandler.playSlap1SoundEffect(); } else { SoundEffectHandler.playSlap2SoundEffect(); } } else if (!mouseRect.Intersects(guy.PositionRect) && slapEffectLocked) { slapEffectLocked = false; } }
IEnumerator WaitThenPlay(SoundEffectHandler sound, float waitTime) { yield return(new WaitForSeconds(waitTime)); sound.PlayEffect(); }
// Use this for initialization void Start() { sound = GameObject.Find("SoundEffects").GetComponent<SoundEffectHandler>(); pHorse = GameObject.Find("Horse").GetComponent<PlayerMovement>(); currentSpeed = 1.0f; }
public virtual void Start() { nextDamage = initialDamage; currentTotalGravity = constantGravity; CalculateDamageOverTime(); CalculateGravityOverTime(); if (duration > 0.0f) { die = Time.time + duration; } if (soundEffectHandler == null) { soundEffectHandler = gameObject.GetComponent<SoundEffectHandler>(); } if (playSoundOnStart && soundEffectHandler != null) { soundEffectHandler.PlayEffect(); } }
/// <summary> /// Upon collision with a Tile, perform the appropriate action depending on the State of the Guy and what kind of Tile is being collided with. /// </summary> /// <remarks>Only if there is an actual collision will any of these statements execute.</remarks> /// <param name="currentState">The current State of the Guy.</param> /// <param name="y">The Y coordinate of the Tile in the level being collided with.</param> /// <param name="x">The X coordinate of the Tile in the level being collided with.</param> protected override void specializedCollision(State currentState, int y, int x) { if (!delayBetweenLaunchesTimer.TimerStarted) // Ensures the Guy doesn't use another Launcher too quickly. { if (currentState == State.Running_Right) { // Allow the Guy to pass through an Air Switch Cannon. if (!Level.tiles[y, x].IsAirCannonSwitch) { position.X = Level.tiles[y, x].Position.X - spriteWidth; } if (Level.tiles[y, x].TileRepresentation == 'S') { prepareMovementDueToSpringCollision(currentState); } else if (Level.tiles[y, x].IsLauncher) { usingLauncher = true; collY = y; collX = x; } else if (Level.tiles[y, x].IsAirCannonSwitch) { Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch); } else { velocity.X = 0f; delayCollisionWithShoesAndGuy = false; } } else if (currentState == State.Running_Left) { if (!Level.tiles[y, x].IsAirCannonSwitch) { position.X = Level.tiles[y, x].Position.X + Level.tiles[y, x].Texture.Width + 1; } if (Level.tiles[y, x].TileRepresentation == 'S') { prepareMovementDueToSpringCollision(currentState); } else if (Level.tiles[y, x].IsLauncher) { usingLauncher = true; collX = x; collY = y; } else if (Level.tiles[y, x].IsAirCannonSwitch) { Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch); } else { velocity.X = 0f; delayCollisionWithShoesAndGuy = false; } } else if (currentState == State.Jumping) { if (!Level.tiles[y, x].IsAirCannonSwitch) { position.Y = Level.tiles[y, x].Position.Y + Level.tiles[y, x].Texture.Height + 2; } if (Level.tiles[y, x].TileRepresentation == 'S') { prepareMovementDueToSpringCollision(currentState); } else if (Level.tiles[y, x].IsLauncher) { usingLauncher = true; collX = x; collY = y; } else if (Level.tiles[y, x].IsAirCannonSwitch) { Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch); } else { velocity.Y = 0f; } } else if (currentState == State.Decending) { if (!Level.tiles[y, x].IsAirCannonSwitch) { position.Y = Level.tiles[y, x].Position.Y - spriteHeight; } if (Level.tiles[y, x].TileRepresentation == 'S' && velocity.Y > 1f) { prepareMovementDueToSpringCollision(currentState); } else if (Level.tiles[y, x].IsLauncher) { usingLauncher = true; collX = x; collY = y; } else if (Level.tiles[y, x].IsAirCannonSwitch) { Air.activateAirCannons(Level.tiles[y, x], CurrentCollidingTile, content, spriteBatch); position = new Vector2(Level.tiles[y, x].Position.X - 16, Level.tiles[y, x].Position.Y - 32); velocity = new Vector2(0f, 0f); if (!idleAnimationLockIsOn) { changeSpriteOfTheGuy("Idle_WithoutShoes_Right"); idleAnimationLockIsOn = true; } } else { velocity = new Vector2(0f, 0f); // So the Guy doesn't fall through. useGravity = false; changeSpriteOfTheGuy("Idle_WithoutShoes_Right"); SoundEffectHandler.playGuyLandingSoundEffect(); } } } }
// Start is called before the first frame update void Start() { SoundEffectHandler.player = this; }
// Use this for initialization void Start() { sound = GameObject.Find("SoundEffects").GetComponent<SoundEffectHandler>(); mMonster = GameObject.Find("MeatMonster").GetComponent<MeatMonster>(); smokeParticle = GameObject.Find("SmokeParticle").GetComponent<ParticleSystem>(); boostParticle = GameObject.Find("BoostParticle").GetComponent<ParticleSystem>(); fireParticle = GameObject.Find("FireParticle").GetComponent<ParticleSystem>(); Random.seed = (int)System.DateTime.Now.Ticks; if (high_scores == null) { high_scores = new int[10]; for (int i=0; i < high_scores.Length; ++i) { high_scores[i] = 0; } } }