public static void PlaySafe(this SoundEffect se)
 {
     if (_soundOn)
     {
         se?.Play();
     }
 }
Exemplo n.º 2
0
 public void DoThunk(SoundEffect thunk)
 {
     thunk?.Play();
     Pos = Position.Perch;
     _retirementTimeLeft = START_RETIREMENT_TIME;
     Level.Laptop.StartStatic();
 }
Exemplo n.º 3
0
        public static void PlaySfx(SoundEffect sfx, float volume = 1, float pitch = 0, float pan = 0)
        {
            if (!Assets.LoadSfx)
            {
                return;
            }

            sfx?.Play(MathUtils.Clamp(0, 1, volume * SfxVolume * MasterVolume), pitch, pan);
        }
        /// <summary>
        /// 新しい弾(Mover)を作成するときライブラリから呼ばれる
        /// </summary>
        public Bullet CreateBullet()
        {
            _shoot?.Play();

            var mover = new Mover(_gameRef, this);

            movers.Add(mover);  //Moverを登録
            mover.Initialize(); //初期化
            return(mover);
        }
Exemplo n.º 5
0
        public Wave(Actor actor) : base(actor)
        {
            speed      = new Vector2(1, 0) * (float)actor.info.speed * 46;
            damage     = actor.info.damage;
            damageType = actor.info.damageType;
            effects    = actor.info.effects;

            sound = actor.info.sound;
            sound?.Play();
        }
Exemplo n.º 6
0
 public void Clone()
 {
     if ((speed.X > 0 && position.X < 5) || (speed.X < 0 && position.X > 0))
     {
         Wave newWave = (Wave)this.MemberwiseClone();
         newWave.Reset();
         newWave.position += new Vector2(1, 0) * Math.Sign(speed.X);
         stage.addProjectile(newWave, newWave.position);
         sound?.Play();
     }
 }
Exemplo n.º 7
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            music = Asset.Load<SoundMusic>("MusicFishLampMp3");
            effect = Asset.Load<SoundEffect>("EffectBip");
            music.IsLooped = true;
            effect.IsLooped = true;
            music.Play();
            effect.Play();
        }
Exemplo n.º 8
0
        public void Update(GameTime gameTime, Vector2 viewPort, List <Ball> balls, int width, int height)
        {
            var boundarySize = BoundarySize;

            PlayerStats.State.Health = Goal.Health;
            PlayerStats.State.Score  = Paddle.Score;
            if (Goal.Died)
            {
                return;
            }

            Goal.Update(balls, width, height);

            if (Goal.Health <= 0 && !Goal.Died)
            {
                death?.Play();
                Goal.Died = true;
            }



            var ball = balls.OrderBy(p => Vector2.Distance(p.Position, Goal.Rectangle.Center)).First();

            var width4  = width / 4f;
            var height4 = height / 4f;


            if (this.State.Position == Paddles.Left)
            {
                Paddle.Update(gameTime, new Vector2(0, boundarySize), viewPort - new Vector2(width4 * 3, boundarySize), ball, width, height);
            }
            else if (State.Position == Paddles.Right)
            {
                Paddle.Update(gameTime, new Vector2(width4 * 3, boundarySize), viewPort - new Vector2(0, boundarySize), ball, width, height);
            }
            else if (State.Position == Paddles.Top)
            {
                Paddle.Update(gameTime, new Vector2(boundarySize, 0), viewPort - new Vector2(boundarySize, height4 * 3), ball, width, height);
            }
            else
            {
                Paddle.Update(gameTime, new Vector2(boundarySize, height4 * 3), viewPort - new Vector2(boundarySize, 0), ball, width, height);
            }
        }
Exemplo n.º 9
0
        internal void HitSurface(SurfaceType surfaceType)
        {
            Instructions.Clear();

            var         randomInt = FlatRedBallServices.Random.Next(2) + 1;
            SoundEffect file      = null;

            if (surfaceType == SurfaceType.Water)
            {
                file = (SoundEffect)GetFile($"cannonballsink0{randomInt}");
            }
            else
            {
                // do we have ground hits sfx? Not yet, but if we do, add the logic here to pick one of the sounds
            }

            file?.Play();

            // broadcast this so that a collision can occur at screen level
            Destroy();
        }
Exemplo n.º 10
0
 public static void PlayE3Spawn()
 {
     e3NoteSpawn.Play();
 }
Exemplo n.º 11
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here

            KeyboardState ks = Keyboard.GetState();



            batLeft.BatSet   = ball.Reset;
            batRight.BatSet  = ball.Reset;
            batLeft.BatMove  = ball.EnterPressed;
            batRight.BatMove = ball.EnterPressed;


            if (enterFlag == false)
            {
                if (ks.IsKeyDown(Keys.Enter))
                {
                    enterFlag         = true;
                    ball.EnterPressed = enterFlag;
                }
            }

            if (ks.IsKeyDown(Keys.A))
            {
                batLeft.BatUp();
            }

            if (ks.IsKeyDown(Keys.Z))
            {
                batLeft.BatDown();
            }

            if (ks.IsKeyDown(Keys.Up))
            {
                batRight.BatUp();
            }

            if (ks.IsKeyDown(Keys.Down))
            {
                batRight.BatDown();
            }

            if (ball.Reset == true)
            {
                enterFlag = false;
            }

            if (ks.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            string rightScoreMsg = rightPlayer + ": " + ball.RightScore.ToString();

            rightScore.Message = rightScoreMsg;

            string leftScoreMsg = leftScoreMsg = leftPlayer + ": " + ball.leftScore.ToString();

            leftScore.Message = leftScoreMsg;

            if (ball.rightScore == WINNING_SCORE)
            {
                if (win.Message == "")
                {
                    applause.Play();
                }

                winMsg      = rightPlayer + " wins!\nPress spacebar to restart";
                win.Message = winMsg;

                spaceBarLock = true;
            }
            if (ball.leftScore == WINNING_SCORE)
            {
                if (win.Message == "")
                {
                    applause.Play();
                }

                winMsg       = leftPlayer + " wins!\nPress spacebar to restart";
                win.Message  = winMsg;
                enterFlag    = true;
                spaceBarLock = true;
            }

            if (win.Message != "")
            {
                ball.EnterPressed = false;
            }

            if (spaceBarLock)
            {
                if (ks.IsKeyDown(Keys.Space))
                {
                    gameReset();
                }
            }



            base.Update(gameTime);
        }
