コード例 #1
0
        private void DrawBatch(PrimitiveGroupEntry entry)
        {
            if (entry.VertexCount <= 0 && entry.IndexCount <= 0)
            {
                return;
            }

            // TODO: Add entry transform matrix

            GL.LineWidth(entry.LineWidth);

            // Apply texture
            var texture = textureFactory.GetTexture(entry.Texture ?? TextureId.White);

            if (texture == null)
            {
                return;
            }

            GL.BindTexture(TextureTarget.Texture2D, texture.PlatformTexture);

            // Draw geometry
            if (entry.IndexCount > 0)
            {
                GL.DrawElements(entry.PrimitiveType, entry.IndexCount, DrawElementsType.UnsignedShort, entry.StartIndex * sizeof(ushort));
            }
            else
            {
                GL.DrawArrays(entry.PrimitiveType, entry.StartVertex, entry.VertexCount);
            }
        }
コード例 #2
0
        public DifficultyState()
            : base()
        {
            var buttonTexture = TextureFactory.GetTexture("Controls/Button");
            var buttonFont    = TextureFactory.GetSpriteFont("Fonts/Font");

            this.selectDifficultyTexture  = TextureFactory.GetTexture("Titles/SELECT");
            this.selectDifficultyTexture2 = TextureFactory.GetTexture("Titles/DIFFICULTY");

            var bossButton = new Button(buttonTexture, buttonFont)
            {
                Position = new Vector2(2, 300),
                Text     = "Boss",
            };

            bossButton.Click += this.BossButton_Click;

            var newGameEasyButton = new Button(buttonTexture, buttonFont)
            {
                Position = new Vector2(161, 450),
                Text     = "Easy",
            };

            newGameEasyButton.Click += this.NewGameEasyButton_Click;

            var newGameNormalButton = new Button(buttonTexture, buttonFont)
            {
                Position = new Vector2(161, 500),
                Text     = "Normal",
            };

            newGameNormalButton.Click += this.NewGameNormalButton_Click;

            var newGameHardButton = new Button(buttonTexture, buttonFont)
            {
                Position = new Vector2(161, 550),
                Text     = "Hard",
            };

            newGameHardButton.Click += this.NewGameHardButton_Click;

            var returnButton = new Button(buttonTexture, buttonFont)
            {
                Position = new Vector2(161, 600),
                Text     = "Main Menu",
            };

            returnButton.Click += this.QuitGameButton_Click;

            this.components = new List <Component>()
            {
                newGameEasyButton,
                newGameNormalButton,
                newGameHardButton,
                returnButton,
                bossButton,
            };
        }
コード例 #3
0
        public SplashScreenManager(float fadeIn, float wait, float fadeOut, Keys skipButton)
        {
            List <Texture2D> images = new List <Texture2D>();

            this.imageTexture = TextureFactory.GetTexture("FinalEndScreen");

            images.Add(this.imageTexture);

            this.screens = new List <SplashScreen>();
            foreach (Texture2D t in images)
            {
                this.screens.Add(new SplashScreen(t, fadeIn, wait, fadeOut));
            }

            this.skipButton = skipButton;
        }
コード例 #4
0
        public static PowerUp CreatePowerUp(Dictionary <string, object> powerUpProperties)
        {
            string    textureName = (string)powerUpProperties["textureName"];
            Texture2D texture     = TextureFactory.GetTexture(textureName);

            string colorName = (string)powerUpProperties["color"];
            Color  color     = System.Drawing.Color.FromName(colorName).ToXNA();

            MovementPattern movement = MovementPatternFactory.CreateMovementPattern((Dictionary <string, object>)powerUpProperties["movementPattern"]);

            float dropPercent = (float)powerUpProperties["dropPercent"];

            PowerUp powerUp = powerUpProperties["powerUpType"] switch
            {
                "damageUp" => new DamageUp(texture, color, movement, dropPercent),
                "extraLife" => new ExtraLife(texture, color, movement, dropPercent),
                _ => throw new Exception("Invalid PowerUp Type"),
            };

            return(powerUp);
        }
