Пример #1
0
        public static void Render(
            List <EnemyObject> enemyObjects,
            EnemyObjectType enemyObjectType,
            TranslatedDTDanmakuDisplay display,
            Dictionary <string, DTDanmakuImage> spriteNameToImageDictionary)
        {
            foreach (EnemyObject enemyObj in enemyObjects)
            {
                if (enemyObj.IsDestroyed)
                {
                    continue;
                }

                if (enemyObj.ObjectType != enemyObjectType)
                {
                    continue;
                }

                if (enemyObj.SpriteName == null)
                {
                    continue;
                }

                DTDanmakuImage image = spriteNameToImageDictionary[enemyObj.SpriteName];

                long width  = display.GetWidth(image);
                long height = display.GetHeight(image);

                int x = (int)(enemyObj.XMillis / 1000 - width / 2);
                int y = (int)(700 - enemyObj.YMillis / 1000 - height / 2);
                display.DrawImageRotatedClockwise(image, x, y, (int)enemyObj.FacingDirectionInMillidegrees);
            }
        }
Пример #2
0
 public static void RenderPowerUps(
     List <PowerUp> powerUps,
     TranslatedDTDanmakuDisplay display)
 {
     foreach (var powerUp in powerUps)
     {
         int powerUpX = ((int)powerUp.xMillis / 1000) - ((int)PowerUp.SPRITE_NUM_X_PIXELS) / 2;
         int powerUpY = 700 - ((int)powerUp.yMillis / 1000) - ((int)PowerUp.SPRITE_NUM_Y_PIXELS) / 2;
         display.DrawImage(DTDanmakuImage.PowerUp, powerUpX, powerUpY);
     }
 }
Пример #3
0
        public static void RenderPlayerLifeIcons(
            int numberOfLivesRemaining,
            TranslatedDTDanmakuDisplay display)
        {
            int width = (int)display.GetWidth(DTDanmakuImage.PlayerLifeIcon);

            for (int i = 0; i < numberOfLivesRemaining; i++)
            {
                display.DrawImage(DTDanmakuImage.PlayerLifeIcon,
                                  x: 1000 - 1 - (i + 1) * (width + 1),
                                  y: 3);
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
 public static void RenderPlayerBullets(
     List <PlayerBullet> playerBullets,
     TranslatedDTDanmakuDisplay display)
 {
     foreach (var playerBullet in playerBullets)
     {
         int playerBulletX = ((int)playerBullet.xMillis / 1000) - ((int)PlayerBullet.SPRITE_NUM_X_PIXELS) / 2;
         int playerBulletY = 700 - ((int)playerBullet.yMillis / 1000) - ((int)PlayerBullet.SPRITE_NUM_Y_PIXELS) / 2;
         if (playerBullet.bulletType == PlayerBullet.PlayerBulletType.Main)
         {
             display.DrawImage(DTDanmakuImage.PlayerBullet, playerBulletX, playerBulletY);
         }
         else if (playerBullet.bulletType == PlayerBullet.PlayerBulletType.Side1Left)
         {
             display.DrawImageRotatedCounterclockwise(DTDanmakuImage.PlayerBullet, playerBulletX, playerBulletY, 10 * 1000);
         }
         else if (playerBullet.bulletType == PlayerBullet.PlayerBulletType.Side1Right)
         {
             display.DrawImageRotatedCounterclockwise(DTDanmakuImage.PlayerBullet, playerBulletX, playerBulletY, -10 * 1000);
         }
         else if (playerBullet.bulletType == PlayerBullet.PlayerBulletType.Side2Left)
         {
             display.DrawImageRotatedCounterclockwise(DTDanmakuImage.PlayerBullet, playerBulletX, playerBulletY, 20 * 1000);
         }
         else if (playerBullet.bulletType == PlayerBullet.PlayerBulletType.Side2Right)
         {
             display.DrawImageRotatedCounterclockwise(DTDanmakuImage.PlayerBullet, playerBulletX, playerBulletY, -20 * 1000);
         }
         else if (playerBullet.bulletType == PlayerBullet.PlayerBulletType.Side3Left)
         {
             display.DrawImageRotatedCounterclockwise(DTDanmakuImage.PlayerBullet, playerBulletX, playerBulletY, 30 * 1000);
         }
         else if (playerBullet.bulletType == PlayerBullet.PlayerBulletType.Side3Right)
         {
             display.DrawImageRotatedCounterclockwise(DTDanmakuImage.PlayerBullet, playerBulletX, playerBulletY, -30 * 1000);
         }
         else
         {
             throw new Exception();
         }
     }
 }
Пример #6
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);
                    }
                }
            }
        }
Пример #7
0
        public void Render(IDisplay <IDTDanmakuAssets> display)
        {
            var translatedDisplay = new TranslatedDTDanmakuDisplay(display, xOffset: 0, yOffset: 0);

            this.gameLogic.Render(translatedDisplay);
        }
Пример #8
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));
            }
        }