//-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 public BaseTileDataInstance()
 {
     room				= null;
     tileData			= null;
     properties			= new Properties(this);
     modifiedProperties	= new Properties(this);
 }
 //-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 public EventTileDataInstance()
 {
     this.room				= null;
     this.position			= Point2I.Zero;
     this.data				= null;
     this.modifiedProperties	= new Properties();
     this.modifiedProperties.PropertyObject = this;
 }
 public BaseTileDataInstance(BaseTileData tileData)
 {
     this.room		= null;
     this.tileData	= tileData;
     this.properties	= new Properties(this);
     this.properties.BaseProperties = tileData.Properties;
     this.modifiedProperties	= new Properties(this);
     this.modifiedProperties.BaseProperties = tileData.Properties;
 }
 //-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 public TileDataInstance()
 {
     this.room		= null;
     this.location	= Point2I.Zero;
     this.layer		= 0;
     this.tileData	= null;
     this.properties = new Properties();
     this.properties.PropertyObject = this;
 }
 public EventTileDataInstance(EventTileData tileData, Point2I position)
 {
     this.room				= null;
     this.position			= position;
     this.data				= tileData;
     this.modifiedProperties	= new Properties();
     this.modifiedProperties.PropertyObject = this;
     this.modifiedProperties.BaseProperties = tileData.Properties;
 }
 //-----------------------------------------------------------------------------
 // Constructor
 //-----------------------------------------------------------------------------
 public DungeonMapRoom()
 {
     this.floor			= null;
     this.room			= null;
     this.hasTreasure	= false;
     this.isBossRoom		= false;
     this.sprite			= null;
     this.isDiscovered	= false;
     this.location		= Point2I.Zero;
 }
 public TileDataInstance(TileData tileData, int x, int y, int layer)
 {
     this.room		= null;
     this.location	= new Point2I(x, y);
     this.layer		= layer;
     this.tileData	= tileData;
     this.properties = new Properties();
     this.properties.PropertyObject = this;
     this.properties.BaseProperties = tileData.Properties;
 }
Example #8
0
 //-----------------------------------------------------------------------------
 // Constructor
 //-----------------------------------------------------------------------------
 public RoomControl()
 {
     level			= null;
     room			= null;
     tiles			= null;
     roomLocation	= Point2I.Zero;
     entities		= new List<Entity>();
     eventTiles		= new List<EventTile>();
     viewControl		= new ViewControl();
 }
Example #9
0
 public bool FindDestinationInLevel(string id, Level level, out Room destRoom, out EventTileDataInstance destEvent)
 {
     for (int x = 0; x < level.Width; x++) {
         for (int y = 0; y < level.Height; y++) {
             if (FindDestinationInRoom(id, level.GetRoomAt(x, y), out destRoom, out destEvent))
                 return true;
         }
     }
     destRoom = null;
     destEvent = null;
     return false;
 }
Example #10
0
 //-----------------------------------------------------------------------------
 // Tile Methods
 //-----------------------------------------------------------------------------
 // Returns true if there is free space to place the given tile at a location.
 public bool CanPlaceTile(TileData tile, Room room, Point2I location, int layer)
 {
     Point2I size = tile.Size;
     for (int x = 0; x < size.X; x++) {
         for (int y = 0; y < size.Y; y++) {
             Point2I loc = location + new Point2I(x, y);
             if (room.GetTile(loc, layer) != null)
                 return false;
         }
     }
     return true;
 }
Example #11
0
 public bool FindDestinationInRoom(string id, Room room, out Room destRoom, out EventTileDataInstance destEvent)
 {
     for (int i = 0; i < room.EventData.Count; i++) {
         if (room.EventData[i].Properties.GetString("id", "") == id) {
             destRoom = room;
             destEvent = room.EventData[i];
             return true;
         }
     }
     destRoom = null;
     destEvent = null;
     return false;
 }
