コード例 #1
0
ファイル: Room.cs プロジェクト: gmk1072/99Bottles
        /// <summary>
        /// Creates the actual tile objects in the world.
        /// </summary>
        public void SpawnRoom(Player player, Room lastRoom)
        {
            if (colliders.Count > 0)
            {
                foreach (Door door in doors)
                {
                    if (door.destination == lastRoom && door.destination != previousRoom)
                    {
                        player.X = door.X - TILE_WIDTH;
                        player.Y = door.Y + TILE_HEIGHT - player.Rect.Height;//made this a little more generic
                        player.positionChangedManually();
                        player.velocity = Vector2.Zero;
                    }
                    else if (door.destination == lastRoom)
                    {
                        player.X = door.X + TILE_WIDTH + 4;
                        player.Y = door.Y + TILE_HEIGHT - player.Rect.Height;//made this a little more generic
                        player.positionChangedManually();
                        player.velocity = Vector2.Zero;
                    }
                }
                return;
            }
            foreground.Clear();
            int exitNum = 0;

            for (int y = level.GetLength(1) - 1; y >= 0; y--)
            {
                for (int x = 0; x < level.GetLength(0); x++)
                {
                    switch (level[x, y])
                    {
                    case ('*'):
                        int            tileNum = rand.Next(7);
                        Texture2D      normal  = manager.content.Load <Texture2D>("Normals/frontNormals/FrontNormalMap_0" + (tileNum + 1) + ".png");
                        ForegroundTile tile    = new ForegroundTile(x * TILE_WIDTH, y * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, (int)(TILE_WIDTH * ISO_SCALE), (int)(TILE_HEIGHT * ISO_SCALE), tileSet, boundsTexture, normal, tileNum);
                        tile.PositionLocked = true;
                        if (Game1.RumbleMode)
                        {
                            if (NoDoors(x, y))
                            {
                                tile.PositionLocked = false;
                                int percent = rand.Next(100);
                                if (percent > 100 - depth)
                                {
                                    tile.rumble = true;

                                    enemies.Add(tile);
                                    tile.color = Color.Gray;
                                    percent    = rand.Next(100);
                                    if (percent > 110 - depth)
                                    {
                                        tile.falling = true;
                                    }
                                }
                            }
                        }
                        foreground.Add(tile);
                        colliders.Add(tile);
                        levelObjects[x, y] = tile;
                        drawable.Add(tile);
                        break;

                    // Cases for entrances and exits.
                    case ('>'):
                        if (nextRooms.Contains(lastRoom))
                        {
                            if (nextRooms[exitNum] == lastRoom)
                            {
                                player.X = (x - 1) * TILE_WIDTH;
                                player.Y = ((y + 1) * TILE_HEIGHT) - player.Rect.Height;    //made this a little more generic
                                player.positionChangedManually();
                                player.velocity = Vector2.Zero;
                            }

                            exitNum++;
                        }
                        else
                        {
                            Room room     = manager.RandomRoom(this);
                            Door nextDoor = new Door(x * TILE_WIDTH + 5, y * TILE_HEIGHT - 6, TILE_WIDTH, TILE_HEIGHT, doorTexture, manager.content.Load <Texture2D>("Normals/BlankNormal.png"), room, manager);
                            nextRooms.Add(room);
                            colliders.Add(nextDoor);
                            levelObjects[x, y] = nextDoor;
                            doors.Add(nextDoor);
                        }
                        break;

                    case ('<'):
                        if (previousRoom != null)
                        {
                            if (previousRoom == lastRoom)
                            {
                                player.X = ((x + 1) * TILE_WIDTH) + 4;
                                player.Y = ((y + 1) * TILE_HEIGHT) - player.Rect.Height;    //made this a little more generic
                                player.positionChangedManually();
                                player.velocity = Vector2.Zero;
                            }
                            Door previousDoor = new Door(x * TILE_WIDTH + 3, y * TILE_HEIGHT - 6, TILE_WIDTH, TILE_HEIGHT, doorTexture, manager.content.Load <Texture2D>("Normals/BlankNormal.png"), previousRoom, manager);
                            colliders.Add(previousDoor);
                            doors.Add(previousDoor);

                            levelObjects[x, y] = previousDoor;
                        }
                        break;

                    case ('┴'):
                        Fan fan = new Fan((x * TILE_WIDTH) - ((int)((TILE_WIDTH * ISO_SCALE) - TILE_WIDTH) / 2), (y * TILE_HEIGHT) - ((int)((TILE_HEIGHT * ISO_SCALE) - TILE_HEIGHT) / 2), (int)(TILE_WIDTH * ISO_SCALE), (int)(TILE_HEIGHT * ISO_SCALE), level[x, y], manager.content.Load <Texture2D>("fan.png"));
                        colliders.Add(fan);
                        colliders.AddRange(fan.getEffects());
                        enemies.AddRange(fan.getEffects());
                        drawable.Add(fan);
                        levelObjects[x, y] = fan;
                        break;

                    case ('┤'):
                        Fan fan1 = new Fan((x * TILE_WIDTH) - ((int)((TILE_WIDTH * ISO_SCALE) - TILE_WIDTH) / 2), (y * TILE_HEIGHT) - ((int)((TILE_HEIGHT * ISO_SCALE) - TILE_HEIGHT) / 2), (int)(TILE_WIDTH * ISO_SCALE), (int)(TILE_HEIGHT * ISO_SCALE), level[x, y], manager.content.Load <Texture2D>("fan.png"));
                        colliders.Add(fan1);
                        colliders.AddRange(fan1.getEffects());
                        enemies.AddRange(fan1.getEffects());
                        drawable.Add(fan1);
                        levelObjects[x, y] = fan1;
                        break;

                    case ('┬'):
                        Fan fan2 = new Fan((x * TILE_WIDTH) - ((int)((TILE_WIDTH * ISO_SCALE) - TILE_WIDTH) / 2), (y * TILE_HEIGHT) - ((int)((TILE_HEIGHT * ISO_SCALE) - TILE_HEIGHT) / 2), (int)(TILE_WIDTH * ISO_SCALE), (int)(TILE_HEIGHT * ISO_SCALE), level[x, y], manager.content.Load <Texture2D>("fan.png"));
                        colliders.Add(fan2);
                        colliders.AddRange(fan2.getEffects());
                        enemies.AddRange(fan2.getEffects());
                        drawable.Add(fan2);
                        levelObjects[x, y] = fan2;
                        break;

                    case ('├'):
                        Fan fan3 = new Fan((x * TILE_WIDTH) - ((int)((TILE_WIDTH * ISO_SCALE) - TILE_WIDTH) / 2), (y * TILE_HEIGHT) - ((int)((TILE_HEIGHT * ISO_SCALE) - TILE_HEIGHT) / 2), (int)(TILE_WIDTH * ISO_SCALE), (int)(TILE_HEIGHT * ISO_SCALE), level[x, y], manager.content.Load <Texture2D>("fan.png"));
                        colliders.Add(fan3);
                        colliders.AddRange(fan3.getEffects());
                        enemies.AddRange(fan3.getEffects());
                        drawable.Add(fan3);
                        levelObjects[x, y] = fan3;
                        break;

                    case ('h'):
                        HoppingEnemy hopEnemy = new HoppingEnemy(x * TILE_WIDTH, y * TILE_HEIGHT, 0.6f, hopEnemyTexture, manager.content.Load <Texture2D>("Normals/BlankNormal.png"), player);
                        colliders.Add(hopEnemy);
                        enemies.Add(hopEnemy);
                        drawable.Add(hopEnemy);
                        levelObjects[x, y] = hopEnemy;
                        break;

                    case ('o'):
                        Ooze ooze = new Ooze(x * TILE_WIDTH, y * TILE_HEIGHT, .50f, oozeTexture, manager.content.Load <Texture2D>("Normals/BlankNormal.png"), player);
                        colliders.Add(ooze);
                        enemies.Add(ooze);
                        drawable.Add(ooze);
                        levelObjects[x, y] = ooze;
                        break;

                    case ('p'):
                        int        phaseTileNum = rand.Next(7);
                        Texture2D  phaseNormal  = manager.content.Load <Texture2D>("Normals/frontNormals/FrontNormalMap_0" + (phaseTileNum + 1) + ".png");
                        PhaseBlock block        = new PhaseBlock(x * TILE_WIDTH, y * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, (int)(TILE_WIDTH * ISO_SCALE), (int)(TILE_HEIGHT * ISO_SCALE), tileSet, boundsTexture, phaseNormal, phaseTileNum, true);
                        colliders.Add(block);
                        drawable.Add(block);
                        levelObjects[x, y] = block;
                        break;

                    case ('b'):

                        Button button = new Button(x * TILE_WIDTH + TILE_WIDTH / 3, y * TILE_HEIGHT + TILE_HEIGHT / 3, TILE_WIDTH / 3, TILE_HEIGHT / 3, boundsTexture, roomFont, null);
                        levelObjects[x, y] = button;
                        colliders.Add(button);
                        colliders.Add(button.Box);
                        enemies.Add(button.Box);
                        drawable.Add(button);
                        break;

                    case ('T'):
                        Button button1 = new Button(x * TILE_WIDTH + TILE_WIDTH / 3, y * TILE_HEIGHT + TILE_HEIGHT / 3, TILE_WIDTH / 3, TILE_HEIGHT / 3, boundsTexture, roomFont, null, true);
                        levelObjects[x, y] = button1;
                        colliders.Add(button1);
                        colliders.Add(button1.Box);
                        enemies.Add(button1.Box);
                        drawable.Add(button1);
                        break;

                    case ('B'):
                        Bottle bottle = new Bottle(x * TILE_WIDTH, y * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, bottleTexture, player, manager);
                        colliders.Add(bottle);
                        drawable.Add(bottle);
                        levelObjects[x, y] = bottle;
                        break;

                    case ('s'):
                        bool onGround = false;
                        try
                        {
                            if (levelObjects[x, y + 1] == null)
                            {
                                onGround = false;
                            }
                            else
                            {
                                onGround = true;
                            }
                        }
                        catch (Exception e)
                        { }
                        Spikes spikes = new Spikes(x * TILE_WIDTH, y * TILE_HEIGHT, spikeTexture, manager.content.Load <Texture2D>("Normals/BlankNormal.png"), player, onGround);
                        colliders.Add(spikes);
                        enemies.Add(spikes);
                        drawable.Add(spikes);
                        levelObjects[x, y] = spikes;
                        break;

                    case ('S'):
                        EntitySpawner spawner = new EntitySpawner(x * TILE_WIDTH, y * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, this);
                        colliders.Add(spawner);
                        enemies.Add(spawner);
                        drawable.Add(spawner);
                        levelObjects[x, y] = spawner;
                        break;
                    }
                    if (level[x, y] != ' ')
                    {
                        int            tileNum = rand.Next(7);
                        Texture2D      normal  = manager.content.Load <Texture2D>("Normals/backgroundNormals/BackNormalMap_0" + (tileNum + 1) + ".png");
                        BackgroundTile back    = new BackgroundTile((x * TILE_WIDTH) + 8, (y * TILE_HEIGHT) - 8, TILE_WIDTH, TILE_HEIGHT, backgroundSet, normal, tileNum);
                        background.Add(back);
                    }
                }
            }
            checkAdditionalInformation();
            prevSize  = colliders.Count;
            prevSize2 = enemies.Count;
            drawable.Add(player);
        }
コード例 #2
0
 public void SetSpawner(EntitySpawner spawner)
 {
     this.spawner = spawner;
 }