コード例 #1
0
            public void PlaySound(DTDanmakuSound sound, int volume)
            {
                if (!this.canSuccessfullyPlayAudio)
                {
                    return;
                }

                double finalVolume = this.soundToFileNameMapping[sound].Volume * (volume / 100.0);

                if (finalVolume > 1.0)
                {
                    finalVolume = 1.0;
                }
                if (finalVolume < 0.0)
                {
                    finalVolume = 0.0;
                }
                if (finalVolume > 0.0)
                {
                    SoundBuffer soundBuffer = this.soundToSoundBufferMapping[sound];
                    soundBuffer.Volume = finalVolume;
                    soundBuffer.Play();
                }
            }
コード例 #2
0
 /// <summary>
 /// Volume ranges from 0 to 100 (both inclusive)
 /// </summary>
 public void PlaySound(DTDanmakuSound sound, int volume)
 {
     this.display.GetAssets().PlaySound(sound: sound, volume: volume);
 }
コード例 #3
0
        public GameLogic GetNextFrame(IKeyboard keyboardInput, IMouse mouseInput, IKeyboard previousKeyboardInput, IMouse previousMouseInput)
        {
            long elapsedMillisPerFrame = 1000 / this.fps;

            this.elapsedTimeMillis += elapsedMillisPerFrame;

            List <Player.PlayerSubFramePosition> playerSubFramePositions = Player.ProcessPlayerMovement(
                player: this.player,
                elapsedMillisPerFrame: elapsedMillisPerFrame,
                keyboardInput: keyboardInput);

            Player.PlayerShootResult playerShootResult = Player.ProcessPlayerShoot(
                player: this.player,
                elapsedMillisPerFrame: elapsedMillisPerFrame,
                keyboardInput: keyboardInput);
            foreach (PlayerBullet newBullet in playerShootResult.PlayerBullets)
            {
                this.playerBullets.Add(newBullet);
            }
            this.shouldPlayPlayerShootSound       = playerShootResult.DidShoot || this.shouldPlayPlayerShootSound;
            this.playerShootSoundCooldownInMillis = this.playerShootSoundCooldownInMillis - elapsedMillisPerFrame;
            if (this.playerShootSoundCooldownInMillis < 0)
            {
                this.playerShootSoundCooldownInMillis = 0;
            }

            this.playerBullets = PlayerBullet.ProcessPlayerBulletMovement(
                playerBullets: this.playerBullets,
                elapsedMillisPerFrame: elapsedMillisPerFrame);

            PowerUp.PowerUpActionResult powerUpResult = PowerUp.ProcessPowerUpMovement(
                powerUps: this.powerUps,
                isPlayerDead: this.player.isDead,
                playerXMillis: this.player.xMillis,
                playerYMillis: this.player.yMillis,
                playerPowerUpLevel: this.player.playerPowerUpLevel,
                elapsedMillisPerFrame: elapsedMillisPerFrame);
            this.powerUps = powerUpResult.powerUps;
            this.player.playerPowerUpLevel = powerUpResult.playerPowerUpLevel;

            EnemyObjectUpdater.UpdateResult enemyObjectUpdateResult = EnemyObjectUpdater.Update(
                currentEnemyObjects: this.enemyObjects,
                playerXMillis: this.player.xMillis,
                playerYMillis: this.player.yMillis,
                elapsedMillisecondsPerIteration: elapsedMillisPerFrame,
                isPlayerDestroyed: this.player.isDead,
                enemyObjectTemplates: this.enemyObjectTemplates,
                rng: this.rng);

            this.enemyObjects = enemyObjectUpdateResult.NewEnemyObjects;
            foreach (Tuple <long, long> newPowerUp in enemyObjectUpdateResult.NewPowerUps)
            {
                this.powerUps.Add(new PowerUp(xMillis: newPowerUp.Item1, yMillis: newPowerUp.Item2));
            }
            if (enemyObjectUpdateResult.ShouldEndLevel)
            {
                this.levelFinishedCountdownInMillis = 3 * 1000;
            }
            foreach (string newSoundEffect in enemyObjectUpdateResult.NewSoundEffectsToPlay)
            {
                DTDanmakuSound sound = this.soundNameToSoundDictionary[newSoundEffect];
                this.soundsThatNeedToBePlayed.Add(sound);
            }

            this.bossHealthBar.ProcessBossHealthBar(
                bossHealthMeterNumber: enemyObjectUpdateResult.BossHealthMeterNumber,
                bossHealthMeterMilliPercentage: enemyObjectUpdateResult.BossHealthMeterMilliPercentage,
                elapsedMillisPerFrame: elapsedMillisPerFrame);

            EnemyObjectMover.UpdateEnemyPositions(
                enemyObjects: this.enemyObjects,
                elapsedMillisecondsPerIteration: elapsedMillisPerFrame);

            bool hasPlayerCollidedWithEnemy = CollisionDetector.HandleCollisionBetweenPlayerAndEnemyObjects(
                playerSubFramePositions: playerSubFramePositions,
                isPlayerDead: this.player.isDead,
                isPlayerInvulnerable: this.player.playerInvincibilityTimeRemainingMillis.HasValue && this.player.playerInvincibilityTimeRemainingMillis.Value > 0,
                enemyObjects: this.enemyObjects);

            if (hasPlayerCollidedWithEnemy)
            {
                this.soundsThatNeedToBePlayed.Add(DTDanmakuSound.PlayerDeath);

                bool stillHasLivesRemaining = this.player.DestroyPlayer(
                    enemyObjects: this.enemyObjects,
                    elapsedMillisecondsPerIteration: elapsedMillisPerFrame,
                    rng: this.rng);

                if (!stillHasLivesRemaining)
                {
                    this.gameOverCountdownInMillis = 3 * 1000;
                }
            }

            Player.ProcessPlayerRespawnAndInvincibility(
                player: this.player,
                elapsedMillisPerFrame: elapsedMillisPerFrame);

            this.playerBullets = CollisionDetector.HandleCollisionBetweenPlayerBulletsAndEnemyObjects(
                playerBullets: this.playerBullets,
                enemyObjects: this.enemyObjects);

            if (!this.player.isDead)
            {
                int playerXMillis;
                int playerYMillis;
                unchecked
                {
                    playerXMillis = (int)this.player.xMillis;
                    playerYMillis = (int)this.player.yMillis;
                }
                this.rng.AddSeed(playerXMillis);
                this.rng.AddSeed(playerYMillis);
            }

            if (this.gameOverCountdownInMillis.HasValue)
            {
                this.gameOverCountdownInMillis = this.gameOverCountdownInMillis.Value - elapsedMillisPerFrame;
                if (this.gameOverCountdownInMillis.Value < 0)
                {
                    this.gameOverCountdownInMillis = 0;
                }
            }
            if (this.levelFinishedCountdownInMillis.HasValue)
            {
                this.levelFinishedCountdownInMillis = this.levelFinishedCountdownInMillis.Value - elapsedMillisPerFrame;
                if (this.levelFinishedCountdownInMillis.Value < 0)
                {
                    this.levelFinishedCountdownInMillis = 0;
                }
            }

            /*
             *      Note that since these debug things bypass regular game logic, they may break other stuff or crash the program
             *      (Should be used for debugging / development only)
             */
            if (this.debugMode)
            {
                if (keyboardInput.IsPressed(Key.One) && !previousKeyboardInput.IsPressed(Key.One))
                {
                    this.powerUps.Add(new PowerUp(xMillis: player.xMillis, yMillis: 710 * 1000));
                }

                if (keyboardInput.IsPressed(Key.Two))
                {
                    for (int i = 0; i < 500; i++)
                    {
                        this.powerUps.Add(new PowerUp(xMillis: player.xMillis + (i - 250) * 1000, yMillis: 710 * 1000));
                    }
                }

                if (keyboardInput.IsPressed(Key.Three) && !previousKeyboardInput.IsPressed(Key.Three))
                {
                    this.gameOverCountdownInMillis = 0;
                }

                if (keyboardInput.IsPressed(Key.Four) && !previousKeyboardInput.IsPressed(Key.Four))
                {
                    this.levelFinishedCountdownInMillis = 0;
                }

                if (keyboardInput.IsPressed(Key.Five) && !previousKeyboardInput.IsPressed(Key.Five))
                {
                    this.debug_renderHitboxes = !this.debug_renderHitboxes;
                }
            }

            return(this);
        }