Example #12
0
        // Place a tile in a room, deleting any other tiles in the way.
        public void PlaceTile(TileDataInstance tile, Room room, Point2I location, int layer)
        {
            // Remove any tiles in the way.
            Point2I size = tile.Size;
            for (int x = 0; x < size.X; x++) {
                for (int y = 0; y < size.Y; y++) {
                    TileDataInstance t = room.GetTile(location, layer);
                    if (t != null)
                        DeleteTile(t);
                }
            }

            // Place the tile.
            room.PlaceTile(tile, location, layer);
        }
 public static bool IsRoomEmpty(Room room)
 {
     TileData sameTileType = null;
     for (int layer = 0; layer < room.LayerCount; layer++) {
         for (int x = 0; x < room.Width; x++) {
             for (int y = 0; y < room.Height; y++) {
                 TileDataInstance tile = room.GetTile(x, y, layer);
                 if (tile != null && layer > 0)
                     return false;
                 if (layer == 0) {
                     if (sameTileType != null && tile == null)
                         return false;
                     else if (sameTileType != null && tile != null && tile.TileData != sameTileType)
                         return false;
                     else if (sameTileType == null && tile != null)
                         sameTileType = tile.TileData;
                 }
             }
         }
     }
     return true;
 }
Example #14
0
 public void Initialize(Room room)
 {
     layerCount = room.LayerCount;
     gridDimensions = (Point2I) GMath.Ceiling((Vector2F)
         (room.Size * GameSettings.TILE_SIZE) / tileGridCellSize);
     tiles = new Tile[gridDimensions.X, gridDimensions.Y, layerCount];
 }
Example #15
0
 //-----------------------------------------------------------------------------
 // Internal methods
 //-----------------------------------------------------------------------------
 private void ActivateTile(MouseButtons mouseButton, Room room, Point2I tileLocation)
 {
     if (mouseButton == MouseButtons.Left) {
         // Sample the tile.
         TileDataInstance tile = room.GetTile(tileLocation, editorControl.CurrentLayer);
         if (tile != null) {
             editorControl.SelectedTilesetTile = -Point2I.One;
             editorControl.SelectedTilesetTileData = tile.TileData;
         }
     }
 }
Example #16
0
 public void FillRoomWithDefaultTiles(Room room)
 {
     for (int x = 0; x < room.Width; x++) {
         for (int y = 0; y < room.Height; y++) {
             room.PlaceTile(new TileDataInstance(Zone.DefaultTileData), x, y, 0);
         }
     }
 }
