- -- GLOBAL VERIABLE DEFINITIONS
- global gMapEditor
- -- PROPERTY DEFINITIONS
- property pData
- property pCoords
- property pItems
- -- Parent script initialization.
- on new(me)
- me.pItems = [:]
- return(me)
- end new
- -- Defines the new map data.
- -- The map data is stored as a property list.
- -- If the data parameter is VOID, a default set of data is assigned.
- on setData(me, data, type)
- if (voidP(data)) then
- data = [:]
- repeat with i = 1 to 4
- data.addProp(symbol("layer" & i), [:])
- repeat with j = 1 to 12
- data[i].addProp(symbol("row" & j), [])
- repeat with k = 1 to 17
- if (i = 1) then
- data[i][j].add(2)
- else
- data[i][j].add(1)
- end if
- end repeat
- end repeat
- end repeat
- data.addProp(#items, [])
- data.addProp(#blockedtiles, [])
- data.addProp(#safe, true)
- data.addProp(#pvp, false)
- data.addProp(#respawn, false)
- end if
- me.pData = data
- me.renderMap(data, type)
- me.renderItems()
- end setData
- -- Renders the map layer images with the given data.
- -- Once the map has been rendered, the movie stage is refreshed.
- on renderMap(me, data, type)
- mapLayer1 = image(544, 384, 16)
- mapLayer2 = image(544, 384, 16)
- mapLayer3 = image(544, 384, 16)
- mapLayer4 = image(544, 384, 16)
- repeat with i = 1 to 4
- repeat with row = 1 to 12
- repeat with column = 1 to 17
- tile = member(data[i][row][column], "Map Tiles").image
- sourceRect = tile.rect
- top = (row - 1) * 32
- left = (column - 1) * 32
- targetRect = rect(left, top, left + 32, top + 32)
- case (i) of
- 1: mapLayer1.copyPixels(tile, targetRect, sourceRect)
- 2: mapLayer2.copyPixels(tile, targetRect, sourceRect)
- 3: mapLayer3.copyPixels(tile, targetRect, sourceRect)
- 4: mapLayer4.copyPixels(tile, targetRect, sourceRect)
- end case
- end repeat
- end repeat
- end repeat
- member("MapLayer1", "Internal").image = mapLayer1
- member("MapLayer2", "Internal").image = mapLayer2
- member("MapLayer3", "Internal").image = mapLayer3
- member("MapLayer4", "Internal").image = mapLayer4
- -- Renders all the blocked tiles when using map editor.
- if (type = #mapeditor_load) then
- tempImage = image(544, 384, 16)
- tempImage.fill(tempImage.rect, rgb(0, 255, 0))
- member("BlockedTileLayer", "Internal").image = tempImage
- blockedTiles = me.getBlockedTiles()
- pcount = blockedTiles.count
- repeat with i = 1 to pcount
- gMapEditor.renderBlockedTile(#add, blockedTiles[i])
- end repeat
- end if
- _movie.updateStage()
- end renderMap
- -- Returns the current map data as a property list.
- on getData(me)
- return(me.pData)
- end getData
- -- Returns the current map items as a linear list.
- on getItems(me)
- return(me.getData().items)
- end getItems
- -- Sets the current map items.
- on setItems(me, itemList)
- me.pData.items = itemList
- end setItems
- -- Returns the current map coords as a linear list.
- on getCoords(me)
- return(me.pCoords)
- end getCoords
- -- Sets the current map coords.
- -- Passed as a string but stored in a linear list.
- -- The coords are then placed inside the map editor fields.
- on setCoords(me, coords)
- me.pCoords = coords
- member("MapX", "User Interface").text = string(me.pCoords[1])
- member("MapY", "User Interface").text = string(me.pCoords[2])
- end setCoords
- -- Returns the list of blocked tiles coords as a linear list.
- -- The coords are also stored as a linear list.
- on getBlockedTiles(me)
- data = me.getData()
- return(data.blockedtiles)
- end getBlockedTiles
- -- Adds a tile location to the blocked tile list.
- -- The blocked tiles list is stored as a linear list.
- on addToBlockedTiles(me, coords)
- data = me.getData()
- blockedTiles = data.blockedtiles
- case (gMapEditor.getBrushType()) of
- #pencil:
- if not(blockedTiles.getPos(coords) = 0) then exit
- gMapEditor.renderBlockedTile(#add, coords)
- blockedTiles.add(coords)
- #fill:
- repeat with row = 1 to 12
- repeat with column = 1 to 17
- if not(blockedTiles.getPos([column, row]) = 0) then next repeat
- gMapEditor.renderBlockedTile(#add, [column, row])
- blockedTiles.add([column, row])
- end repeat
- end repeat
- end case
- data.blockedtiles = blockedTiles
- me.setData(data)
- end addToBlockedTiles
- -- Removes a tile location from the blocked tile list.
- -- The blocked tiles list is stored as a linear list.
- on removeFromBlockedTiles(me, coords)
- data = me.getData()
- blockedTiles = data.blockedtiles
- case (gMapEditor.getBrushType()) of
- #pencil:
- gMapEditor.renderBlockedTile(#remove, coords)
- position = blockedTiles.getPos(coords)
- if (position = 0) then exit
- blockedTiles.deleteAt(position)
- #fill:
- repeat with row = 1 to 12
- repeat with column = 1 to 17
- gMapEditor.renderBlockedTile(#remove, [column, row])
- position = blockedTiles.getPos([column, row])
- if (position = 0) then next repeat
- blockedTiles.deleteAt(position)
- end repeat
- end repeat
- end case
- data.blockedtiles = blockedTiles
- me.setData(data)
- end removeFromBlockedTiles
- -- Show the map loading screen.
- -- Used for when a map has not completeled loading.
- -- When showing the loading screen, all items are remove from the map.
- on loadingScreen(me, type)
- if (voidP(type)) then type = #show
- case (type) of
- #show: sprite(1000).visible = true
- #hide: sprite(1000).visible = false
- #check: return(sprite(1000).visible)
- end case
- end loadingScreen
- -- Renders all items on the map.
- on renderItems(me)
- itemList = me.getItems()
- put(itemList)
- count = itemList.count
- if (count = 0) then exit
- repeat with i = 1 to count
- me.addItemToMap(itemList[i][1], itemList[i][2], #render)
- end repeat
- end renderItems
- -- Removes all items from the map.
- -- Used when moving from one map to another.
- on removeItems(me)
- itemList = me.getItems()
- count = itemList.count
- if (count = 0) then exit
- repeat with i = 1 to count
- me.removeItemFromMap(itemList[1][1], itemList[1][2], #all)
- end repeat
- end removeItems
- -- Adds an item to the map.
- on addItemToMap(me, itemName, location, type)
- if not(type = #render) then
- itemList = me.getItems()
- if not(itemList.getPos([itemName, location]) = 0) then exit
- itemList.add([itemName, location])
- me.setItems(itemList)
- end if
- objectName = itemName & "-" & location[1] & "-" & location[2]
- itemObject = me.pItems.getAProp(objectName)
- if not(voidP(itemObject)) then
- put("[Map Manager] addItemToMap() function called when item already exists in that location.")
- exit
- end if
- itemScript = script("ItemScript").new(itemName, location)
- me.pItems.addProp(objectName, itemScript)
- itemScript.findSpriteChannel()
- itemScript.resetBitmap()
- itemScript.renderBitmap()
- end addItemToMap
- -- Removes an item from the map.
- on removeItemFromMap(me, itemName, location, type)
- if (type = #all) then
- itemList = me.getItems()
- position = itemList.getPos([itemName, location])
- if (position = 0) then exit
- itemList.deleteAt(position)
- me.setItems(itemList)
- end if
- objectName = itemName & "-" & location[1] & "-" & location[2]
- itemObject = me.pItems.getAProp(objectName)
- if (voidP(itemObject)) then
- put("[Map Manager] removeItemFromMap() function called when item doesn't exist.")
- exit
- end if
- itemObject.deleteSprite()
- itemObject.deleteBitmap()
- position = listPos(me.pItems, objectName)
- me.pItems.deleteAt(position)
- end removeItemFromMap