Exemplo n.º 12
0
        /*
         * ‘******************************************************
         * ‘***  detectCollision
         * ‘***  Zach Languell, Kevin Anderson, Holley Melchor, Blake Young
         * ‘******************************************************
         * ‘*** The purpose of this function is to detect collision amongst interactable objects as dictated from requirements
         * ‘*** Method Inputs:
         * ‘***    gameTime
         * ‘*** Return value:
         * ‘***    NA
         * ‘******************************************************
         * ‘*** 11/20/2015
         * ‘******************************************************
         */
        protected void detectCollision(GameTime gameTime)
        {
            collisionTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (player.carriedObject == null && player.IsDiving())
            {
                foreach (ScoringObject s in scoringObjectSpawner.scoringObjects)
                {
                    if (player.collisionRectangle.Intersects(s.collisionRectangle))
                    {
                        //if(pixelPerfect(player.texture, s.texture, player.collisionRectangle, s.collisionRectangle, player.rectangle, s.rectangle))
                        //{
                        player.IsDiveComplete = true;
                        player.carriedObject  = s;
                        s.setStateCarried();
                        s.lastPosition.Y = s.position.Y;
                        if (s.isbone)
                        {
                            pickUpSound.Play();
                        }
                        else
                        {
                            turtlePickUp.Play();
                        }
                        break;
                        // }
                    }
                }
            }
            else if (!player.IsDiving())
            {
                foreach (EnemyObject e in enemySpawner.enemyObjects)
                {
                    if (player.collisionRectangle.Intersects(e.collisionRectangle))
                    {
                        //if (pixelPerfect(player.texture, e.texture, player.collisionRectangle, e.collisionRectangle, player.rectangle, e.rectangle))
                        // {
                        if (player.carriedObject != null)
                        {
                            player.takeDamage();
                        }

                        else if (collisionTimer > 500)
                        {
                            gameState = GameState.leaderBoard;
                            bgmPlayer.stop();
                            UnloadContent();
                            LoadContent();
                        }
                        collisionTimer = 0;
                        break;
                        //}
                    }
                }
            }

            foreach (ScoringObject s in scoringObjectSpawner.scoringObjects)
            {
                if (s.collisionRectangle.Intersects(tw.collisionRectangle) && s.scoreState == Breaking_Bones.ScoringObject.ScoreState.Dropped)
                {
                    if (s.scoreState == Breaking_Bones.ScoringObject.ScoreState.Dropped)
                    {
                        s.scoreState = Breaking_Bones.ScoringObject.ScoreState.Dead;
                        if (!s.forceDrop)
                        {
                            gainPointSound.Play();
                        }
                        if (s.isbone)
                        {
                            playerScore += s.score * 3;
                        }
                        else
                        {
                            playerScore += s.score * 10;
                        }
                    }
                    break;
                }
            }

            foreach (ScoringObject s in scoringObjectSpawner.scoringObjects)
            {
                foreach (Rock r in rockSpawner.rockObjects)
                {
                    if (s.collisionRectangle.Intersects(r.collisionRectangle) && s.scoreState == Breaking_Bones.ScoringObject.ScoreState.Dropped)
                    {
                        s.scoreState = Breaking_Bones.ScoringObject.ScoreState.Dead;
                        if (s.isbone)
                        {
                            if (!s.forceDrop)
                            {
                                gainPointSound.Play();
                            }
                            playerScore += s.score * 3;
                        }
                        else
                        {
                            turtleDeath.Play();
                            playerScore += s.score;
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 13
0
 public override void Draw(SpriteBatch spriteBatch)
 {
     if (!Main.playerInventory)
     {
         Texture2D Bar   = Revolutions.mod.GetTexture("UI/WhiteLine");
         float     scale = 0.5f;
         NPC       boss  = RevolutionsPlayer.nowBoss;
         RevolutionsPlayer.HthBarTimer -= RevolutionsPlayer.HthBarTimer > 0 ? 1 : 0;
         if ((boss != null && boss.active) != RevolutionsPlayer.lastHthBarStatus && Revolutions.Settings.extraAI && Main.LocalPlayer.active && !RevolutionsPlayer.lastHthBarStatus)
         {
             RevolutionsPlayer.HthBarTimer = 30;
         }
         float       drawPosFix  = 0;
         SoundEffect soundEffect = Revolutions.mod.GetSound("Sounds/Custom/sword");
         if (RevolutionsPlayer.HthBarTimer == 10)
         {
             soundEffect.Play();
         }
         if (RevolutionsPlayer.HthBarTimer != 0)
         {
             drawPosFix = (1 - (30 - RevolutionsPlayer.HthBarTimer) * (30 - RevolutionsPlayer.HthBarTimer) / 900f) * Main.screenWidth * Main.UIScale;
         }
         if (boss != null && boss.active && Main.LocalPlayer.active)
         {
             string text = boss.TypeName;
             if (boss.type == 398)
             {
                 text = Language.GetTextValue("NPCName.MoonLordHead");
             }
             if (boss.type == 125)
             {
                 text = Language.GetTextValue("BuffName.TwinEyesMinion");
             }
             if (boss.type == 126)
             {
                 text = Language.GetTextValue("BuffName.TwinEyesMinion");
             }
             //月主和魔眼的名字特殊处理
             float v = Helper.GetStringLength(Main.fontDeathText, text, 0.8f);
             Terraria.Utils.DrawBorderStringFourWay(spriteBatch, Main.fontDeathText, text,
                                                    0.5f * Main.screenWidth - 0.5f * v - drawPosFix, 50f, Color.White, Color.Transparent, Vector2.Zero, 0.8f);
             text = RevolutionsPlayer.nowBossLifeTrue.ToString() + "/" + RevolutionsPlayer.nowBossLifeMax.ToString();
             int posfix = 0;
             if (v > 269)
             {
                 posfix = 45;
             }
             v = Helper.GetStringLength(Main.fontMouseText, text, 0.8f);
             float a = (float)(Bar.Width * Helper.GetCloserSingle(RevolutionsPlayer.nowBossLife
                                                                  , RevolutionsPlayer.nowBossLifeTrue
                                                                  , Math.Sin(0.1745 * (RevolutionsPlayer.timer2 - 1)), 1) / RevolutionsPlayer.nowBossLifeMax);
             Terraria.Utils.DrawBorderStringFourWay(spriteBatch, Main.fontMouseText, text,
                                                    0.5f * (Main.screenWidth + scale * Bar.Width) - v + drawPosFix, 72f + posfix, Color.White, Color.Transparent, Vector2.Zero, 0.8f);
             spriteBatch.Draw(Bar, new Vector2(0.5f * Main.screenWidth - 0.5f * scale * Bar.Width + drawPosFix, 102.5f), new Rectangle(0, 0, (int)(Bar.Width), Bar.Height), Color.White * 0.33f, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f);
             if (boss.type == ModContent.NPCType <NPCs.Core>())
             {
                 Bar = Revolutions.mod.GetTexture("UI/RainbowLine");
             }
             spriteBatch.Draw(Bar, new Vector2(0.5f * Main.screenWidth - 0.5f * scale * Bar.Width + drawPosFix, 102.5f), new Rectangle(0, 0, (int)a, Bar.Height), Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f);
         }
         RevolutionsPlayer.lastHthBarStatus = (boss != null && boss.active);
     }
 }
Exemplo n.º 14
0
        private void UpdatePlayer(GameTime gameTime)
        {
            player.Update(gameTime);

            // Get Thumbstick Controls
            player.Position.X += currentGamePadState.ThumbSticks.Left.X * playerMoveSpeed;
            player.Position.Y -= currentGamePadState.ThumbSticks.Left.Y * playerMoveSpeed;

            // Use the Keyboard / Dpad
            if (currentKeyboardState.IsKeyDown(Keys.Left) ||
                currentGamePadState.DPad.Left == ButtonState.Pressed)
            {
                player.Position.X -= playerMoveSpeed;
            }
            if (currentKeyboardState.IsKeyDown(Keys.Right) ||
                currentGamePadState.DPad.Right == ButtonState.Pressed)
            {
                player.Position.X += playerMoveSpeed;
            }
            if (currentKeyboardState.IsKeyDown(Keys.Up) ||
                currentGamePadState.DPad.Up == ButtonState.Pressed)
            {
                player.Position.Y -= playerMoveSpeed;
            }
            if (currentKeyboardState.IsKeyDown(Keys.Down) ||
                currentGamePadState.DPad.Down == ButtonState.Pressed)
            {
                player.Position.Y += playerMoveSpeed;
            }

            // Make sure that the player does not go out of bounds
            player.Position.X = MathHelper.Clamp(player.Position.X, 0, GraphicsDevice.Viewport.Width - player.Width);
            player.Position.Y = MathHelper.Clamp(player.Position.Y, 0, GraphicsDevice.Viewport.Height - player.Height);

            // Fire only every interval we set as the fireTime

            if (Keyboard.GetState().IsKeyDown(Keys.Q) ||
                currentGamePadState.Buttons.LeftShoulder == ButtonState.Pressed)
            {
                if (gameTime.TotalGameTime - previousFireTime > fireTime)
                {
                    // Reset our current time
                    previousFireTime = gameTime.TotalGameTime;

                    // Add the projectile, but add it to the front and center of the player
                    AddProjectile(player.Position + new Vector2(player.Width / 2, 0));

                    // Play the laser sound
                    laserSound.Play();
                }
            }
            if (Keyboard.GetState().IsKeyDown(Keys.W) ||
                currentGamePadState.Buttons.LeftStick == ButtonState.Pressed && currentGamePadState.Buttons.RightStick == ButtonState.Pressed)
            {
                if (gameTime.TotalGameTime - previousFireTime > largeFireTime)
                {
                    //Reset our current time
                    previousFireTime = gameTime.TotalGameTime;

                    AddBigProjectile(player.Position + new Vector2(player.Width / 2, 0));
                    // Play the laser sound
                    laserSound.Play();
                }
            }

            if (Keyboard.GetState().IsKeyDown(Keys.E) ||
                currentGamePadState.Buttons.RightShoulder == ButtonState.Pressed)
            {
                if (gameTime.TotalGameTime - previousFireTime > fireTime)
                {
                    //Reset our current time
                    previousFireTime = gameTime.TotalGameTime;

                    AddProjectile(player.Position + new Vector2(player.Width / 2, 0));
                    AddUpProjectile(player.Position + new Vector2(player.Width / 2, 0));
                    AddDownProjectile(player.Position + new Vector2(player.Width / 2, 0));

                    // Play the laser sound
                    laserSound.Play();
                }
            }

            // reset score if player health goes to zero
            if (player.Health <= 0)
            {
                player.Health = 100;
                score         = 0;
            }
        }
Exemplo n.º 15
0
 public virtual void PlaySound(SoundEffect s)
 {
     s.Play();
     hasPlayedSound = true; // the first sound has been played!
 }
Exemplo n.º 16
0
        public override void Update(GameTime gameTime)
        {
            //if (InputHandler.PressedCancel() && _passStep != 8)
            //    Game.Exit();

            if (InputHandler.PressedUp())
            {
                _menuIndex--;

                if (_menuIndex < 0)
                {
                    _menuIndex = _menuText.Length - 1;
                }

                select.Play();
            }

            if (InputHandler.PressedDown())
            {
                _menuIndex = (_menuIndex + 1) % _menuText.Length;
                select.Play();
            }

            if (InputHandler.PressedAction() && _passStep != 9)
            {
                choose.Play();

                // 1 Player
                if (_menuIndex == 0)
                {
                    StateManager.ChangeState(GameStateManager.State.GameplayScreen);
                }
                // Improvements
                else if (_menuIndex == 1)
                {
                    StateManager.ChangeState(GameStateManager.State.ImprovementScreen);
                }
                // Options
                else if (_menuIndex == 2)
                {
                    StateManager.ChangeState(GameStateManager.State.OptionsScreen);
                }
                // Exit
                else if (_menuIndex == 3)
                {
                    Process.GetCurrentProcess().Kill();
                }
            }

            if (_backgroundMainRectangle.X + Config.Resolution.X <= 0)
            {
                _backgroundMainRectangle.X = _backgroundRightRectangle.X + Config.Resolution.X;
            }

            if (_backgroundRightRectangle.X + Config.Resolution.X <= 0)
            {
                _backgroundRightRectangle.X = _backgroundMainRectangle.X + Config.Resolution.X;
            }

            /*
             * if (_backgroundMainRectangle.Y + _backgroundImage.Height <= 0)
             *  _backgroundMainRectangle.Y = _backgroundTopRectangle.Y - _backgroundImage.Height;
             *
             * if (_backgroundTopRectangle.Y + _backgroundImage.Height <= 0)
             *  _backgroundTopRectangle.Y = _backgroundMainRectangle.Y - _backgroundImage.Height;
             */


            _backgroundMainRectangle.X  -= (int)(70 * (float)gameTime.ElapsedGameTime.TotalSeconds);
            _backgroundRightRectangle.X -= (int)(70 * (float)gameTime.ElapsedGameTime.TotalSeconds);

            // Cheat and debug mode
            if (!Config.Cheat)
            {
                if ((_passStep == 0 || _passStep == 1) && InputHandler.PressedUp())
                {
                    _passStep++;
                }
                else if ((_passStep == 2 || _passStep == 3) && InputHandler.PressedDown())
                {
                    _passStep++;
                }
                else if ((_passStep == 4 || _passStep == 6) && InputHandler.PressedLeft())
                {
                    _passStep++;
                }
                else if ((_passStep == 5 || _passStep == 7) && InputHandler.PressedRight())
                {
                    _passStep++;
                }
                else if (_passStep == 8 && (InputHandler.PressedCancel() || InputHandler.KeyPressed(Keys.B)))
                {
                    _passStep++;
                }
                else if (_passStep == 9 && (InputHandler.PressedAction() || InputHandler.KeyPressed(Keys.A)))
                {
                    _passStep++;
                }

                if (_passStep == 10)
                {
                    Config.Cheat = true;
                    _passSound.Play();
                }
            }
            else if (InputHandler.KeyDown(Keys.F9))
            {
                Config.Debug = !Config.Debug;
            }

            if (Config.Cheat)
            {
                if (InputHandler.KeyDown(Keys.A) || InputHandler.ButtonDown(Buttons.Y, PlayerIndex.One))
                {
                    PlayerData.Credits += 1000;
                }
            }

            base.Update(gameTime);
        }
Exemplo n.º 17
0
        private void CheckCollision(IncomingDots[] enemyDotList, float timeDelta, Vector2 screenCenter)
        {
            for (int i = 0; i < enemyDotList.Length; i++)
            {
                if (enemyDotList[i].hasBeenPlaced && enemyDotList[i].isAlive)
                {
                    enemyDotList[i].Update(timeDelta);
                }

                if (enemyDotList[i].isAlive)
                {
                    if (enemyDotList[i].spawnPosition.Y >= 950)
                    {
                        enemyRandom = r.Next(6) + 1;
                        switch (enemyRandom)
                        {
                        case 1:
                            dotHitSound1.Play();
                            break;

                        case 2:
                            dotHitSound2.Play();
                            break;

                        case 3:
                            dotHitSound3.Play();
                            break;

                        case 4:
                            dotHitSound4.Play();
                            break;

                        case 5:
                            dotHitSound5.Play();
                            break;

                        case 6:
                            dotHitSound6.Play();
                            break;
                        }

                        enemyDotList[i].isAlive = false;

                        if (player.currentColor == Player.Colors.red && (enemyDotList[i].color == IncomingDots.possibleColors.red ||
                                                                         enemyDotList[i].color == IncomingDots.possibleColors.orange ||
                                                                         enemyDotList[i].color == IncomingDots.possibleColors.purple))
                        {
                            enemyDotList[i].isAlive = false;
                        }
                        else if (player.currentColor == Player.Colors.blue && (enemyDotList[i].color == IncomingDots.possibleColors.blue ||
                                                                               enemyDotList[i].color == IncomingDots.possibleColors.green ||
                                                                               enemyDotList[i].color == IncomingDots.possibleColors.purple))
                        {
                            enemyDotList[i].isAlive = false;
                        }
                        else if (player.currentColor == Player.Colors.yellow && (enemyDotList[i].color == IncomingDots.possibleColors.yellow ||
                                                                                 enemyDotList[i].color == IncomingDots.possibleColors.orange ||
                                                                                 enemyDotList[i].color == IncomingDots.possibleColors.green))
                        {
                            enemyDotList[i].isAlive = false;
                        }
                        else
                        {
                            player.isAlive = false;
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
 public static void Play(SoundEffect s, float volume, float pitch)
 {
     CheckSound();
     s.Play(volume, pitch, 0);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Updates the burger's location based on mouse. Also fires
        /// french fries as appropriate
        /// </summary>
        /// <param name="gameTime">game time</param>
        /// <param name="mouse">the current state of the mouse</param>
        public void Update(GameTime gameTime, KeyboardState keyboard)
        {
            // burger should only respond to input if it still has health

            if (health > 0)
            {
                // move burger using mouse
                //drawRectangle.X = mouse.X - drawRectangle.Width / 2;
                //drawRectangle.Y = mouse.Y - drawRectangle.Height / 2;

                // move burger using keyboard
                if (keyboard.IsKeyDown(Keys.W) || keyboard.IsKeyDown(Keys.Up))
                {
                    drawRectangle.Y -= GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.A) || keyboard.IsKeyDown(Keys.Left))
                {
                    drawRectangle.X -= GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.S) || keyboard.IsKeyDown(Keys.Down))
                {
                    drawRectangle.Y += GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.D) || keyboard.IsKeyDown(Keys.Right))
                {
                    drawRectangle.X += GameConstants.BurgerMovementAmount;
                }

                // clamp burger in window
                if (drawRectangle.Left < 0)
                {
                    drawRectangle.X = 0;
                }
                if (drawRectangle.Right > GameConstants.WindowWidth)
                {
                    drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
                }
                if (drawRectangle.Top < 0)
                {
                    drawRectangle.Y = 0;
                }
                if (drawRectangle.Bottom > GameConstants.WindowHeight)
                {
                    drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
                }

                // handling of the space key - Creation of a projectile
                // the burger shoots upwards
                if (keyboard.IsKeyDown(Keys.Space) && canShoot)
                {
                    canShoot = false;
                    Projectile friesProjectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries), drawRectangle.Center.X,
                                                                drawRectangle.Center.Y - GameConstants.FrenchFriesProjectileOffset, -GameConstants.FrenchFriesProjectileSpeed);
                    Game1.AddProjectile(friesProjectile);
                    shootSound.Play();
                }

                // update shooting allowed
                // timer concept (for animations) introduced in Chapter 7
                // i placed the canshoot check inside the health>0 because, You should only if the burger is "alive"
                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                    //I used >= instead of just ==
                    if (elapsedCooldownMilliseconds >= GameConstants.BurgerTotalCooldownMilliseconds || keyboard.IsKeyUp(Keys.Space))
                    {
                        elapsedCooldownMilliseconds = 0;
                        canShoot = true;
                    }
                }
            }



            // shoot if appropriate
        }
Exemplo n.º 20
0
        public override void Update(GameTime gameTime)
        {
            switch (gameState)
            {
            case 1:
            {
                KeyboardState ks = Keyboard.GetState();
                if (ks.IsKeyDown(Keys.Enter))
                {
                    Player.isVisible = true;

                    Score.levelNo     = 1;
                    ship.Health       = 200;
                    Score.playerScore = 0;
                    gameState         = 2; // play level 1
                    enemyShipList.Clear();
                    asteroidList.Clear();
                    dieList.Clear();
                    explossionList.Clear();
                    ship.bulletList.Clear();
                    ship.Position = new Vector2(0, tex1.Height - texL.Height);
                }

                break;
            }

            case 2:

            {
                Score.levelNo = 1;

                //asteroids update, check for collisions

                foreach (Asteroids a in asteroidList)
                {
                    if (a.BoundingBox.Intersects(ship.BoundingBox))
                    {
                        //Ship.isVisible = false;
                        //player die
                        dieList.Add(new Die(game1, spriteBatch,
                                            game1.Content.Load <Texture2D>("images/dieUpdated"),
                                            new Vector2(ship.Position.X, ship.Position.Y + 15), 5));



                        ship.Position = new Vector2(0, tex1.Height - texL.Height);
                        ship.Health  -= 20;
                        a.IsVisible   = false;
                    }
                    //check through bullet list
                    for (int i = 0; i < ship.bulletList.Count; i++)
                    {
                        if (a.BoundingBox.Intersects(ship.bulletList[i].BoundingBox))
                        {
                            bombSound.Play();
                            explossionList.Add(new Explossion(game1, spriteBatch,
                                                              game1.Content.Load <Texture2D>("images/explosion3"),
                                                              new Vector2(a.Position.X, a.Position.Y)));
                            Score.playerScore += 10;
                            a.IsVisible        = false;
                            ship.bulletList.ElementAt(i).IsVisible = false;
                        }
                    }

                    //die.Update(gameTime);
                    a.Update(gameTime);
                }
                if (ship.Health <= 0)
                {
                    Game1.sat = false;
                    gameState = 1;        // gameover
                }
                if (Score.playerScore == 200 && ship.Health != 0)
                {
                    gameState = 3;           //complete level 1
                }
                foreach (Die d in dieList)
                {
                    d.Update(gameTime);
                }
                foreach (Explossion ex in explossionList)
                {
                    ex.Update(gameTime);
                }
                DieManager();
                ExplossionManager();
                LoadAsteroids();
                base.Update(gameTime);

                break;
            }

            case 3:
            {
                float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
                timer -= elapsed;
                if (timer < 0)
                {
                    yes = true;
                    //Timer expired, execute action
                    timer = TIMER;           //Reset Timer
                }
                //ship.Health = 200;
                //Score.playerScore = 0;
                Score.levelNo = 2;
                //base.Update(gameTime);
                sb2.Update(gameTime);
                asteroidList.Clear();
                dieList.Clear();
                explossionList.Clear();
                ship.bulletList.Clear();
                ship.Position = new Vector2(0, tex1.Height - texL.Height);

                //gameState = 4; //level 2
                break;
            }

            case 4:
            {
                foreach (Enemy e in enemyShipList)
                {
                    //enemyship collision with player ship
                    if (e.BoundingBox.Intersects(ship.BoundingBox))
                    {
                        if (ship.Health != 0)
                        {
                            ship.Health -= 40;
                            e.IsVisible  = false;
                        }
                    }
                    //enemy bullet collission with player ship
                    for (int i = 0; i < e.bulletList.Count; i++)
                    {
                        if (ship.BoundingBox.Intersects(e.bulletList[i].BoundingBox))
                        {
                            //player die
                            dieList.Add(new Die(game1, spriteBatch,
                                                game1.Content.Load <Texture2D>("images/dieUpdated"),
                                                new Vector2(ship.Position.X, ship.Position.Y + 15), 5));

                            ship.Health -= enemyBulletDamage;
                            e.bulletList[i].IsVisible = false;

                            e.IsVisible   = false;
                            ship.Position = new Vector2(0, tex1.Height - texL.Height);
                        }
                    }

                    //player bullet collission with enemy ship
                    for (int i = 0; i < ship.bulletList.Count; i++)
                    {
                        if (ship.bulletList[i].BoundingBox.Intersects(e.BoundingBox))
                        {
                            bombSound.Play();
                            explossionList.Add(new Explossion(game1, spriteBatch,
                                                              game1.Content.Load <Texture2D>("images/explosion3"),
                                                              new Vector2(e.Position.X, e.Position.Y)));
                            Score.playerScore           += 20;
                            ship.bulletList[i].IsVisible = false;
                            e.IsVisible = false;
                        }
                    }
                    e.Update(gameTime);
                }

                foreach (Die d in dieList)
                {
                    d.Update(gameTime);
                }

                foreach (Explossion ex in explossionList)
                {
                    ex.Update(gameTime);
                }

                if (ship.Health <= 0)
                {
                    Game1.sat = false;         // game over
                    gameState = 1;
                }
                DieManager();
                ExplossionManager();
                LoadAsteroids();
                LoadEnemy();
                sb2.Update(gameTime);
                base.Update(gameTime);
                break;
            }
            }
        }
Exemplo n.º 21
0
        public override void Update(GameTime gameTime)
        {
            KeyboardState keyState = Keyboard.GetState();

            if (!Game1.Instance.Camera.isRoverCamera)
            {
                if (keyState.IsKeyDown(Keys.B))
                {
                    //turn the container for camera laser left
                    roverMovement.RotationCameraLaserYAxis(0.01f);
                }
                if (keyState.IsKeyDown(Keys.M))
                {
                    //turn the container for camera laser right
                    roverMovement.RotationCameraLaserYAxis(-0.01f);
                }
                if (keyState.IsKeyDown(Keys.H))
                {
                    // So the camera/laser can only look up a certain amount
                    if (roverMovement.cameraLaserContainerXaxisRotation.Motor.Settings.Servo.Goal >= -maximumTurnAngle)
                    {
                        roverMovement.RotationXAxis(-0.01f, right);
                    }
                }
                if (keyState.IsKeyDown(Keys.N))
                {
                    // So the camera/laser can only look down a certain amount
                    if (roverMovement.cameraLaserContainerXaxisRotation.Motor.Settings.Servo.Goal <= maximumTurnAngle)
                    {
                        roverMovement.RotationXAxis(0.01f, right);
                    }
                }
            }

            if (keyState.IsKeyDown(Keys.F))
            {
                //the drill cylinder looks up
                SetDrillOrientation(-0.01f);
            }
            if (keyState.IsKeyDown(Keys.V))
            {
                //the drill cylinder looks down
                SetDrillOrientation(0.01f);
            }

            if (keyState.IsKeyDown(Keys.Space))
            {
                //create the laser to shoot & add to game
                Lazer laser = new Lazer();
                laserShot.Play();
                laser.pos  = cameraLaserContainer.body.Position;
                laser.look = GetLaserLook();
                Game1.Instance.Children.Add(laser);
            }

            //code taken from bepu physics demo suspensioncardemo.cs and adapted for this project
            roverMovement.steeringMotor1.Settings.Servo.BaseCorrectiveSpeed = 3 + 7 * Math.Min(roverMovement.steeringMotor1.ConnectionB.AngularVelocity.Length() / 100, 1);
            roverMovement.steeringMotor2.Settings.Servo.BaseCorrectiveSpeed = 3 + 7 * Math.Min(roverMovement.steeringMotor2.ConnectionB.AngularVelocity.Length() / 100, 1);

            if (keyState.IsKeyDown(Keys.Down))
            {
                //move rover backward
                roverMovement.MoveForwardBackward(-driveSpeed);
                if (Game1.Instance.Camera.isRoverCamera)
                {
                    SetRoverCamera(0);
                }
            }
            else if (keyState.IsKeyDown(Keys.Up))
            {
                //move rover forward
                roverMovement.MoveForwardBackward(driveSpeed);
                if (Game1.Instance.Camera.isRoverCamera)
                {
                    SetRoverCamera(0);
                }
            }
            else
            {
                //turn driving motor off
                roverMovement.SetMotorActive(false);
            }

            if (keyState.IsKeyDown(Keys.Left))
            {
                //turn rover left
                roverMovement.TurnLeftRight(maximumTurnAngle);
                if (Game1.Instance.Camera.isRoverCamera)
                {
                    SetRoverCamera(0.01f);
                }
            }
            else if (keyState.IsKeyDown(Keys.Right))
            {
                //turn rover right
                roverMovement.TurnLeftRight(-maximumTurnAngle);
                if (Game1.Instance.Camera.isRoverCamera)
                {
                    SetRoverCamera(-0.01f);
                }
            }
            else
            {
                //Face forward
                roverMovement.steeringMotor1.Settings.Servo.Goal = 0;
                roverMovement.steeringMotor2.Settings.Servo.Goal = 0;
            }

            if (keyState.IsKeyDown(Keys.P))
            {
                if (elapsed > (1.0f / fireRate))
                {
                    //Change to or out of the rovers camera
                    if (Game1.Instance.Camera.isRoverCamera == false)
                    {
                        //set look vector and position of camera and if it is rover camera, changes controls if it is
                        ChangeCameraBeingUsed(GetCameraRoverPosition(), GetLaserLook(), true);
                    }
                    else
                    {
                        //put camera back to normal
                        ChangeCameraBeingUsed(new Vector3(248, 64, -200), new Vector3(0.0f, 0.0f, -1.0f), false);
                    }
                    elapsed = 0.0f;
                }
            }
            elapsed += (float)gameTime.ElapsedGameTime.TotalSeconds; //used so cant chnge between normal camera and rover camera too quickly
            if (elapsed >= 25.0f)
            {
                elapsed = 25.0f;
            }
            if (keyState.IsKeyDown(Keys.E))
            {
                //set the rover to explode
                if (!exploded)
                {
                    Explosion createExplosion = new Explosion(Vector3.Zero, 2000, 30, Game1.Instance.Space);
                    createExplosion.Position = roverBase.body.Position;

                    //disable all the joints
                    foreach (RevoluteJoint joint in roverMovement.roverJoints)
                    {
                        joint.IsActive = false;
                    }
                    foreach (var suspensionString in roverMovement.suspensionSprings)
                    {
                        suspensionString.IsActive = false;
                    }
                    foreach (var joint in roverMovement.joints)
                    {
                        joint.IsActive = false;
                    }
                    foreach (var motor in roverMovement.motors)
                    {
                        motor.IsActive = false;
                    }

                    //start the explosion
                    createExplosion.Explode();
                    explosionSound.Play();
                    exploded = true;
                }
            }
        }
Exemplo n.º 22
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (mInputState.IsNewLeftPressed())
            {
                Input(new Point(Mouse.GetState().X, Mouse.GetState().Y));
            }

            bool bCountScore;

            switch (State)
            {
            case EBoardState.Initialize:
                InitializeBoard();
                break;

            case EBoardState.Process:
                State = CheckBoard().Count >= 1 ? EBoardState.Destroy : EBoardState.Revert;
                break;

            case EBoardState.Swap:
                Swap();
                State = EBoardState.Process;
                break;

            case EBoardState.Revert:
                if (!Table[Focus.X, Focus.Y].IsMoving() && !Table[mDesfocus.X, mDesfocus.Y].IsMoving())
                {
                    Swap();
                    State = EBoardState.Input;
                    Focus = new Point(-1, -1);
                    MissSound.Play();
                }

                break;

            case EBoardState.Destroy:
                bCountScore = true;
                for (var col = 0; col < NumberOfColumns && bCountScore; col++)
                {
                    for (var row = 0; row < NumberOfRows; row++)
                    {
                        if (!Table[col, row].IsMoving() && !Table[col, row].ZoomOut)
                        {
                            continue;
                        }

                        bCountScore = false;
                        break;
                    }
                }

                if (bCountScore)
                {
                    var list = CheckBoard();
                    foreach (var g in list)
                    {
                        g.ZoomOut = true;
                    }

                    State  = EBoardState.Refresh;
                    Score += list.Count * list.Count;
                    WinSound.Play();
                }

                break;

            case EBoardState.Refresh:
                bCountScore = true;
                for (var col = 0; col < NumberOfColumns && bCountScore; col++)
                {
                    for (var row = 0; row < NumberOfRows; row++)
                    {
                        if (!Table[col, row].IsMoving() && !Table[col, row].ZoomOut)
                        {
                            continue;
                        }

                        bCountScore = false;
                        break;
                    }
                }

                if (bCountScore)
                {
                    Focus = new Point(-1, -1);

                    for (var col = 0; col < NumberOfColumns; col++)
                    {
                        for (var row = 0; row < NumberOfRows; row++)
                        {
                            if (Table[col, row].Scale <= 0f)
                            {
                                Table[col, row] = null;
                            }
                        }
                    }

                    for (var row = NumberOfRows - 1; row >= 0; row--)
                    {
                        for (var col = 0; col < NumberOfColumns; col++)
                        {
                            if (Table[col, row] != null)
                            {
                                continue;
                            }

                            for (var i = row - 1; i >= -1; i--)
                            {
                                if (i == -1)
                                {
                                    Table[col, row] = new Gem(Game, (EGemType)mRandom.Next(0, 7), Mapping(new Point(col, -1)));
                                    Table[col, row].SetMove(Mapping(new Point(col, row)));
                                }
                                else if (Table[col, i] != null)
                                {
                                    Table[col, row] = Table[col, i];
                                    Table[col, i]   = null;
                                    Table[col, row].SetMove(Mapping(new Point(col, row)));
                                    break;
                                }
                            }
                        }
                    }

                    if (CheckBoard().Count == 0)
                    {
                        State = CheckMovable() ? EBoardState.Input : EBoardState.Initialize;
                    }
                    else
                    {
                        State = EBoardState.Destroy;
                    }
                }

                break;
            }

            UpdateTable(gameTime);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            // TODO: Add your update logic here
            //Reads The Joypads
            GamePadState pad_p1 = GamePad.GetState(PlayerIndex.One);
            //Reads GamePad 1
            // pad[1] = GamePad.GetState(PlayerIndex.Two);                         //Reads GamePad 2


            const float friction = .8f;

            if (gameover)
            {
                music.Play();
            }

            if (!gameover)
            {
                if (pad_p1.Buttons.Back == ButtonState.Pressed)
                {
                    gameover = true;
                }

                //Move Two Bats


                if (!pad_p1.IsConnected)
                {
                    if (bat.position.X > ball.position.X)
                    {
                        bat.velocity.X -= bat.power;
                    }
                    else
                    {
                        bat.velocity.X += bat.power;
                    }
                }

                //Move The Bats Based On Joypad Input
                //  bat[i].position.Y -= pad[i].ThumbSticks.Left.Y * bat[i].power;
                bat.velocity.X += pad_p1.ThumbSticks.Left.X * bat.power;
                bat.position   += bat.velocity;

                bat.velocity *= friction;

                //Alter Bat Direction When Bat Hits Bounderies
                //Bat Hits The Bottom Of The Screen
                if (bat.position.Y > displayheight - bat.rect.Height / 2)
                {
                    bat.position.Y = displayheight - bat.rect.Height / 2;
                    bat.velocity.Y = 0;
                }
                //Bat Hits The Top Of The Screen
                if (bat.position.Y < bat.rect.Height / 2)
                {
                    bat.position.Y = bat.rect.Height / 2;
                    bat.velocity.Y = 0;
                }

                if (bat.position.X > displaywidth - bat.rect.Width / 2)
                {
                    bat.position.X = displaywidth - bat.rect.Width / 2;
                    bat.velocity.X = 0;
                }
                if (bat.position.X < bat.rect.Width / 2)
                {
                    bat.position.X = bat.rect.Width / 2;
                    bat.velocity.X = 0;
                }

                //Set The Bat Rectangle To The Current Position
                bat.rect.X = (int)bat.position.X;
                bat.rect.Y = (int)bat.position.Y;

                //Create Bounding Box
                bat.bbox = new BoundingBox(new Vector3(bat.position.X - bat.rect.Width / 2, bat.position.Y - bat.rect.Height / 2, 0),
                                           new Vector3(bat.position.X + bat.rect.Width / 2, bat.position.Y + bat.rect.Height / 2, 0));



                ball.position += ball.velocity;                 //Move The Ball
                ball.rotation += ball.rotationspeed;            //Spins Ball
                ball.velocity *= 1.0005f;                       //Speeds Ball Up Over Time


                //If The Ball Hits The Top Or The Bottom Of The Screen Reverse Its Direction On The Y Axis
                if (ball.position.Y < ball.rect.Height / 2)
                {
                    ball.velocity.Y = -ball.velocity.Y;
                    ball.position.Y = ball.rect.Height / 2;
                }
                if (ball.position.Y > displayheight + ball.rect.Height / 2)
                {
                    lives--;
                    resetball();
                    if (lives <= 0)
                    {
                        gameover = true;
                        if (bat.score > highscore)
                        {
                            highscore = bat.score;
                        }
                    }
                }

                //Check If The Ball Goes Out Either Side
                if (ball.position.X > displaywidth - ball.rect.Width / 2)
                {
                    //  bat[0].score += 5;
                    //  resetball();
                    //  yoda.Play();
                    ball.position.X = displaywidth - ball.rect.Height / 2;
                    ball.velocity.X = -ball.velocity.X;
                }


                if (ball.position.X < ball.rect.Width / 2)
                {
                    // bat[1].score += 5;
                    //  resetball();
                    // darth.Play();
                    ball.position.X = ball.rect.Width / 2;
                    ball.velocity.X = -ball.velocity.X;
                }



                float ballspeed = ball.velocity.Length();
                ball.velocity.Normalize();

                Boolean hitball = false;

                //Create BoundingSphere Around The Ball
                ball.bsphere = new BoundingSphere(ball.position, ball.rect.Width / 2);



                // Bounce Ball Off Bat 1
                if (bat.bbox.Intersects(ball.bsphere) && bat.position.Y >= ball.position.Y)
                {
                    hitball         = true;
                    ball.velocity.Y = -Math.Abs(ball.velocity.Y);
                    ball.velocity.X = (ball.position.X - bat.position.X) / 40f;//Force Ball To Go Left
                    // ball.velocity.Y += (ball.position.Y - bat[1].position.Y) / 40f;
                    lightsabre.Play();
                    bat.vibration = 1f;
                }

                for (int y = 0; y < rows; y++)
                {
                    for (int x = 0; x < columns; x++)
                    {
                        brick[x, y].bbox = new BoundingBox(new Vector3(brick[x, y].rect.X - brick[x, y].rect.Width / 2, brick[x, y].rect.Y - brick[x, y].rect.Height / 2, 0),
                                                           new Vector3(brick[x, y].rect.X + brick[x, y].rect.Width / 2, brick[x, y].rect.Y + brick[x, y].rect.Height / 2, 0));

                        if (ball.bsphere.Intersects(brick[x, y].bbox) && brick[x, y].visible)
                        {
                            hitball = true;

                            if (ball.oldposition.Y - ball.rect.Height / 2 > brick[x, y].rect.Y + brick[x, y].rect.Height / 2)
                            {
                                ball.velocity.Y = Math.Abs(ball.velocity.Y);
                            }
                            if (ball.oldposition.Y + ball.rect.Height / 2 < brick[x, y].rect.Y - brick[x, y].rect.Height / 2)
                            {
                                ball.velocity.Y = -Math.Abs(ball.velocity.Y);
                            }
                            if (ball.oldposition.X + ball.rect.Width / 2 < brick[x, y].rect.X - brick[x, y].rect.Width / 2)
                            {
                                ball.velocity.X = -Math.Abs(ball.velocity.X);
                            }
                            if (ball.oldposition.X - ball.rect.Width / 2 > brick[x, y].rect.X + brick[x, y].rect.Width / 2)
                            {
                                ball.velocity.X = Math.Abs(ball.velocity.X);
                            }

                            brick[x, y].visible = false;

                            bat.score += 5;
                            brickcount--;

                            if (brickcount <= 0)
                            {
                                resetlevel();
                            }
                        }

                        brick[x, y].rect.X += batmove;

                        if (brickcount == 5 && batmove == 0)
                        {
                            batmove = 5;
                        }

                        if (brick[x, y].rect.X > displaywidth - brick[x, y].rect.Width / 2)
                        {
                            batmove = -Math.Abs(batmove);
                        }
                        else if (brick[x, y].rect.X < brick[x, y].rect.Width / 2)
                        {
                            batmove = Math.Abs(batmove);
                        }
                    }
                }



                GamePad.SetVibration(PlayerIndex.One, bat.vibration, bat.vibration);

                if (bat.vibration > 0)
                {
                    bat.vibration -= 0.1f;
                }


                ball.velocity.Normalize();
                ball.velocity *= ballspeed;

                if (!hitball)
                {
                    ball.oldposition = ball.position;
                }
                else
                {
                    ball.position = ball.oldposition;
                }

                //Set Position Of Ball Rectangle To Match Its Position For Drawing Purposes
                ball.rect.X = (int)ball.position.X;
                ball.rect.Y = (int)ball.position.Y;

                //If Either Player Reaches Maxscore, End Game
                if (lives == 0)
                {
                    winner.Play();
                    gameover = true;

                    //winner.Play();
                }
            }
            else
            {
                //Game Is Over
                //Start Game Again When User Presses Start

                if (pad_p1.Buttons.Start == ButtonState.Pressed)
                {
                    resetgame();
                }
                if (pad_p1.Buttons.Back == ButtonState.Pressed)
                {
                    this.Exit();
                }
            }

            base.Update(gameTime);
        }
Exemplo n.º 24
0
 public virtual void PlaySound(SoundEffect s, float volume)
 {
     s.Play(volume, 0, 0);
     hasPlayedSound = true; // the first sound has been played!
 }
Exemplo n.º 25
0
    double PalloLiikkuuAani(SoundEffect aani)
    {
        // tulkkaa x,y ja nopeus äänenvoimakkuudeksi, stereo-efektiksi ja toistonopeudeksi
        double odotus = 0.5 - pallonNopeus / 3.0;
        double toistonopeus = (-0.5 + pallonNopeus) / 5.0;
        double volume = 0.33 + pallonSijaintiY / 1.5;
        double panorointi = pallonSijaintiX*2.0-1.0;

        //MessageDisplay.Add(String.Format("pan:{0:F2}, vol:{1:F2}, pitch:{2:F2}, , wait:{3:F2}", panorointi, volume, toistonopeus, odotus));
        aani.Play(volume, toistonopeus, panorointi);

        return odotus * SAMPLENPITUUS_KERROIN;
    }
Exemplo n.º 26
0
        private static void PerformKiss(NPC npc, Vector2 midpoint, string partner)
        {
            int    spouseFrame = 28;
            bool   facingRight = true;
            string name        = npc.Name;

            if (name == "Sam")
            {
                spouseFrame = 36;
                facingRight = true;
            }
            else if (name == "Penny")
            {
                spouseFrame = 35;
                facingRight = true;
            }
            else if (name == "Sebastian")
            {
                spouseFrame = 40;
                facingRight = false;
            }
            else if (name == "Alex")
            {
                spouseFrame = 42;
                facingRight = true;
            }
            else if (name == "Krobus")
            {
                spouseFrame = 16;
                facingRight = true;
            }
            else if (name == "Maru")
            {
                spouseFrame = 28;
                facingRight = false;
            }
            else if (name == "Emily")
            {
                spouseFrame = 33;
                facingRight = false;
            }
            else if (name == "Harvey")
            {
                spouseFrame = 31;
                facingRight = false;
            }
            else if (name == "Shane")
            {
                spouseFrame = 34;
                facingRight = false;
            }
            else if (name == "Elliott")
            {
                spouseFrame = 35;
                facingRight = false;
            }
            else if (name == "Leah")
            {
                spouseFrame = 25;
                facingRight = true;
            }
            else if (name == "Abigail")
            {
                spouseFrame = 33;
                facingRight = false;
            }

            bool right = npc.position.X < midpoint.X;

            if (npc.position == midpoint)
            {
                right = String.Compare(npc.Name, partner) < 0;
            }
            else if (npc.position.X == midpoint.X)
            {
                right = npc.position.Y > midpoint.Y;
            }

            bool flip = (facingRight && !right) || (!facingRight && right);

            int offset = 24;

            if (right)
            {
                offset *= -1;
            }

            npc.position.Value = new Vector2(midpoint.X + offset, midpoint.Y);

            int delay = 1000;

            npc.movementPause = delay;
            npc.Sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame>
            {
                new FarmerSprite.AnimationFrame(spouseFrame, delay, false, flip, new AnimatedSprite.endOfAnimationBehavior(npc.haltMe), true)
            });
            npc.doEmote(20, true);
            if (ModEntry.config.RealKissSound && kissEffect != null)
            {
                float distance = 1f / ((Vector2.Distance(midpoint, Game1.player.position) / 256) + 1);
                float pan      = (float)(Math.Atan((midpoint.X - Game1.player.position.X) / Math.Abs(midpoint.Y - Game1.player.position.Y)) / (Math.PI / 2));
                //ModEntry.PMonitor.Log($"kiss distance: {distance} pan: {pan}");
                kissEffect.Play(distance * Game1.options.soundVolumeLevel, 0, pan);
            }
            else
            {
                Game1.currentLocation.playSound("dwop", NetAudio.SoundContext.NPC);
            }

            npc.Sprite.UpdateSourceRect();
        }
        public override void Update(GameTime gameTime)
        {
            this.MouseGame.Update(gameTime);
            this.GameTimer.Update(gameTime);
            this.VocabularyPalette.Update(gameTime);
            this.MecheBomb.Update(gameTime);

            switch (this.NbVocabulary)
            {
            case 4:
                #region FMOD
                this.BombWickFmodSound(TimeSpan.FromSeconds(60), ref bombWickEvent, ref bombWick_fmod_param);
                #endregion
                this.Increase = (150 / (this.NbVocabulary * 2)) + 1;

                break;

            case 9:
                #region FMOD
                this.BombWickFmodSound(TimeSpan.FromSeconds(90), ref bombWickEvent_2, ref bombWick_fmod_param_2);
                #endregion
                if (this.BoolIncrease)
                {
                    this.Increase     = (150 / (this.NbVocabulary * 2)) + 1;
                    this.BoolIncrease = false;
                }
                else
                {
                    this.Increase     = (150 / (this.NbVocabulary * 2));
                    this.BoolIncrease = true;
                }
                break;

            case 16:
                #region FMOD
                this.BombWickFmodSound(TimeSpan.FromSeconds(120), ref bombWickEvent_3, ref bombWick_fmod_param_3);
                #endregion
                this.Increase = (150 / this.NbVocabulary) + 1;
                if (this.BoolIncrease)
                {
                    this.Increase     = (150 / this.NbVocabulary) + 1;
                    this.BoolIncrease = false;
                }
                else
                {
                    this.Increase     = (150 / this.NbVocabulary);
                    this.BoolIncrease = true;
                }
                break;

            case 25:
                #region FMOD
                this.BombWickFmodSound(TimeSpan.FromSeconds(160), ref bombWickEvent_4, ref bombWick_fmod_param_4);
                #endregion
                this.Increase = 150 / this.NbVocabulary;

                break;

            default:
                throw new Exception("Nombre de carré incorrecte.");
            }


            if (LeitnerGame.Right)
            {
                #region FMOD sound FailedChoice
                FmodFactory.Instance.start(ref rightChoiceEvent);
                FmodFactory.Instance.setParamValue(rightNumber, ref rightChoice_fmod_param);
                rightNumber++;
                wrongNumber = 0;
                if (rightNumber > 4)
                {
                    rightNumber = 0;
                }
                #endregion

                LeitnerGame.Wrong = false;
                LeitnerGame.Right = false;
                this.ProgressBar.Increase(this.Increase);
                Leitner.Instance.SelectedVocabulary.Known = true;
                Leitner.Instance.next();
                this.SelectedVocabularyName.Text = Leitner.Instance.SelectedVocabulary.Nom;
                this.Information.Text            = "Félicitation, tu\nas choisi la bonne\ncouleur.";
                this.Information.Color           = Color.LimeGreen;
            }
            else if (LeitnerGame.Wrong)
            {
                #region FMOD sound FailedChoice
                FmodFactory.Instance.start(ref wrongChoiceEvent);
                FmodFactory.Instance.setParamValue(wrongNumber, ref wrongChoice_fmod_param);
                wrongNumber++;
                rightNumber = 0;
                if (wrongNumber > 4)
                {
                    wrongNumber = 0;
                }
                #endregion

                LeitnerGame.Wrong = false;
                LeitnerGame.Right = false;
                this.ProgressBar.Decrease(this.Increase);
                this.DisplayCorrectVocabulary.VocabularyLeitner.Image = Leitner.Instance.SelectedVocabulary.Image;
                Leitner.Instance.next();
                this.SelectedVocabularyName.Text = Leitner.Instance.SelectedVocabulary.Nom;
                this.Information.Text            = "Dommage, la bonne\ncouleur était : ";
                this.Information.Color           = Color.DarkRed;
            }

            #region FMOD Update Timer

            #endregion

            if (this.GameTimer.Finished && this.MecheBomb.Finished)
            {
                this.BoomImage.Increase(20);
                if (!boomPlayed)
                {
                    BoomSound.Play();
                    boomPlayed = true;
                }
            }

            if (this.BoomImage.Finished)
            {
                this.Result = 1;
            }

            if (this.ProgressBar.Value >= 150)
            {
                this.Result = 2;
            }
        }
Exemplo n.º 28
0
        public void Update(List <ObjCollisionable> Obstacles, SoundEffect JumpEffect, SoundEffect ShootEffect)
        {
            Position += Speed;

            RecPerso.X   = Convert.ToInt32(Position.X) - 90 / 2;
            RecPerso.Y   = Convert.ToInt32(Position.Y) - 90 - (90 / 2);
            SurObject    = false;
            SousObject   = false;
            DroiteObject = false;
            GaucheObject = false;

            #region Obstacle

            if (Obstacles != null)
            {
                foreach (ObjCollisionable Objects in Obstacles)
                {
                    if (RecPerso.isOnTopOf(Objects.DimObj))
                    {
                        Speed.Y   = 0;
                        HasJump   = false;
                        Gravity   = false;
                        SurObject = true;
                        break;
                    }
                    else
                    {
                        Gravity = true;
                    }

                    if (RecPerso.isOnBottomOf(Objects.DimObj))
                    {
                        SousObject = true;
                        Speed.Y    = 0;
                    }
                    else
                    if (RecPerso.isOnRightOf(Objects.DimObj))
                    {
                        DroiteObject = true;
                        Speed.X      = 0;
                    }
                    if (RecPerso.isOnLeftOf(Objects.DimObj))
                    {
                        GaucheObject = true;
                        Speed.X      = 0;
                    }
                }
            }
            #endregion

            if (!Transformation) //bloquer les bouton lors de la transformation
            {
                #region touche W,A,S,D
                if (KeyboardHelper.KeyHold(Keys.W) || KeyboardHelper.KeyHold(Keys.Up) && !HasJump)
                {
                    flip = SpriteEffects.None;

                    if (KeyboardHelper.KeyPressed(Keys.C))
                    {
                        ShootUp = true;
                    }
                    if (!OutofWindow(RecPerso, "W") && !SousObject)
                    {
                        if (!GravityActive)
                        {
                            Speed.Y = -2;
                            Speed.X = 0;
                            flip    = SpriteEffects.None;
                        }
                    }
                    else
                    {
                        Speed.Y = 0;
                    }
                }
                else if (KeyboardHelper.KeyHold(Keys.A) || KeyboardHelper.KeyHold(Keys.Left))
                {
                    if (!OutofWindow(RecPerso, "A") && !DroiteObject)
                    {
                        Speed.X = -2;
                        if (!HasJump && !Gravity)
                        {
                            Speed.Y = 0;
                        }

                        if (KeyboardHelper.KeyHold(Keys.LeftShift))
                        {
                            Speed.X -= 2;
                            WalkigNormal.FrameTimer = CourseFrameTimer;
                        }
                        else
                        {
                            WalkigNormal.FrameTimer = WalkingFrameTimer;
                        }

                        flip = SpriteEffects.FlipHorizontally;
                    }
                    else
                    {
                        Speed.X = 0;
                    }
                }
                else if (KeyboardHelper.KeyHold(Keys.S) || KeyboardHelper.KeyHold(Keys.Down) && !HasJump)
                {
                    if (!OutofWindow(RecPerso, "S") && !SurObject)
                    {
                        Speed.Y = 2;
                        Speed.X = 0;
                        // flip = SpriteEffects.None;
                    }
                    else
                    {
                        Speed.Y = 0;
                    }
                }
                else if (KeyboardHelper.KeyHold(Keys.D) || KeyboardHelper.KeyHold(Keys.Right))
                {
                    if (!OutofWindow(RecPerso, "D") && !GaucheObject)
                    {
                        Speed.X = 2;
                        KeyboardHelper.InputRightPressed();
                        if (!HasJump && !Gravity)
                        {
                            Speed.Y = 0;
                        }

                        if (KeyboardHelper.KeyHold(Keys.LeftShift))
                        {
                            Speed.X += 2;
                            WalkigNormal.FrameTimer = CourseFrameTimer;
                        }
                        else
                        {
                            WalkigNormal.FrameTimer = WalkingFrameTimer;
                        }
                        flip = SpriteEffects.None;
                    }
                    else
                    {
                        Speed.X = 0;
                    }
                }
                else
                {
                    Speed.X = 0;
                    if (!GravityActive)
                    {
                        Speed.Y = 0;
                    }
                    Hula = false;
                }

                #endregion
                #region Space
                if (GravityActive)
                {
                    if (KeyboardHelper.KeyPressed(Keys.Space) && !HasJump && !bCrouch)
                    {
                        Position.Y -= 10;
                        Speed.Y     = -5;
                        if (JumpEffect != null)
                        {
                            JumpEffect.Play();
                        }
                        HasJump = true;
                        Gravity = true;
                    }

                    if (Gravity)
                    {
                        float i = 1;
                        Speed.Y += 0.15f * i;
                    }

                    ///Pour aterrir au sol
                    if (GravityLimit)
                    {
                        if (Position.Y >= 500)
                        {
                            HasJump = false;
                            Gravity = false;
                        }

                        else
                        {
                            Gravity = true;
                        }


                        if (!Gravity)
                        {
                            Speed.Y = 0f;
                        }
                    }
                }

                #endregion
                #region Transformation
                if (KeyboardHelper.KeyPressed(Keys.T))
                {
                    Transformation = true;
                }
                #endregion
                #region Hula
                if (KeyboardHelper.KeyHold(Keys.LeftAlt))
                {
                    Hula = true;
                }
                #endregion

                UpdateBullets();

                #region Shoot
                if (KeyboardHelper.KeyHold(Keys.C) && pastKey.IsKeyUp(Keys.C) && GravityActive)
                {
                    ShootAnim = true;
                    if (ShootEffect != null)
                    {
                        ShootEffect.Play();
                    }
                    Shoot();
                }
                pastKey = Keyboard.GetState();
                #endregion
            }

            else
            {
                Speed.X = 0; Speed.Y = 0;
            }


            #region Animation Par rapport au touche
            bCrouch = false;
            #region Si Position X change
            if (Speed.X != 0)
            {
                if (LoxiTransformation)
                {
                    if (HasJump)
                    {
                        AnimationPlayer.PlayAnimation(JumpForwardTransfo);
                    }
                    else if (Hula)
                    {
                        AnimationPlayer.PlayAnimation(Attack);
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(WalkingTransfo);
                    }
                }
                else
                {
                    if (HasJump)
                    {
                        AnimationPlayer.PlayAnimation(JumpForwardNormal);
                    }
                    else if (ShootAnim)
                    {
                        if (ShootUp)
                        {
                            AnimationPlayer.PlayAnimation(ShootUpwardNormal);
                            if (AnimationPlayer.FrameIndex == 8)
                            {
                                ShootAnim = false;
                                ShootUp   = false;
                            }
                        }
                        else
                        {
                            AnimationPlayer.PlayAnimation(ShootNormal);
                            if (AnimationPlayer.FrameIndex == 10)
                            {
                                ShootAnim = false;
                            }
                        }
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(WalkigNormal);
                    }
                }
            }
            #endregion
            #region Si Position X reste pareil
            else if (Speed.X == 0)
            {
                if (Transformation)
                {
                    AnimationPlayer.PlayAnimation(TransfoNormal);
                    if (AnimationPlayer.FrameIndex == 18)
                    {
                        Transformation = false;
                    }
                    LoxiTransformation = true;
                }
                else
                if (LoxiTransformation)
                {
                    if (HasJump)
                    {
                        AnimationPlayer.PlayAnimation(JumpTransfo);
                    }

                    else if (Hula)
                    {
                        AnimationPlayer.PlayAnimation(Attack);
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(NothingTransfo);
                    }
                }
                else
                {
                    if (HasJump)
                    {
                        AnimationPlayer.PlayAnimation(JumpNormal);
                    }

                    else if (ShootAnim)
                    {
                        if (ShootUp)
                        {
                            AnimationPlayer.PlayAnimation(ShootUpwardNormal);
                            if (AnimationPlayer.FrameIndex == 8)
                            {
                                ShootAnim = false;
                                ShootUp   = false;
                            }
                        }
                        else
                        {
                            AnimationPlayer.PlayAnimation(ShootNormal);
                            if (AnimationPlayer.FrameIndex == 10)
                            {
                                ShootAnim = false;
                            }
                        }
                    }


                    else if (KeyboardHelper.KeyHold(Keys.Down) || KeyboardHelper.KeyHold(Keys.S))
                    {
                        bCrouch = true;
                        AnimationPlayer.PlayAnimation(Crouch);
                    }
                    else
                    {
                        AnimationPlayer.PlayAnimation(NothingNormal);
                    }
                }
            }
            #endregion
            #endregion
        }
Exemplo n.º 29
0
 /// <summary>
 /// Called when this gem has been collected by a player and removed from the level.
 /// </summary>
 /// <param name="collectedBy">
 /// The player who collected this gem. Although currently not used, this parameter would be
 /// useful for creating special powerup gems. For example, a gem could make the player invincible.
 /// </param>
 public void OnCollected(Player collectedBy)
 {
     _collectedSound.Play();
 }
Exemplo n.º 30
0
 public void destroy()
 {
     score += 50;
     destroyEffect.Play();
     enemy01.Remove();
 }
Exemplo n.º 31
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here

            //keyboard

            currenKey = Keyboard.GetState();

            if (currenKey.IsKeyDown(Keys.Space) && isOverGame == false)// && player.lives > 0)
            {
                player.y   = (int)(player.y - player.speed);
                player.pic = bird;
                fly.Play();
            }
            else
            {
                player.y   = (int)(player.y + 2);
                player.pic = bird_fall;
                //fall.Play();
            }

            //player.x = MathHelper.Clamp(player.x, 0, W - player.pic.Width);
            player.y = MathHelper.Clamp(player.y, 0, H - player.pic.Height);

            if (player.y > H - player.pic.Height - 60 && player.lives != 0)
            {
                player.x = 15;
                player.y = H / 2 - 50;
                player.lives--;
                smash.Play();
            }



            if (player.lives == 0)
            {
                //MediaPlayer.Stop();
                //MediaPlayer.Play(GameSong2);
                //player.speed = 0;
                //player.y = H / 2 - 50;
                //player.pic = bird;
                isOverGame = true;
                //player.time = 0;
                //Floor.Speed = 0;
                //pillar.speed = 0;
            }



            foreach (Vector2 pos in pillar.Stonelist)
            {
                if (isCollide(player, pos, pillar.pic))
                {
                    player.x = 15;
                    player.y = H / 2 - 20;
                    player.lives--;
                    //player.time = 0;
                    player.score--;
                    smash.Play();
                    //if (player.lives <= 0)
                    //{

                    //    player.lives = 10;


                    //    //pillar.speed = 0;
                    //    //player.time = 0;
                    //    //break;

                    //}
                }
            }


            putStone += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (putStone >= 1500 && player.lives > 0)
            {
                putStone = 0;
                player.score++;
            }


            if (isOverGame)
            {
                player.speed = 0;
                player.y     = H / 2 - 50;
                player.pic   = bird;
                player.time  = 0;
                Floor.Speed  = 0;
                pillar.speed = 0;

                if (currenKey.IsKeyDown(Keys.Enter) && isOverGame)
                {
                    player.speed = 4;
                    //player.time =
                    player.lives = 2;
                    player.x     = 15;
                    player.y     = H / 2;
                    player.score = 0;
                    Floor.Speed  = -5;
                    pillar.speed = 5;
                    isOverGame   = false;
                    MediaPlayer.Play(GameSong2);
                }
            }

            pillar.Update(gameTime);
            Floor.Update();

            base.Update(gameTime);
        }
Exemplo n.º 32
0
 //Play the tone and execute the conditional above.  This method is accessed in the Game1 class to activate it
 public void PlayTone()
 {
     ColorSwitched = true;
     tone.Play();
 }