Example #17
0
        public void BeginRoom(Room room)
        {
            this.room			= room;
            this.roomLocation	= room.Location;
            this.level			= room.Level;

            // Clear event tiles.
            eventTiles.Clear();

            // Clear all entities from the old room (except for the player).
            entities.Clear();
            if (Player != null) {
                Player.Initialize(this);
                entities.Add(Player);
            }

            // Create the tile grid.
            tiles = new Tile[room.Width, room.Height, room.LayerCount];
            for (int x = 0; x < room.Width; x++) {
                for (int y = 0; y < room.Height; y++) {
                    for (int i = 0; i < room.LayerCount; i++) {
                        TileDataInstance data = room.TileData[x, y, i];
                        tiles[x, y, i] = null;
                        if (data != null)
                            tiles[x, y, i] = Tile.CreateTile(data);
                    }
                }
            }

            // Create the event tiles.
            eventTiles.Capacity = room.EventData.Count;
            for (int i = 0; i < room.EventData.Count; i++) {
                EventTileDataInstance data  = room.EventData[i];
                EventTile eventTile = EventTile.CreateEvent(data);
                eventTiles.Add(eventTile);
            }

            // Initialize the tiles.
            for (int x = 0; x < room.Width; x++) {
                for (int y = 0; y < room.Height; y++) {
                    for (int i = 0; i < room.LayerCount; i++) {
                        Tile t = tiles[x, y, i];
                        if (t != null)
                            t.Initialize(this);
                    }
                }
            }

            // Initialize the event tiles.
            for (int i = 0; i < eventTiles.Count; i++) {
                eventTiles[i].Initialize(this);
            }

            viewControl.Bounds = RoomBounds;
            viewControl.ViewSize = GameSettings.VIEW_SIZE;
        }
        //-----------------------------------------------------------------------------
        // Static Methods
        //-----------------------------------------------------------------------------
        public static DungeonMapRoom Create(Room room, DungeonMapFloor floor)
        {
            // Don't show empty rooms.
            if (IsRoomEmpty(room))
                return null;

            // Create the map room object.
            DungeonMapRoom mapRoom = new DungeonMapRoom() {
                room			= room,
                hasTreasure		= room.HasUnopenedTreasure(),
                isDiscovered	= room.IsDiscovered,
                isBossRoom		= room.IsBossRoom,
                location		= room.Location,
                sprite			= null,
                floor			= floor,
            };

            // Determine the sprite to draw for this room based on its connections.
            Sprite[] connectedSprites = new Sprite[16] {
                GameData.SPR_UI_MAP_ROOM_NONE,
                GameData.SPR_UI_MAP_ROOM_RIGHT,
                GameData.SPR_UI_MAP_ROOM_UP,
                GameData.SPR_UI_MAP_ROOM_UP_RIGHT,
                GameData.SPR_UI_MAP_ROOM_LEFT,
                GameData.SPR_UI_MAP_ROOM_LEFT_RIGHT,
                GameData.SPR_UI_MAP_ROOM_LEFT_UP,
                GameData.SPR_UI_MAP_ROOM_LEFT_UP_RIGHT,
                GameData.SPR_UI_MAP_ROOM_DOWN,
                GameData.SPR_UI_MAP_ROOM_DOWN_RIGHT,
                GameData.SPR_UI_MAP_ROOM_DOWN_UP,
                GameData.SPR_UI_MAP_ROOM_DOWN_UP_RIGHT,
                GameData.SPR_UI_MAP_ROOM_DOWN_LEFT,
                GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_RIGHT,
                GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_UP,
                GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_UP_RIGHT,
            };

            // Check for room connections.
            int[] connected = new int[] { 0, 0, 0, 0 };
            for (int y = 0; y < room.Height; y++) {
                bool freeOnRight = true;
                bool freeOnLeft = true;
                for (int i = 0; i < room.LayerCount; i++) {
                    TileDataInstance left = room.GetTile(0, y, i);
                    if (left != null && left.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(left.Type))
                        freeOnLeft = false;
                    TileDataInstance right = room.GetTile(room.Width - 1, y, i);
                    if (right != null && right.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(right.Type))
                        freeOnRight = false;;
                }
                if (freeOnRight)
                    connected[Directions.Right] = 1;
                if (freeOnLeft)
                    connected[Directions.Left] = 1;
            }
            for (int x = 0; x < room.Width; x++) {
                bool freeOnUp = true;
                bool freeOnDown = true;
                for (int i = 0; i < room.LayerCount; i++) {
                    TileDataInstance up = room.GetTile(x, 0, i);
                    TileDataInstance down = room.GetTile(x, room.Height - 1, i);
                    if (up != null && up.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(up.Type))
                        freeOnUp = false;
                    if (down != null && down.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(down.Type))
                        freeOnDown = false;
                }
                if (freeOnUp)
                    connected[Directions.Up] = 1;
                if (freeOnDown)
                    connected[Directions.Down] = 1;
            }

            int spiteIndex = (connected[0]) + (connected[1] << 1) + (connected[2] << 2) + (connected[3] << 3);
            mapRoom.sprite = connectedSprites[spiteIndex];

            return mapRoom;
        }
