private void Awake() { if (messageDictionary == null) { messageDictionary = new Dictionary <TEXT_MESSAGES, string>(); messageDictionary[TEXT_MESSAGES.GATHER_HERE] = "I found something"; messageDictionary[TEXT_MESSAGES.HELP] = "Help me!"; messageDictionary[TEXT_MESSAGES.RUN] = "Run"; messageDictionary[TEXT_MESSAGES.GOOD_JOB] = "Well done"; } if (emojiPositions == null) { emojiPositions = new Dictionary <EMOJIS, Vector3>(); emojiPositions[EMOJIS.SLY] = new Vector3(-0.018f, -0.082f, -0.11f); emojiPositions[EMOJIS.KISSY] = new Vector3(0.088f, -0.168f, -0.11f); emojiPositions[EMOJIS.SNORE] = new Vector3(-0.018f, -0.062f, -0.11f); emojiPositions[EMOJIS.ROFLMAO] = new Vector3(-0.018f, -0.062f, -0.11f); emojiPositions[EMOJIS.NEUTRAL] = new Vector3(0.00f, 0.06f, -0.11f); //TODO: testing. positions gets wonky with above data emojiPositions[EMOJIS.SLY] = new Vector3(0.0f, 0.0f, -0.11f); emojiPositions[EMOJIS.KISSY] = new Vector3(0.0f, 0.0f, -0.11f); emojiPositions[EMOJIS.SNORE] = new Vector3(0.0f, 0.0f, -0.11f); emojiPositions[EMOJIS.ROFLMAO] = new Vector3(0.0f, 0.0f, -0.11f); emojiPositions[EMOJIS.NEUTRAL] = new Vector3(0.0f, 0.0f, -0.11f); } moveDirection = (int)MOVE_DIRECTION.LEFT; rb2d = GetComponent <Rigidbody2D>(); sc = GetComponent <SoundCaller>(); lastDirection = Vector2.right; disableFromMiniMapIfNotLocalPlayer(); }
IEnumerator endDay() { feasting = true; //float nightTransitionTime = 3.0f; SoundManager.instance.playSound(SoundManager.SOUNDS.FEAST); StartCoroutine(CameraScript.instance.fade(false, 2, 0.8f)); yield return(new WaitForSeconds(2.25f)); StartCoroutine(MusicManager.instance.silenceMusic()); yield return(new WaitForSeconds(1.25f)); SoundCaller sc = SoundManager.instance.getSoundCaller(); AudioSource nightSoundSource = sc.findFreeAudioSource(); float originalVolume = nightSoundSource.volume; nightSoundSource.clip = SoundManager.instance.normalNightSound; nightSoundSource.Play(); GameState.instance.pressNextDay(); yield return(new WaitForSeconds(1.0f)); float extraSecondsWaited = 0; Dictionary <int, Seed> seeds = GameState.instance.getPlantedSeeds(); List <int> seedPositions = new List <int>(); foreach (int seedPos in seeds.Keys) { seedPositions.Add(seedPos); } while (seedPositions.Count > 0) { int seedToPop = seedPositions[UnityEngine.Random.Range(0, seedPositions.Count)]; if (seeds[seedToPop].daysGrown == seeds[seedToPop].specie.growTime) { SoundManager.instance.playSound(SoundManager.SOUNDS.FARM); } updateSeed(seeds[seedToPop], seedToPop); float delay = UnityEngine.Random.Range(0.2f, 0.95f); yield return(new WaitForSeconds(delay)); extraSecondsWaited += delay; seedPositions.Remove(seedToPop); } yield return(new WaitForSeconds(3.25f - extraSecondsWaited)); nightSoundSource.Stop(); yield return(new WaitForSeconds(2.25f)); StartCoroutine(MusicManager.instance.setVolume(0.1f)); StartCoroutine(CameraScript.instance.fade(true, 2.5f)); yield return(new WaitForSeconds(2.0f)); feasting = false; }
// Shoot (set starting position of bullets) public override void Shoot() { // shoot only on bulletdelay reset if (this.BulletDelay >= 0) { this.BulletDelay--; } // if bullet delay is at 0, create new bullet if (this.BulletDelay <= 0) { // Event handling SoundCaller shotFired = new SoundCaller(SoundManager.Instance.PlayerShootSound); if (this.AttackBonusActive) { Vector2 newLeftBulletPosition = new Vector2(this.Position.X - this.PlayerBulletTexture.Width / 2, this.position.Y + this.Texture.Height / 2); PlayerBullet newLeftBullet = new PlayerBullet(this.PlayerBulletTexture, newLeftBulletPosition, PlayerBulletSpeed); Vector2 newRightBulletPosition = new Vector2(this.Position.X + this.Texture.Width - this.PlayerBulletTexture.Width / 2, this.position.Y + this.Texture.Height / 2); PlayerBullet newRightBullet = new PlayerBullet(this.PlayerBulletTexture, newRightBulletPosition, PlayerBulletSpeed); Vector2 newBulletPosition = new Vector2(this.Position.X + this.Texture.Width / 2 - this.PlayerBulletTexture.Width / 2, this.position.Y + this.Texture.Height / 2); PlayerBullet newBullet = new PlayerBullet(this.PlayerBulletTexture, newBulletPosition, PlayerBulletSpeed); if (this.BulletList.Count < 20) { this.AddBullet(newLeftBullet); this.AddBullet(newRightBullet); this.AddBullet(newBullet); } } else { Vector2 newBulletPosition = new Vector2(this.Position.X + this.Texture.Width / 2 - this.PlayerBulletTexture.Width / 2, this.position.Y + this.Texture.Height / 2); PlayerBullet newBullet = new PlayerBullet(this.PlayerBulletTexture, newBulletPosition, PlayerBulletSpeed); if (this.BulletList.Count < 20) { this.AddBullet(newBullet); } } } // reset delay if (this.BulletDelay == 0) { this.BulletDelay = PlayerBulletDelay; } }
private void Awake() { snowballTimer = new Timer(snowballCooldown); invulTimer = new Timer(invulTime); cc = GetComponent <CapsuleCollider2D>(); energy = maxEnergy; displayedEnergy = energy; energyBadCoroutine = null; walkSoundTimer = new Timer(walkSoundCooldown); sc = GetComponent <SoundCaller>(); rb = GetComponent <Rigidbody2D>(); }
// Use this for initialization void Awake() { if (instance == null) { instance = this; } else if (instance != this) { DestroyObject(gameObject); //Destroy(this); } DontDestroyOnLoad(this); sc = GetComponent <SoundCaller>(); }
public BUTTONS[] buttonIDs; //IMPORTANT! need to be as long as number of buttons void Start() { sc = gameObject.GetComponent <SoundCaller>(); int i = 0; menuObjects = new GameObject[gameObject.GetComponentsInChildren <TextPulse>().Length]; foreach (TextPulse menuObject in gameObject.GetComponentsInChildren <TextPulse>()) { menuObjects[i] = menuObject.gameObject; menuObjects[i].GetComponent <TextPulse>().setButtonInfo(i, (int)buttonIDs[i]); i++; } highlightedButton = 0; menuObjects[highlightedButton].GetComponent <TextPulse>().highlight(); }
// Use this for initialization void Start() { sc = GetComponent <SoundCaller>(); rb2d = GetComponent <Rigidbody2D>(); rb2d.velocity = patrolDirection * patrolSpeed; patrolDirection.Normalize(); curSpriteID = rb2d.velocity.x < 0 ? (int)PATROL_DIRECTION.LEFT : (int)PATROL_DIRECTION.RIGHT; if (rb2d.velocity.y != 0) { curSpriteID = rb2d.velocity.y < 0 ? (int)PATROL_DIRECTION.UP : (int)PATROL_DIRECTION.DOWN; } flashLightRotator = transform.GetChild(0).gameObject; flashLightRotator.transform.rotation = Quaternion.Euler(0, 0, getAngle(patrolDirection)); currentSprite = sprites[curSpriteID]; GetComponent <SpriteRenderer>().sprite = currentSprite; }
void Awake() { sc = GetComponent <SoundCaller>(); }
//Update protected override void Update(GameTime gameTime) { //Allows the Game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } switch (this.GameState) { // UPDATE MENU STATE case State.Menu: { //Get Keyboard State KeyboardState keyState = Keyboard.GetState(); if (keyState.IsKeyDown(Keys.Enter)) { this.GameState = State.Playing; MediaPlayer.Play(this.SM.BgMusic); } if (keyState.IsKeyDown(Keys.Q)) { Environment.Exit(0); } this.sf.Update(gameTime); this.sf.Speed = 1; break; } //UPDATE PLAYING STATE case State.Playing: { this.sf.Speed = Starfield.StarfieldSpeed; // Updating Enemies and checking collision of enemy ship to player ship // Polymorphism - accessing the child class of Enemy prop's and methods; foreach (IEnemy e in this.EnemyList) { // Check if enemyship is colliding with player if (e.BoundingBox.Intersects(this.Player.BoundingBox)) { SoundCaller explosionOccured = new SoundCaller(this.SM.ExplodeSound); // Event handling; this.Player.Health -= e.EnemyShipDamage; this.Player.ResetBonusEffects(); // When player is hit - attack bonus is set to its initial value; e.DestroyObject(); } // Check enemy bullet collision with player ship for (int i = 0; i < e.BulletList.Count; i++) { if (this.Player.BoundingBox.Intersects(e.BulletList[i].BoundingBox)) { this.Player.Health -= e.BulletList[i].Damage; // When player is hit - attack bonus is set to its initial value; this.Player.ResetBonusEffects(); e.BulletList[i].DestroyObject(); } } // Check player bullet collision to enemy ship for (int i = 0; i < this.Player.BulletList.Count; i++) { if (this.Player.BulletList[i].BoundingBox.Intersects(e.BoundingBox)) { e.Health -= this.Player.BulletList[i].Damage * this.Player.AttackPower; this.Player.BulletList[i].DestroyObject(); if (e.Health <= 0) { SoundCaller explosionOccured = new SoundCaller(this.SM.ExplodeSound); // Event handling; this.explosionList.Add(new Explosion(this.Content.Load <Texture2D>("explosion3"), new Vector2(e.Position.X, e.Position.Y))); this.Hud.PlayerScore += e.EnemyPoints; e.DestroyObject(); } } } e.Update(gameTime); } foreach (Explosion ex in this.ExplosionList) { ex.Update(gameTime); } // for each asteroid in our asteroidList, update it and check for collisions foreach (Asteroid a in this.AsteroidList) { // check if any asteroids are colliding with player // if they are set visible to false if (a.BoundingBox.Intersects(this.Player.BoundingBox)) { this.Player.Health -= a.Damage; this.Player.ResetBonusEffects(); // When player is hit - attack bonus is set to its initial value; a.DestroyObject(); } //Iterate through our bulletList if any asteroids come in contacts with trhese bulets, destroy bulets and asteroids for (int i = 0; i < this.Player.BulletList.Count; i++) { if (a.BoundingBox.Intersects(this.Player.BulletList[i].BoundingBox)) { SoundCaller explosionOccured = new SoundCaller(this.SM.ExplodeSound); // Event handling; this.explosionList.Add(new Explosion(this.Content.Load <Texture2D>("explosion3"), new Vector2(a.Position.X, a.Position.Y))); this.Hud.PlayerScore += Asteroid.AsteroidPoints; a.DestroyObject(); this.Player.BulletList[i].DestroyObject(); } } a.Update(gameTime); } //for each bonus in our bonusesList, update it and check for collisions foreach (BonusObject bonus in this.BonusesList) { //check if any bonuses are colliding with player // if they are set visible to false if (bonus.BoundingBox.Intersects(this.Player.BoundingBox)) { bonus.DistributeBonusEffect(this.Player); bonus.DestroyObject(); } bonus.Update(gameTime); } // If a player health is zero - game over; try { if (this.Player.Health <= 0) { throw new DeadPlayerException(this.Player.Health); } } catch (DeadPlayerException) { this.GameState = State.Gameover; } this.Hud.Update(gameTime); this.Player.Update(gameTime); this.sf.Update(gameTime); this.ManageExplosions(); this.LoadAsteroids(); this.LoadEnemies(); this.LoadBonuses(); break; } //UPDATE GAME OVER STATE case State.Gameover: { //Get Keyboard State KeyboardState keyState = Keyboard.GetState(); this.sf.Update(gameTime); this.sf.Speed = 5; if (keyState.IsKeyDown(Keys.Escape)) { this.enemyList.Clear(); this.asteroidList.Clear(); this.Player.ClearBullets(); this.bonusesList.Clear(); this.explosionList.Clear(); this.Player.ResetStartPosition(); this.Player.Health = Player.InitialPlayerHealth; this.Hud.PlayerScore = HUD.InititalPlayerScore; this.GameState = State.Menu; } // Stop music MediaPlayer.Stop(); break; } } base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.M)) { if (!this.MuteWasPressed) { this.MuteWasPressed = true; this.DontPlayMusic = !this.DontPlayMusic; } } else { this.MuteWasPressed = false; } if (!this.DontPlayMusic) { MediaPlayer.Resume(); } else { MediaPlayer.Pause(); } if (this.GameState == DefaultGameType) { if (Keyboard.GetState().IsKeyDown(Keys.Enter)) { this.GameState = GameType.Play; } } else if (this.GameState == GameType.Play) { try { if (this.player.IsBeeingDamaged && this.player.CurrentSpeed > 0) { if (!this.player.IsOutOfRoad) { SoundCaller obstacle = new SoundCaller(this.SoundManager.ObstacleSound); } this.player.Color = Color.Red; if (this.player.Score >= 1) { this.player.Score--; } this.player.Health--; } else { this.player.Color = Color.White; } foreach (Obstacle obstacle in this.ObstaclesList) { obstacle.DetectCollision(this.player); obstacle.Update(gameTime, this.player.CurrentSpeed); } } catch (CrashException) { this.GameState = GameType.Crash; } foreach (IBonus bonus in this.BonusesList) { if (this.player.BoundingBox.Intersects(bonus.BoundingBox)) { if (bonus.GetType().Name == ScoreBonusName) { SoundCaller bonusCollected = new SoundCaller(this.SoundManager.BonusSound); this.player.Score += ScoreAndHealth.ScoreBonus; bonus.DestroyObject(); } else if (this.player.Health < ScoreAndHealth.InitialPlayerHealth) { SoundCaller bonusCollected = new SoundCaller(this.SoundManager.BonusSound); this.player.Health += ScoreAndHealth.HealthBonus; if (this.player.Health > ScoreAndHealth.InitialPlayerHealth) { this.player.Health = ScoreAndHealth.InitialPlayerHealth; } bonus.DestroyObject(); } } bonus.Update(gameTime, this.player.CurrentSpeed); } if (this.progressPlayer.PositionY == 0) { this.GameState = GameType.End; } this.road.Update(gameTime, this.player.CurrentSpeed); this.player.Update(gameTime); this.LoadBonuses(); this.LoadObstacles(); this.hud.Update(gameTime, this.player.CurrentSpeed); this.AddGameObject(this.road); foreach (var item in this.BonusesList) { this.AddGameObject(item); } this.AddGameObject(this.player); this.AddGameObject(this.progressPlayer); this.AddGameObject(this.hud); } else if (this.GameState == GameType.Crash) { if (Keyboard.GetState().IsKeyDown(Keys.Enter)) { this.Exit(); } } else if (this.GameState == GameType.End) { if (Keyboard.GetState().IsKeyDown(Keys.Enter)) { this.Exit(); } } else if (this.GameState == GameType.End) { if (Keyboard.GetState().IsKeyDown(Keys.Enter)) { this.Exit(); } } base.Update(gameTime); }
// Use this for initialization void Start() { soundTimer = new Timer(moveSoundDelay); r2d = GetComponent <Rigidbody2D>(); sc = GetComponent <SoundCaller>(); }