Esempio n. 1
0
        private void CreateTanks(ContentManager contentManager)
        {
            for (int x = 0; x < MapWidth; x++)
            {
                for (int y = 0; y < LevelHeight; y++)
                {
                    Texture2D tempTexture           = contentManager.Load <Texture2D>("Enemy1");
                    const int marginBottom          = 1;
                    int       maginLeft             = (150 - tempTexture.Width) / 2;
                    float     xPos                  = (x * 150) + maginLeft;
                    float     yPos                  = (y * SpaceBetweenPlatforms) - tempTexture.Height - marginBottom;
                    Vector2   tempVector            = Factory.CreateVector(xPos, yPos);
                    Rectangle tempCollisonRectangle = Factory.CreateRectangle((int)tempVector.X, (int)tempVector.Y, tempTexture.Width, tempTexture.Height);
                    Sprite    tempSprite            = Factory.CreateSprite(tempTexture, 1, tempVector);
                    Tank      tempTank              = WorldFactory.CreateTank(tempSprite, tempCollisonRectangle);

                    switch (EnemiesArray[y, x])
                    {
                    case 1:
                        tempTank.Direction = Direction.ToRight;
                        AllTanks.Add(tempTank);
                        break;

                    case 2:
                        tempTank.Direction = Direction.ToLeft;
                        AllTanks.Add(tempTank);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        private void Shoot()
        {
            if (Sprite.NumberOfSprites == 1 && LastTimeShooted >= 190)
            {
                GameSounds.PlayShootSound();

                Texture2D bulletTexture = Factory.CreateTexture("Bullet");
                const int yOffset       = 10;
                int       xOffset;

                if (direction == Direction.ToLeft)
                {
                    xOffset = -bulletTexture.Width;
                }
                else
                {
                    xOffset = Sprite.Texture.Width;
                }

                Vector2   bulletPosition            = Factory.CreateVector(Sprite.Position.X + xOffset, Sprite.Position.Y + yOffset);
                Rectangle bulletCollisoionRectangle = Factory.CreateRectangle((int)bulletPosition.X, (int)bulletPosition.Y, bulletTexture.Width, bulletTexture.Height);
                Sprite    sprite = Factory.CreateSprite(bulletTexture, 1, bulletPosition);
                Bullet    bullet = WorldFactory.CreateBullet(sprite, bulletCollisoionRectangle);
                bullet.direction = direction;
                ShootedBullets.Add(bullet);
                LastTimeShooted = 0;
            }
        }
        private void CreatePickables(ContentManager contentManager)
        {
            Texture2D tempTexture = contentManager.Load <Texture2D>("Pickable1");

            for (int x = 0; x < MapWidth; x++)
            {
                for (int y = 0; y < LevelHeight; y++)
                {
                    int    BLOCK_ID  = PickablesArray[y, x];
                    string ID_STRING = Convert.ToString(BLOCK_ID);

                    if (ID_STRING != "0")
                    {
                        tempTexture = contentManager.Load <Texture2D>("Pickable" + ID_STRING);
                    }

                    const int marginBottom          = 10;
                    int       maginLeft             = (150 - tempTexture.Width) / 2;
                    float     xPos                  = (x * 150) + maginLeft;
                    float     yPos                  = (y * SpaceBetweenPlatforms) - tempTexture.Height - marginBottom;
                    Vector2   tempVector            = Factory.CreateVector(xPos, yPos);
                    Rectangle tempCollisonRectangle = Factory.CreateRectangle((int)tempVector.X, (int)tempVector.Y, tempTexture.Width, tempTexture.Height);
                    Sprite    tempSprite            = Factory.CreateSprite(tempTexture, 1, tempVector);

                    switch (PickablesArray[y, x])
                    {
                    case 1:
                        MoneySafeKey tempMoneySafeKey = WorldFactory.CreateKey(tempSprite, tempCollisonRectangle, MoneySafeIndentifiers[totalKeys]);
                        AllPickables.Add(tempMoneySafeKey as Block);
                        totalKeys++;
                        break;

                    case 2:
                        Coin tempCoin = WorldFactory.CreateCoin(tempSprite, tempCollisonRectangle);
                        AllPickables.Add(tempCoin);
                        break;

                    case 3:
                        Potion tempPotion = WorldFactory.CreatePotion(tempSprite, tempCollisonRectangle);
                        AllPickables.Add(tempPotion);
                        break;

                    case 4:
                        MoneySafe tempMoneySafe = WorldFactory.CreateSafe(tempSprite, tempCollisonRectangle, MoneySafeIndentifiers[totalMoneySafes]);
                        AllPickables.Add(tempMoneySafe);
                        totalMoneySafes++;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        protected void CreateObstacles(ContentManager contentManager)
        {
            for (int x = 0; x < MapWidth; x++)
            {
                for (int y = 0; y < LevelHeight; y++)
                {
                    // Create Platform
                    Texture2D platformTexture       = contentManager.Load <Texture2D>("Block1");
                    Vector2   tempVector            = Factory.CreateVector(x * platformTexture.Width, y * SpaceBetweenPlatforms);
                    Rectangle tempCollisonRectangle = Factory.CreateRectangle((int)tempVector.X, (int)tempVector.Y, platformTexture.Width, platformTexture.Height);
                    Sprite    tempSprite            = Factory.CreateSprite(platformTexture, 1, tempVector);
                    Block     platform = WorldFactory.CreatePlatform(tempSprite, tempCollisonRectangle);

                    switch (ObstaclesArray[y, x])
                    {
                    case 1:
                        // Add Platform
                        AllObstacles.Add(platform);

                        break;

                    case 2:
                        // Add platform
                        AllObstacles.Add(platform);

                        // Create Door on the platform
                        Texture2D doorTexture = contentManager.Load <Texture2D>("Block2");

                        int     maginLeft  = (150 - doorTexture.Width) / 2;
                        float   xPos       = (x * platformTexture.Width) + maginLeft;
                        float   yPos       = (y * SpaceBetweenPlatforms) - doorTexture.Height;
                        Vector2 doorVector = Factory.CreateVector(xPos, yPos);

                        Rectangle doorCollisonRectangle = Factory.CreateRectangle((int)doorVector.X, (int)doorVector.Y, doorTexture.Width, doorTexture.Height);
                        Sprite    doorSprite            = Factory.CreateSprite(doorTexture, 1, doorVector);
                        Block     door = WorldFactory.CreateDoor(doorSprite, doorCollisonRectangle);

                        AllObstacles.Add(door);

                        break;

                    default:
                        break;
                    }
                }
            }
        }
Esempio n. 5
0
        public void Shoot()
        {
            Texture2D bulletTexture = Factory.CreateTexture("Bullet");
            int       yOffset       = 10;
            int       xOffset;

            if (Direction == Direction.ToLeft)
            {
                xOffset = -bulletTexture.Width;
            }
            else
            {
                xOffset = Sprite.Texture.Width;
            }

            Vector2   bulletPosition            = Factory.CreateVector(Sprite.Position.X + xOffset, Sprite.Position.Y + yOffset);
            Rectangle bulletCollisoionRectangle = Factory.CreateRectangle((int)bulletPosition.X, (int)bulletPosition.Y, bulletTexture.Width, bulletTexture.Height);
            Sprite    sprite = Factory.CreateSprite(bulletTexture, 1, bulletPosition);
            Bullet    bullet = WorldFactory.CreateBullet(sprite, bulletCollisoionRectangle);

            bullet.direction = Direction;
            ShootedBullets.Add(bullet);
        }