Example #19
0
        // Load a single room from an java level file.
        public static Room LoadJavaRoom(BinaryReader bin, Level level, int locX, int locY)
        {
            byte width		= bin.ReadByte();
            byte height		= bin.ReadByte();
            level.RoomSize	= new Point2I(width, height);
            Room room		= new Room(level, locX, locY);
            room.Zone		= GameData.ZONE_SUMMER;

            // Read the tile data.
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    byte tilesetIndex = bin.ReadByte();

                    if (tilesetIndex > 0) {
                        Tileset tileset = GameData.TILESET_OVERWORLD;
                        if (tilesetIndex == 2)
                            tileset = GameData.TILESET_INTERIOR;
                        byte tilesetSourceX = bin.ReadByte();
                        byte tilesetSourceY = bin.ReadByte();
                        room.CreateTile(tileset.TileData[tilesetSourceX, tilesetSourceY], x, y, 0);
                    }
                    else {
                        // Only use default tiles on bottom layer.
                        Tileset tileset = GameData.TILESET_OVERWORLD;
                        room.CreateTile(tileset.TileData[tileset.DefaultTile.X, tileset.DefaultTile.Y], x, y, 0);
                    }

                }
            }

            return room;
        }
Example #20
0
        public void TransitionToRoom(Room nextRoom, RoomTransition transition)
        {
            // Create the new room control.
            RoomControl newControl = new RoomControl();
            newControl.gameManager	= gameManager;
            newControl.level		= level;
            newControl.room			= nextRoom;
            newControl.roomLocation	= nextRoom.Location;

            // Play the transition.
            transition.OldRoomControl = this;
            transition.NewRoomControl = newControl;
            gameManager.PopGameState();
            gameManager.PushGameState(transition);
            GameControl.RoomControl = newControl;
        }
Example #21
0
        // Start a new game.
        public void StartGame()
        {
            roomTicks = 0;

            // Setup the player beforehand so certain classes such as the HUD can reference it
            player = new Player();

            inventory						= new Inventory(this);
            menuWeapons						= new MenuWeapons(gameManager);
            menuSecondaryItems				= new MenuSecondaryItems(gameManager);
            menuEssences					= new MenuEssences(gameManager);
            menuWeapons.PreviousMenu		= menuEssences;
            menuWeapons.NextMenu			= menuSecondaryItems;
            menuSecondaryItems.PreviousMenu	= menuWeapons;
            menuSecondaryItems.NextMenu		= menuEssences;
            menuEssences.PreviousMenu		= menuSecondaryItems;
            menuEssences.NextMenu			= menuWeapons;

            mapDungeon = new ScreenDungeonMap(gameManager);

            GameData.LoadInventory(inventory, true);

            inventory.ObtainAmmo("ammo_ember_seeds");
            inventory.ObtainAmmo("ammo_scent_seeds");
            inventory.ObtainAmmo("ammo_pegasus_seeds");
            inventory.ObtainAmmo("ammo_gale_seeds");
            inventory.ObtainAmmo("ammo_mystery_seeds");

            hud = new HUD(this);
            hud.DynamicHealth = player.Health;

            rewardManager = new RewardManager(this);
            GameData.LoadRewards(rewardManager);
            dropManager = new DropManager(this);
            GameData.LoadDrops(dropManager, rewardManager);

            // Create the script runner.
            scriptRunner = new ScriptRunner(this);

            // Create the room control.
            roomControl = new RoomControl();
            gameManager.PushGameState(roomControl);

            // Load the world.
            //WorldFile worldFile = new WorldFile();
            //world = worldFile.Load("Content/Worlds/temp_world.zwd");

            // Begin the room state.
            if (gameManager.LaunchParameters.Length > 0) {
                LoadWorld(gameManager.LaunchParameters[0]);

                if (gameManager.LaunchParameters.Length > 1 && gameManager.LaunchParameters[1] == "-test") {
                    // Launch parameters can define player's start position.
                    int startLevel = Int32.Parse(gameManager.LaunchParameters[2]);
                    int startRoomX = Int32.Parse(gameManager.LaunchParameters[3]);
                    int startRoomY = Int32.Parse(gameManager.LaunchParameters[4]);
                    int startPlayerX = Int32.Parse(gameManager.LaunchParameters[5]);
                    int startPlayerY = Int32.Parse(gameManager.LaunchParameters[6]);

                    player.SetPositionByCenter(new Point2I(startPlayerX, startPlayerY) * GameSettings.TILE_SIZE + new Point2I(8, 8));
                    player.MarkRespawn();
                    roomControl.BeginRoom(world.Levels[startLevel].Rooms[startRoomX, startRoomY]);
                }
                else {
                    player.SetPositionByCenter(world.StartTileLocation * GameSettings.TILE_SIZE + new Point2I(8, 8));
                    player.MarkRespawn();
                    roomControl.BeginRoom(world.StartRoom);
                }
            }
            else {
                //WorldFile worldFile = new WorldFile();
                //world = worldFile.Load("temp_world.zwd");
                LoadWorld(GameDebug.CreateTestWorld());
                player.SetPositionByCenter(world.StartTileLocation * GameSettings.TILE_SIZE + new Point2I(8, 8));
                player.MarkRespawn();
                roomControl.BeginRoom(world.StartRoom);
            }
            roomStateStack = new RoomStateStack(new RoomStateNormal());
            roomStateStack.Begin(this);

            if (!roomControl.Room.IsHiddenFromMap)
                lastRoomOnMap = roomControl.Room;

            AudioSystem.MasterVolume = 0.04f; // The way David likes it.
        }
 public virtual void Clone(BaseTileDataInstance copy)
 {
     this.room		= copy.Room;
     this.tileData	= copy.tileData;
     this.properties	= new Properties(this);
     this.properties.BaseProperties = tileData.Properties;
     this.modifiedProperties	= new Properties(this);
     this.modifiedProperties.BaseProperties = tileData.Properties;
     this.properties.SetAll(copy.properties);
 }