コード例 #5
0
        public static Projectile CreateProjectile(Dictionary <string, object> projectileProperties)
        {
            Projectile projectile = null;

            string    textureName = (string)projectileProperties["textureName"];
            Texture2D texture     = TextureFactory.GetTexture(textureName);

            string colorName = (string)projectileProperties["color"];
            Color  color     = System.Drawing.Color.FromName(colorName).ToXNA();

            MovementPattern movement = MovementPatternFactory.CreateMovementPattern((Dictionary <string, object>)projectileProperties["movementPattern"]);

            int damage = Convert.ToInt32((float)projectileProperties["damage"]);

            switch (projectileProperties["projectileType"])
            {
            case "bullet":
                projectile = new Bullet(texture, color, movement, damage);
                break;

            case "bouncingBullet":
                projectile = new BouncingBullet(texture, color, movement, damage);
                break;

            case "bounceBullet":
                int numberOfTimesToBounce = (int)projectileProperties["bounceTimes"];
                projectile = new BounceBullet(texture, color, movement, damage, numberOfTimesToBounce);
                break;

            case "pushBullet":
                projectile = new PushBullet(texture, color, movement, damage);
                break;

            default:
                throw new Exception("Invalid Projectile Type");
            }

            return(projectile);
        }
コード例 #6
0
        public static Entity CreateEntity(Dictionary <string, object> entityProperties)
        {
            Entity    entity      = null;
            string    textureName = (string)entityProperties["textureName"];
            Texture2D texture     = TextureFactory.GetTexture(textureName);

            string colorName = (string)entityProperties["color"];
            Color  color     = System.Drawing.Color.FromName(colorName).ToXNA();

            Dictionary <string, object> movementPatternProperties = null;
            MovementPattern             movement = null;

            if (entityProperties.ContainsKey("movementPattern"))
            {
                movementPatternProperties = (Dictionary <string, object>)entityProperties["movementPattern"];
                movement = MovementPatternFactory.CreateMovementPattern(movementPatternProperties);
            }

            string enemyType            = (string)entityProperties["entityType"];
            string entityClassification = (string)entityProperties["entityType"] != "player" ? "enemy" : "player";

            int hp = Convert.ToInt32((float)entityProperties["hp"]);

            List <Attack> attacks = null;

            if (entityProperties["attacks"] is List <object> )
            {
                attacks = AttackFactory.CreateAttacks((List <object>)entityProperties["attacks"]);
            }
            else if (entityProperties["attacks"] is Dictionary <string, object> )
            {
                attacks = AttackFactory.CreateAttacks((Dictionary <string, object>)entityProperties["attacks"]);
            }

            switch (entityClassification)
            {
            case "player":
                entity = new Player(texture, color, movement, hp, attacks);
                entity.SpawnPosition = new Vector2((float)movementPatternProperties["spawnXPosition"], (float)movementPatternProperties["spawnYPosition"]);
                break;

            case "enemy":
                PowerUp powerUp = PowerUpFactory.CreatePowerUp((Dictionary <string, object>)entityProperties["powerUp"]);

                switch (enemyType)
                {
                case "simpleGrunt":
                    entity = new SimpleGrunt(texture, color, movement, powerUp, hp, attacks);
                    break;

                case "complexGrunt":
                    entity = new ComplexGrunt(texture, color, movement, powerUp, hp, attacks);
                    break;

                case "midBoss":
                    entity = new MidBoss(texture, color, movement, powerUp, hp, attacks);
                    break;

                case "finalBoss":
                    List <Attack> phase2Attacks = null;
                    if (entityProperties["phase2Attacks"] is List <Dictionary <string, object> > )
                    {
                        phase2Attacks = AttackFactory.CreateAttacks((List <object>)entityProperties["phase2Attacks"]);
                    }
                    else if (entityProperties["phase2Attacks"] is Dictionary <string, object> )
                    {
                        phase2Attacks = AttackFactory.CreateAttacks((Dictionary <string, object>)entityProperties["phase2Attacks"]);
                    }

                    entity = new FinalBoss(texture, color, movement, powerUp, hp, attacks, phase2Attacks);
                    break;
                }

                break;

            default:
                throw new Exception("Invalid Entity");
            }

            if (entity.Movement != null)
            {
                entity.Movement.Parent = entity;
            }

            return(entity);
        }
