Guest User

Untitled

a guest
Jul 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. /*
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. *
  21. * User: Jesse Freeman
  22. * Date: 12/15/10
  23. * Time: 9:43 PM
  24. *
  25. */
  26. package com.gamecook.patdownpete.sprites
  27. {
  28. import flash.display.Bitmap;
  29. import flash.display.BitmapData;
  30. import flash.geom.Point;
  31. import flash.geom.Rectangle;
  32.  
  33. public class ColorMap extends Bitmap
  34. {
  35.  
  36. private var colorMap:Array = [];
  37. private var colorKey:Rectangle;
  38.  
  39. public function ColorMap(bitmapData:BitmapData, colorKey:Rectangle)
  40. {
  41. super(bitmapData);
  42. parseColorMap(colorKey);
  43. }
  44.  
  45. public function parseColorMap(colorKey:Rectangle):void
  46. {
  47. this.colorKey = colorKey;
  48.  
  49. if (bitmapData)
  50. {
  51. var pixel:uint;
  52.  
  53. for (var x:int = colorKey.x; x < colorKey.width; x++)
  54. {
  55. for (var y:int = colorKey.y; y < colorKey.height; y++)
  56. {
  57. pixel = bitmapData.getPixel(x, y);
  58. if (colorMap.indexOf(pixel) == -1)
  59. {
  60. colorMap.push(pixel);
  61. }
  62. }
  63. }
  64.  
  65. }
  66. else
  67. {
  68. throw new Error("You must have BitmapData before parsing a color map.");
  69. }
  70.  
  71. }
  72.  
  73. public function clear():void
  74. {
  75. bitmapData = null;
  76. colorMap.length = 0;
  77. }
  78.  
  79. public function testCollision(point:Point):int
  80. {
  81. if (colorKey.containsPoint(point))
  82. return 0;
  83.  
  84. var index:int = colorMap.indexOf(bitmapData.getPixel(point.x, point.y));
  85. return index == -1 ? 0 : index;
  86.  
  87. }
  88. }
  89. }
Add Comment
Please, Sign In to add comment