Example #23
0
        // Shift the room grid.
        public void Shift(Point2I distance)
        {
            Room[,] oldRooms = rooms;
            rooms = new Room[dimensions.X, dimensions.Y];

            for (int x = 0; x < dimensions.X; x++) {
                for (int y = 0; y < dimensions.Y; y++) {
                    if (x - distance.X >= 0 && x - distance.X < dimensions.X &&
                        y - distance.Y >= 0 && y - distance.Y < dimensions.Y)
                    {
                        rooms[x, y] = oldRooms[x - distance.X, y - distance.Y];
                        rooms[x, y].Location = new Point2I(x, y);
                    }
                    else
                        rooms[x, y] = new Room(this, x, y, Zone ?? Resources.GetResource<Zone>(""));
                }
            }
        }
Example #24
0
        //-----------------------------------------------------------------------------
        // Internal methods
        //-----------------------------------------------------------------------------
        private void ActivateTile(MouseButtons mouseButton, Room room, Point2I tileLocation)
        {
            if (mouseButton == MouseButtons.Left) {
                room.CreateTile(
                    editorControl.SelectedTilesetTileData,
                    tileLocation.X, tileLocation.Y, editorControl.CurrentLayer
                );

            }
            else if (mouseButton == MouseButtons.Right) {
                if (editorControl.CurrentLayer == 0) {
                    room.CreateTile(
                        editorControl.Tileset.DefaultTileData,
                        tileLocation.X, tileLocation.Y, editorControl.CurrentLayer
                    );
                }
                else {
                    room.RemoveTile(tileLocation.X, tileLocation.Y, editorControl.CurrentLayer);
                }
            }
            else if (mouseButton == MouseButtons.Middle) {
                // Sample the tile.
                TileDataInstance tile = room.GetTile(tileLocation, EditorControl.CurrentLayer);
                if (tile != null) {
                    editorControl.SelectedTilesetTile = -Point2I.One;
                    editorControl.SelectedTilesetTileData = tile.TileData;
                }
            }
        }
Example #25
0
        //-----------------------------------------------------------------------------
        // Mutators
        //-----------------------------------------------------------------------------
        // Resize the dimensions of the room grid.
        public void Resize(Point2I size)
        {
            Room[,] oldRooms = rooms;
            rooms = new Room[size.X, size.Y];

            for (int x = 0; x < size.X; x++) {
                for (int y = 0; y < size.Y; y++) {
                    if (oldRooms != null && x < dimensions.X && y < dimensions.Y)
                        rooms[x, y] = oldRooms[x, y];
                    else
                        rooms[x, y] = new Room(this, x, y, Zone ?? GameData.ZONE_DEFAULT);
                }
            }

            dimensions = size;
        }