コード例 #7
0
        public unsafe void Draw(Matrix4x4 projection, Slice <Sprite> sprites, Slice <Matrix3x2>?transforms = null, Slice <int>?indices = null)
        {
            var spriteCount = (indices != null ? indices.Value.Count : sprites.Count);

            if (spriteCount <= 0)
            {
                return;
            }

            EnsureBufferCapacity(spriteCount);

            fixed(Vertex *pVertex = vertexData)
            fixed(ushort *pIndex   = indexData)
            fixed(Sprite * pSprite = &sprites.Items[sprites.Begin])
            {
                var vertexCount     = 0;
                var drawing         = false;
                var isTransparent   = false;
                var previousTexture = (Texture)null;

                Vertex *vertex = pVertex;
                Sprite *sprite = pSprite;

                for (var i = 0; i < spriteCount; i++)
                {
                    var iIndexed = i;
                    if (indices != null)
                    {
                        iIndexed = indices.Value[i];

                        Debug.Assert(iIndexed >= 0 && iIndexed < sprites.Count);

                        sprite = pSprite + iIndexed;
                    }

                    var currentTexture = textureFactory.GetTexture(sprite->Texture);
                    if (currentTexture == null)
                    {
                        continue;
                    }

                    if (previousTexture == null)
                    {
                        previousTexture = currentTexture;
                    }
                    else if (currentTexture.PlatformTexture != previousTexture.PlatformTexture)
                    {
                        if (!drawing)
                        {
                            drawing = true;
                            PlatformBeginDraw(ref projection);
                        }

                        PlatformDraw(
                            pVertex, pIndex, vertexCount, vertexCount / 4 * 6,
                            previousTexture.PlatformTexture, isTransparent);

                        vertexCount     = 0;
                        vertex          = pVertex;
                        previousTexture = currentTexture;
                        isTransparent   = false;
                    }

                    var isSpriteTransparent = currentTexture.IsTransparent || sprite->Color.IsTransparent;
                    isTransparent |= isSpriteTransparent;

                    if (sprite->Rotation == 0)
                    {
                        if (transforms == null)
                        {
                            PopulateVertex(sprite, currentTexture, vertex++, vertex++, vertex++, vertex++);
                        }
                        else
                        {
                            PopulateVertexWithTransform(sprite, currentTexture, vertex++, vertex++, vertex++, vertex++, transforms.Value[iIndexed]);
                        }
                    }
                    else
                    {
                        if (transforms == null)
                        {
                            PopulateVertexWithRotation(sprite, currentTexture, vertex++, vertex++, vertex++, vertex++);
                        }
                        else
                        {
                            PopulateVertexWithRotationAndTransform(sprite, currentTexture, vertex++, vertex++, vertex++, vertex++, transforms.Value[iIndexed]);
                        }
                    }

                    vertexCount += 4;

                    if (indices == null)
                    {
                        sprite++;
                    }
                }

                if (vertexCount > 0)
                {
                    if (!drawing)
                    {
                        drawing = true;
                        PlatformBeginDraw(ref projection);
                    }

                    PlatformDraw(
                        pVertex, pIndex, vertexCount, vertexCount / 4 * 6,
                        previousTexture.PlatformTexture, isTransparent);
                }

                if (drawing)
                {
                    PlatformEndDraw();
                }
            }
        }