示例#1
0
        public void RenderBossHealthBar(TranslatedDTDanmakuDisplay display)
        {
            List <DisplayedHealthBar> list = new List <DisplayedHealthBar>();

            foreach (DisplayedHealthBar healthBar in this.displayedHealthBars)
            {
                list.Add(healthBar);
            }

            list.Sort();

            for (int i = 0; i < list.Count; i++)
            {
                DisplayedHealthBar healthBar = list[i];

                long maxWidthInPixels = 800;

                long desiredWidth = maxWidthInPixels * healthBar.MilliPercentage / 100L / 1000L;

                int alpha;

                if (this.bossHealthMeterNumber == null)
                {
                    alpha = 0;
                }
                else if (healthBar.MeterNumber >= this.bossHealthMeterNumber.Value)
                {
                    alpha = 255;
                }
                else if (healthBar.MeterNumber == this.bossHealthMeterNumber.Value - 1)
                {
                    alpha = 40;
                }
                else
                {
                    alpha = 0;
                }

                display.DrawRectangle(
                    x: 100,
                    y: 40,
                    width: (int)desiredWidth,
                    height: 7,
                    color: GetColor(bossHealthMeterNumber: healthBar.MeterNumber, alpha: alpha),
                    fill: true);
            }
        }
示例#2
0
        public static void RenderPlayer(
            Player player,
            TranslatedDTDanmakuDisplay display,
            bool debugMode,
            bool debug_renderHitboxes)
        {
            if (!player.isDead)
            {
                int playerX = ((int)player.xMillis / 1000) - ((int)Player.SPRITE_NUM_X_PIXELS) / 2;
                int playerY = 700 - ((int)player.yMillis / 1000) - ((int)Player.SPRITE_NUM_Y_PIXELS) / 2;

                if (player.playerInvincibilityTimeRemainingMillis.HasValue && player.playerInvincibilityTimeRemainingMillis.Value > 0)
                {
                    display.DrawImage(DTDanmakuImage.PlayerShipInvulnerable, playerX, playerY);
                }
                else
                {
                    display.DrawImage(DTDanmakuImage.PlayerShip, playerX, playerY);
                }

                /*
                 *      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 (debugMode)
                {
                    if (debug_renderHitboxes)
                    {
                        display.DrawRectangle(
                            x: ((int)(player.xMillis / 1000L)) - 3,
                            y: 700 - ((int)(player.yMillis / 1000L)) - 3,
                            width: 7,
                            height: 7,
                            color: new DTColor(255, 0, 0),
                            fill: true);
                    }
                }
            }
        }
示例#3
0
        public void Render(TranslatedDTDanmakuDisplay display)
        {
            if (this.shouldPlayPlayerShootSound)
            {
                if (this.playerShootSoundCooldownInMillis <= 0)
                {
                    display.PlaySound(sound: DTDanmakuSound.PlayerShoot, volume: this.soundVolume);
                    this.playerShootSoundCooldownInMillis = 10;
                }
                this.shouldPlayPlayerShootSound = false;
            }

            foreach (DTDanmakuSound sound in this.soundsThatNeedToBePlayed)
            {
                display.PlaySound(sound: sound, volume: this.soundVolume);
            }
            this.soundsThatNeedToBePlayed = new List <DTDanmakuSound>();

            // Draw background
            display.DrawRectangle(
                x: 0,
                y: 0,
                width: 1000,
                height: 700,
                color: new DTColor(r: 132, g: 245, b: 255),                 // teal
                fill: true);

            EnemyObjectRenderer.Render(
                enemyObjects: this.enemyObjects,
                enemyObjectType: EnemyObjectType.Enemy,
                display: display,
                spriteNameToImageDictionary: this.spriteNameToImageDictionary);

            Player.RenderPlayer(
                player: this.player,
                display: display,
                debugMode: this.debugMode,
                debug_renderHitboxes: this.debug_renderHitboxes);

            PowerUp.RenderPowerUps(
                powerUps: this.powerUps,
                display: display);

            PlayerBullet.RenderPlayerBullets(
                playerBullets: this.playerBullets,
                display: display);

            EnemyObjectRenderer.Render(
                enemyObjects: this.enemyObjects,
                enemyObjectType: EnemyObjectType.EnemyBullet,
                display: display,
                spriteNameToImageDictionary: this.spriteNameToImageDictionary);

            // Placeholders shouldn't have any sprites, so this should be a no-op
            EnemyObjectRenderer.Render(
                enemyObjects: this.enemyObjects,
                enemyObjectType: EnemyObjectType.Placeholder,
                display: display,
                spriteNameToImageDictionary: this.spriteNameToImageDictionary);

            Player.RenderPlayerLifeIcons(
                numberOfLivesRemaining: this.player.numLivesLeft,
                display: display);

            this.bossHealthBar.RenderBossHealthBar(display: display);

            /*
             *      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 (this.debug_renderHitboxes)
                {
                    foreach (EnemyObject enemy in this.enemyObjects)
                    {
                        if (enemy.CollisionBoxes != null)
                        {
                            for (int i = 0; i < enemy.CollisionBoxes.Count; i++)
                            {
                                display.DrawRectangle(
                                    x: (int)((enemy.XMillis + enemy.CollisionBoxes[i].LowerXMillis) / 1000L),
                                    y: (int)(700 - ((enemy.YMillis + enemy.CollisionBoxes[i].UpperYMillis) / 1000L)),
                                    width: (int)((enemy.CollisionBoxes[i].UpperXMillis - enemy.CollisionBoxes[i].LowerXMillis) / 1000L + 1),
                                    height: (int)((enemy.CollisionBoxes[i].UpperYMillis - enemy.CollisionBoxes[i].LowerYMillis) / 1000L + 1),
                                    color: new DTColor(r: 0, g: 0, b: 255, alpha: 50),
                                    fill: true);
                            }
                        }
                        if (enemy.DamageBoxes != null)
                        {
                            for (int i = 0; i < enemy.DamageBoxes.Count; i++)
                            {
                                display.DrawRectangle(
                                    x: (int)((enemy.XMillis + enemy.DamageBoxes[i].LowerXMillis) / 1000L),
                                    y: (int)(700 - ((enemy.YMillis + enemy.DamageBoxes[i].UpperYMillis) / 1000L)),
                                    width: (int)((enemy.DamageBoxes[i].UpperXMillis - enemy.DamageBoxes[i].LowerXMillis) / 1000L + 1),
                                    height: (int)((enemy.DamageBoxes[i].UpperYMillis - enemy.DamageBoxes[i].LowerYMillis) / 1000L + 1),
                                    color: new DTColor(r: 0, g: 0, b: 255, alpha: 50),
                                    fill: true);
                            }
                        }
                    }
                    foreach (PlayerBullet playerBullet in this.playerBullets)
                    {
                        for (int i = 0; i < playerBullet.CollisionBoxes.Count; i++)
                        {
                            ObjectBox playerBulletObjectBox = playerBullet.CollisionBoxes[i];
                            display.DrawRectangle(
                                x: (int)((playerBullet.xMillis + playerBulletObjectBox.LowerXMillis) / 1000L),
                                y: (int)(700 - ((playerBullet.yMillis + playerBulletObjectBox.UpperYMillis) / 1000L)),
                                width: (int)((playerBulletObjectBox.UpperXMillis - playerBulletObjectBox.LowerXMillis) / 1000L + 1),
                                height: (int)((playerBulletObjectBox.UpperYMillis - playerBulletObjectBox.LowerYMillis) / 1000L + 1),
                                color: new DTColor(r: 255, g: 0, b: 0, alpha: 50),
                                fill: true);
                        }
                    }
                }
            }

            /*
             *      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)
            {
                display.DebugPrint(
                    x: 10,
                    y: 10 + 30,
                    debugText: "Number of objects: " + (this.powerUps.Count + this.playerBullets.Count + this.enemyObjects.Count));
            }
        }