Example #26
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            Point2I mousePos	= new Point2I(e.X, e.Y);
            Room	room		= LevelDisplayControl.SampleRoom(mousePos);
            Point2I tileCoord	= LevelDisplayControl.SampleTileCoordinates(mousePos);

            if (e.Button == MouseButtons.Left && room != null) {
                if (!editorControl.EventMode) {
                    if (System.Windows.Forms.Control.ModifierKeys == Keys.Shift) {
                        selectedRoom = room;
                        Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, Point2I.Zero);
                        LevelDisplayControl.SetSelectionBox(levelTileCoord, room.Size);
                        EditorControl.PropertyGridControl.OpenProperties(room.Properties, room);
                    }
                    else {
                        // Select tiles.
                        selectedTile = room.GetTile(tileCoord, editorControl.CurrentLayer);

                        if (selectedTile != null) {
                            Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord);
                            LevelDisplayControl.SetSelectionBox(levelTileCoord, Point2I.One);
                            EditorControl.PropertyGridControl.OpenProperties(selectedTile.Properties, selectedTile);
                        }
                        else {
                            LevelDisplayControl.ClearSelectionBox();
                            EditorControl.PropertyGridControl.CloseProperties();
                        }
                    }
                }
                else {
                    // Select events.
                    selectedEventTile = LevelDisplayControl.SampleEventTile(mousePos);

                    if (selectedEventTile != null) {
                        Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord);
                        LevelDisplayControl.SetSelectionBox(levelTileCoord, Point2I.One);
                        EditorControl.PropertyGridControl.OpenProperties(selectedEventTile.Properties, selectedEventTile);
                    }
                    else {
                        LevelDisplayControl.ClearSelectionBox();
                        EditorControl.PropertyGridControl.CloseProperties();
                    }
                }
            }
        }
Example #27
0
        private void ActivateTile(MouseButtons mouseButton, Room room, Point2I tileLocation)
        {
            TileDataInstance tile = room.GetTile(tileLocation, EditorControl.CurrentLayer);

            if (mouseButton == MouseButtons.Left) {
                TileData selectedTilesetTileData = editorControl.SelectedTilesetTileData as TileData;

                if (selectedTilesetTileData != null) {
                    // Remove the existing tile.
                    if (tile != null) {
                        room.RemoveTile(tile);
                        editorControl.OnDeleteObject(tile);
                    }
                    // Place the new tile.
                    room.PlaceTile(
                        new TileDataInstance(selectedTilesetTileData),
                        tileLocation.X, tileLocation.Y, editorControl.CurrentLayer);
                }
            }
            else if (mouseButton == MouseButtons.Right) {
                // Erase the tile.
                if (tile != null) {
                    room.RemoveTile(tile);
                    editorControl.OnDeleteObject(tile);
                }
            }
            else if (mouseButton == MouseButtons.Middle) {
                // Sample the tile.
                if (tile != null) {
                    editorControl.SelectedTilesetTile		= -Point2I.One;
                    editorControl.SelectedTilesetTileData	= tile.TileData;
                }
            }
        }
Example #28
0
        //-----------------------------------------------------------------------------
        // Mutators
        //-----------------------------------------------------------------------------
        // Resize the dimensions of the room grid.
        public void Resize(Point2I size)
        {
            Room[,] oldRooms = rooms;
            rooms = new Room[size.X, size.Y];

            for (int x = 0; x < size.X; x++) {
                for (int y = 0; y < size.Y; y++) {
                    if (oldRooms != null && x < dimensions.X && y < dimensions.Y)
                        rooms[x, y] = oldRooms[x, y];
                    else
                        rooms[x, y] = new Room(this, x, y, zone ?? Resources.GetResource<Zone>(""));
                }
            }

            dimensions = size;
        }