Recent Posts
mIRC | 8 sec ago
None | 21 sec ago
None | 35 sec ago
None | 39 sec ago
None | 50 sec ago
PHP | 59 sec ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
JavaScript | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 10th of Feb 2010 12:30:34 AM Download | Raw | Embed | Report
  1. -- GLOBAL VERIABLE DEFINITIONS
  2. global gMapEditor
  3.  
  4.  
  5. -- PROPERTY DEFINITIONS
  6. property pData
  7. property pCoords
  8. property pItems
  9.  
  10.  
  11. -- Parent script initialization.
  12. on new(me)
  13.   me.pItems = [:]
  14.   return(me)
  15. end new
  16.  
  17.  
  18. -- Defines the new map data.
  19. -- The map data is stored as a property list.
  20. -- If the data parameter is VOID, a default set of data is assigned.
  21. on setData(me, data, type)
  22.   if (voidP(data)) then
  23.     data = [:]
  24.     repeat with i = 1 to 4
  25.       data.addProp(symbol("layer" & i), [:])
  26.       repeat with j = 1 to 12
  27.         data[i].addProp(symbol("row" & j), [])
  28.         repeat with k = 1 to 17
  29.           if (i = 1) then
  30.             data[i][j].add(2)
  31.           else
  32.             data[i][j].add(1)
  33.           end if
  34.         end repeat
  35.       end repeat
  36.     end repeat
  37.     data.addProp(#items, [])
  38.     data.addProp(#blockedtiles, [])
  39.     data.addProp(#safe, true)
  40.     data.addProp(#pvp, false)
  41.     data.addProp(#respawn, false)
  42.   end if
  43.   me.pData = data
  44.   me.renderMap(data, type)
  45.   me.renderItems()
  46. end setData
  47.  
  48.  
  49. -- Renders the map layer images with the given data.
  50. -- Once the map has been rendered, the movie stage is refreshed.
  51. on renderMap(me, data, type)
  52.   mapLayer1 = image(544, 384, 16)
  53.   mapLayer2 = image(544, 384, 16)
  54.   mapLayer3 = image(544, 384, 16)
  55.   mapLayer4 = image(544, 384, 16)
  56.   repeat with i = 1 to 4
  57.     repeat with row = 1 to 12
  58.       repeat with column = 1 to 17
  59.         tile = member(data[i][row][column], "Map Tiles").image
  60.         sourceRect = tile.rect
  61.         top = (row - 1) * 32
  62.         left = (column - 1) * 32
  63.         targetRect = rect(left, top, left + 32, top + 32)
  64.         case (i) of
  65.           1: mapLayer1.copyPixels(tile, targetRect, sourceRect)
  66.           2: mapLayer2.copyPixels(tile, targetRect, sourceRect)
  67.           3: mapLayer3.copyPixels(tile, targetRect, sourceRect)
  68.           4: mapLayer4.copyPixels(tile, targetRect, sourceRect)
  69.         end case
  70.       end repeat
  71.     end repeat
  72.   end repeat
  73.   member("MapLayer1", "Internal").image = mapLayer1
  74.   member("MapLayer2", "Internal").image = mapLayer2
  75.   member("MapLayer3", "Internal").image = mapLayer3
  76.   member("MapLayer4", "Internal").image = mapLayer4
  77.   -- Renders all the blocked tiles when using map editor.
  78.   if (type = #mapeditor_load) then
  79.     tempImage = image(544, 384, 16)
  80.     tempImage.fill(tempImage.rect, rgb(0, 255, 0))
  81.     member("BlockedTileLayer", "Internal").image = tempImage
  82.     blockedTiles = me.getBlockedTiles()
  83.     pcount = blockedTiles.count
  84.     repeat with i = 1 to pcount
  85.       gMapEditor.renderBlockedTile(#add, blockedTiles[i])
  86.     end repeat
  87.   end if
  88.   _movie.updateStage()
  89. end renderMap
  90.  
  91.  
  92. -- Returns the current map data as a property list.
  93. on getData(me)
  94.   return(me.pData)
  95. end getData
  96.  
  97.  
  98. -- Returns the current map items as a linear list.
  99. on getItems(me)
  100.   return(me.getData().items)
  101. end getItems
  102.  
  103.  
  104. -- Sets the current map items.
  105. on setItems(me, itemList)
  106.   me.pData.items = itemList
  107. end setItems
  108.  
  109.  
  110. -- Returns the current map coords as a linear list.
  111. on getCoords(me)
  112.   return(me.pCoords)
  113. end getCoords
  114.  
  115.  
  116. -- Sets the current map coords.
  117. -- Passed as a string but stored in a linear list.
  118. -- The coords are then placed inside the map editor fields.
  119. on setCoords(me, coords)
  120.   me.pCoords = coords
  121.   member("MapX", "User Interface").text = string(me.pCoords[1])
  122.   member("MapY", "User Interface").text = string(me.pCoords[2])
  123. end setCoords
  124.  
  125.  
  126. -- Returns the list of blocked tiles coords as a linear list.
  127. -- The coords are also stored as a linear list.
  128. on getBlockedTiles(me)
  129.   data = me.getData()
  130.   return(data.blockedtiles)
  131. end getBlockedTiles
  132.  
  133.  
  134. -- Adds a tile location to the blocked tile list.
  135. -- The blocked tiles list is stored as a linear list.
  136. on addToBlockedTiles(me, coords)
  137.   data = me.getData()
  138.   blockedTiles = data.blockedtiles
  139.   case (gMapEditor.getBrushType()) of
  140.     #pencil:
  141.       if not(blockedTiles.getPos(coords) = 0) then exit
  142.       gMapEditor.renderBlockedTile(#add, coords)
  143.       blockedTiles.add(coords)
  144.     #fill:
  145.       repeat with row = 1 to 12
  146.         repeat with column = 1 to 17
  147.           if not(blockedTiles.getPos([column, row]) = 0) then next repeat
  148.           gMapEditor.renderBlockedTile(#add, [column, row])
  149.           blockedTiles.add([column, row])
  150.         end repeat
  151.       end repeat
  152.   end case
  153.   data.blockedtiles = blockedTiles
  154.   me.setData(data)
  155. end addToBlockedTiles
  156.  
  157.  
  158. -- Removes a tile location from the blocked tile list.
  159. -- The blocked tiles list is stored as a linear list.
  160. on removeFromBlockedTiles(me, coords)
  161.   data = me.getData()
  162.   blockedTiles = data.blockedtiles
  163.   case (gMapEditor.getBrushType()) of
  164.     #pencil:
  165.       gMapEditor.renderBlockedTile(#remove, coords)
  166.       position = blockedTiles.getPos(coords)
  167.       if (position = 0) then exit
  168.       blockedTiles.deleteAt(position)
  169.     #fill:
  170.       repeat with row = 1 to 12
  171.         repeat with column = 1 to 17
  172.           gMapEditor.renderBlockedTile(#remove, [column, row])
  173.           position = blockedTiles.getPos([column, row])
  174.           if (position = 0) then next repeat
  175.           blockedTiles.deleteAt(position)
  176.         end repeat
  177.       end repeat
  178.   end case
  179.   data.blockedtiles = blockedTiles
  180.   me.setData(data)
  181. end removeFromBlockedTiles
  182.  
  183.  
  184. -- Show the map loading screen.
  185. -- Used for when a map has not completeled loading.
  186. -- When showing the loading screen, all items are remove from the map.
  187. on loadingScreen(me, type)
  188.   if (voidP(type)) then type = #show
  189.   case (type) of
  190.     #show: sprite(1000).visible = true
  191.     #hide: sprite(1000).visible = false
  192.     #check: return(sprite(1000).visible)
  193.   end case
  194. end loadingScreen
  195.  
  196.  
  197. -- Renders all items on the map.
  198. on renderItems(me)
  199.   itemList = me.getItems()
  200.   put(itemList)
  201.   count = itemList.count
  202.   if (count = 0) then exit
  203.   repeat with i = 1 to count
  204.     me.addItemToMap(itemList[i][1], itemList[i][2], #render)
  205.   end repeat
  206. end renderItems
  207.  
  208.  
  209. -- Removes all items from the map.
  210. -- Used when moving from one map to another.
  211. on removeItems(me)
  212.   itemList = me.getItems()
  213.   count = itemList.count
  214.   if (count = 0) then exit
  215.   repeat with i = 1 to count
  216.     me.removeItemFromMap(itemList[1][1], itemList[1][2], #all)
  217.   end repeat
  218. end removeItems
  219.  
  220.  
  221. -- Adds an item to the map.
  222. on addItemToMap(me, itemName, location, type)
  223.   if not(type = #render) then
  224.     itemList = me.getItems()
  225.     if not(itemList.getPos([itemName, location]) = 0) then exit
  226.     itemList.add([itemName, location])
  227.     me.setItems(itemList)
  228.   end if
  229.   objectName = itemName & "-" & location[1] & "-" & location[2]
  230.   itemObject = me.pItems.getAProp(objectName)
  231.   if not(voidP(itemObject)) then
  232.     put("[Map Manager] addItemToMap() function called when item already exists in that location.")
  233.     exit
  234.   end if
  235.   itemScript = script("ItemScript").new(itemName, location)
  236.   me.pItems.addProp(objectName, itemScript)
  237.   itemScript.findSpriteChannel()
  238.   itemScript.resetBitmap()
  239.   itemScript.renderBitmap()
  240. end addItemToMap
  241.  
  242.  
  243. -- Removes an item from the map.
  244. on removeItemFromMap(me, itemName, location, type)
  245.   if (type = #all) then
  246.     itemList = me.getItems()
  247.     position = itemList.getPos([itemName, location])
  248.     if (position = 0) then exit
  249.     itemList.deleteAt(position)
  250.     me.setItems(itemList)
  251.   end if
  252.   objectName = itemName & "-" & location[1] & "-" & location[2]
  253.   itemObject = me.pItems.getAProp(objectName)
  254.   if (voidP(itemObject)) then
  255.     put("[Map Manager] removeItemFromMap() function called when item doesn't exist.")
  256.     exit
  257.   end if
  258.   itemObject.deleteSprite()
  259.   itemObject.deleteBitmap()
  260.   position = listPos(me.pItems, objectName)
  261.   me.pItems.deleteAt(position)
  262. end removeItemFromMap
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: