Downloads containing TrueColor v12.asc

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Nyan Rush sAlAmAnDeR Mutator N/A Download file
JJ2+ Only: Foo Single Player 2/14:...Featured Download Violet CLM Single player 10 Download file
TSF with JJ2+ Only: Operation Cleanup: Turtle...Featured Download happygreenfrog Single player 8.2 Download file

File preview

  1. //TrueColor v12.asc: version 1.2 (2018/02/08)
  2. #pragma require "TrueColor v12.asc"
  3.  
  4. /*
  5. TrueColor v12.asc lets scriptwriters create palette-independent images to be drawn to the screen as sprites, meaning you can script an enemy, pickup, etc. that uses colors that are nowhere to be found in the level's palette. This is accomplished over a series of three steps, repeatable as many times as you like:
  6. 1) Load an external .bmp file from the player's harddrive into memory in a TrueColor::Bitmap object.
  7. 2) Call TrueColor::Bitmap::saveToAnimFrames one or more times, or simplify by using the TrueColor::AllocateSpriteSheet function, to save one or more rectangular subareas from the bitmap image into one or more series of subsequent jjANIMFRAMEs, using one or more TrueColor::Coordinates objects to specify how much of the bitmap image to save.
  8. 3) Use the various TrueColor drawing functions (NOT the normal jjDraw* functions or jjCANVAS::draw* methods) to draw the resulting images, as stored in jjANIMFRAMEs series, to the screen.
  9.  
  10. A note for when designing external .bmp files for use with this library: color 0,0,0 is FULLY TRANSPARENT. Any other color is FULLY OPAQUE. TrueColor v12.asc does not offer greater than 1-bit alpha at this time.
  11.  
  12. API:
  13.         const uint TrueColor::NumberOfFramesPerImage
  14.                 Each TrueColor image, in order to be usable by drawing code, is saved to a series of (TrueColor::NumberOfFramesPerImage) subsequent jjANIMFRAME objects. You will need to be able to multiply and/or divide by this number when dealing with any animation more than one image long. For instance, if you want to draw the third(2) image from a TrueColor animation stored as the first(0) animation in ANIM::SPARK:
  15.                         TrueColor::DrawSprite(100, 100, ANIM::SPARK, 0, 2 * TrueColor::NumberOfFramesPerImage);
  16.        
  17.        
  18.         ANIM::Set TrueColor::FindCustomAnim()
  19.                 A convenience function not used directly by any part of the TrueColor library, TrueColor::FindCustomAnim simply finds you an ANIM::Set constant such that allocating a new animset to it would not interfere with any existing code running in the level.
  20.        
  21.         void TrueColor::ProcessPalette()
  22.                 This function must be called at the beginning of the level and again any time jjPAL::apply is called. This is because the TrueColor images, while visually palette-independent, must still use the contents of jjPalette in order to set themselves up as jjANIMFRAME images, and the details of this process can change slightly every time the palette is edited. As a result, constant jjPalette changes are an even worse idea in levels with TrueColor images than they are the rest of the time.
  23.                
  24.         void TrueColor::EnableCaching(bool enable = true)
  25.                 Enabling caching has two separate effects. First, every time you save a (subarea of a) bitmap image to some jjANIMFRAMEs (either directly through TrueColor::Bitmap::saveToAnimFrames or indirectly through TrueColor::AllocateSpriteSheet), TrueColor v12.asc will cache what image data was saved to which frames. Second, every time TrueColor::ProcessPalette is called, all cached image data will be saved to their respective animframes again, using the new palette. If caching is NOT enabled when ProcessPalette() is called, all previously saved TrueColor images must be MANUALLY saved to their respective jjANIMFRAMEs all over again, though the actual animset allocation need not be repeated.
  26.                
  27.                 Note that the resaving of the cached images is done in response to TrueColor::ProcessPalette, not in response to jjPAL::apply, which may present difficulties if jjPAL::apply is called by a script module other than the one including TrueColor v12.asc. At worst you can try using jjPAL::operator==.
  28.                
  29.                 Disabling caching (i.e. passing "false") will not empty the existing cache, it will only prevent the cache from being added to or used until such time as caching is enabled again. As a general rule, you should enable caching iff your script includes one or more palette changes, so that you don't have to do that work manually, but it will serve no purpose (and only take up unneeded memory) if your palette never changes.
  30.        
  31.         void TrueColor::AllocateSpriteSheet(const ANIM::Set setID, const Bitmap& bitmap, const array<array<TrueColor::Coordinates>>& setCoordinates = array<array<TrueColor::Coordinates>>(1, array<TrueColor::Coordinates>(1)))
  32.                 An all-in-one function that 1) allocates an entire new animset (at jjAnimSets[setID]) with its length and the lengths of each of its animations determined by the sizes of setCoordinates, then 2) saves all bitmap's rectangular subareas (defined by setCoordinates' various TrueColor::Coordinates objects) into the jjANIMFRAMEs of that animset. This is almost the same thing as jjANIMSET::load, with the caveats that a) all the sprite properties are defined in the script instead of in a .j2a file, and b) you must remember to use TrueColor::NumberOfFramesPerImage when browsing frames within any animations so allocated.
  33.                
  34.                 See example script for example.
  35.        
  36.         void TrueColor::DrawSprite(float xPixel, float yPixel, int setID, uint8 animation, uint frame, int direction = 0, uint8 layerZ = 4, uint8 layerXY = 4, int8 playerID = -1)
  37.         void TrueColor::DrawCanvasSprite(jjCANVAS@ canvas, int xPixel, int yPixel, int setID, uint8 animation, uint frame, int8 direction = 0)
  38.         ...
  39.                 All single sprite drawing functions--Sprite, ResizedSprite, RotatedSprite, and SwingingVineSprite, both with and without FromCurFrame--are recreated in TrueColor. The argument pattern is always exactly the same as the normal JJ2+ version's, except for the spriteMode and spriteParam arguments, which are omitted entirely. To call the TrueColor equivalent of a jjCANVAS method, insert "Canvas" after "Draw" and pass the jjCANVAS@ as the first argument.
  40.                
  41.                 The sprite will be drawn as semitransparent iff jjANIMFRAME::transparent is true for the first jjAnimFrames entry in the sequence of (TrueColor::NumberOfFramesPerImage) entries. This can be achieved by setting TrueColor::Coordinates::transparent to true while saving them.
  42.                
  43.                 The sprite should be saved with TrueColor::Coordinates::swingingVine as true iff you intend to use either SwingingVineSpriteFromCurFrame function on it. Otherwise it will be drawn incorrectly, just as with normal, none-TrueColor swinging vine sprites.
  44.                
  45.                 There are no TrueColor versions of Pixel, Rectangle, or String (at this time).
  46.        
  47.         void TrueColor::DrawObject(jjOBJ@)
  48.                 A TrueColor version of jjOBJ::draw(), for convenience purposes. Frozen objects will be drawn as frozen (SPRITE::FROZEN), recently hit objects will be drawn all white (SPRITE::SINGLECOLOR), and all other objects will be drawn using a call to TrueColor::DrawSpriteFromCurFrame. No equivalent to SPRITE::GEM is currently provided.
  49.        
  50.        
  51.         class TrueColor::Bitmap
  52.                 A Bitmap is roughly analogous to a jjPIXELMAP, in that it contains an array of pixel colors--here represented by jjPALCOLORs, rather than uint8s--and can be saved to jjANIMFRAMEs. However, its most important constructors are from a string or jjSTREAM, loading a bitmap image (traditionally originating from an external .bmp file) into memory, and it cannot be saved to tiles or textured backgrounds.
  53.                
  54.                 Properties:
  55.                         const uint width
  56.                         const uint height
  57.                         array<array<jjPALCOLOR>> pixels
  58.                                 All the 24-bit colors in the image, accessed pixels[x][y]
  59.                 Methods:
  60.                         Bitmap()
  61.                                 Default constructor is not helpful but required by AS: width and height are 0 and pixels is length 0
  62.                         Bitmap(uint w, uint h)
  63.                                 Constructor from dimensions: sets width and height to w and h and resizes pixels accordingly, filling the arrays with transparent jjPALCOLOR objects (red==0, green==0, blue==0)
  64.                         Bitmap(const string &in fileroot)
  65.                                 Appends ".bmp" to fileroot (e.g. "foo" becomes "foo.bmp") if fileroot does not end with ".bmp" already, and tries to load that file as a 24-bit bitmap file with a width that is a multiple of four pixels. Any failure results in width/height both equalling 0, pixels remaining at length 0, and a variously helpful error message printed to the chatlog; otherwise, the pixels array is filled with the contents of the .bmp file.
  66.                         Bitmap(jjSTREAM &in file)
  67.                                 Tries to load this jjSTREAM as a 24-bit bitmap file with the exact same internal formatting as the file loaded by the previous constructor. There should be no difference between writing "TrueColor::Bitmap bar('foo.bmp');" and writing "TrueColor::Bitmap bar(jjSTREAM('foo.bmp'));" This constructor, however, is more useful in case the image does not come directly from the user's harddrive, e.g. if it is sent from the server to a client in a multiplayer game.
  68.                         Bitmap(const jjPIXELMAP &in pixelmap, const jjPAL &in palette = jjPalette)
  69.                                 Constructs a bitmap with the same dimensions and image as the pixelmap, where for each coordinate pair x,y, bitmap.pixels[x][y] = palette.color[pixelmap[x,y]].
  70.                         Bitmap(const TrueColor::Bitmap &in source, uint left, uint top, uint width, uint height)
  71.                                 First constricts left/top/width/height as needed if they do not actually fit into source's dimensions, then resizes the pixels array to width,height and fills it with the contents of the defined subarea of source. In other words, this is a cropping constructor.
  72.                         void saveToAnimFrames(uint frameID, const TrueColor::Coordinates@ coordinates = null) const
  73.                                 Saves this image, or a subarea within it, to a series of subsequent jjANIMFRAMEs beginning at jjAnimFrames[frameID] and continuing until jjAnimFrames[frameID + TrueColor::NumberOfFramesPerImage]; sets all those jjANIMFRAMEs' hotspot, gunspot, coldspot, and transparency properties according to the equivalent properties on the coordinates argument; and picks the jjANIMFRAMEs' transparency colors based on the coordinates argument's swingingVine property. If the coordinates argument is left null (default), the _entire_ image will be saved to the jjANIMFRAMEs, not a subarea of it, and their hotspots/gunspots/coldspots will all be left at 0,0.
  74.                         void swizzle(COLOR::Component red, COLOR::Component green, COLOR::Component blue)
  75.                                 A shortcut method to apply jjPALCOLOR::swizzle to every pixel in the image.
  76.        
  77.         class TrueColor::Coordinates
  78.                 Roughly analogous to jjANIMFRAME, in that it provides (a series of) jjANIMFRAMEs with their dimensions and hotspot/gunspot/coldspot positions, but its primary purpose is to specify a rectangular subarea of a TrueColor::Bitmap to be saved to jjANIMFRAMEs. For example, a TrueColor::Bitmap with width==100 and height==50, saved to jjANIMFRAMEs using a TrueColor::Coordinates with left=50,top=25,width=50,height=25 would save only the bottom right quadrant of its entire 100x50 image.
  79.                
  80.                 Properties:
  81.                         int hotSpotX, hotSpotY, gunSpotX, gunSpotY, coldSpotX, coldSpotY
  82.                         bool transparent, swingingVine
  83.                 Methods:
  84.                         Coordinates()
  85.                                 Default constructor sets all properties, including dimensions, to 0
  86.                         Coordinates(uint l, uint t, uint w, uint h, int hX = 0, int hY = 0, int gX = 0, int gY = 0, int cX = 0, int cY = 0, bool tr = false, bool sv = false)
  87.                                 Sets dimensions according to the first four arguments (left, top, width, height), then optionally allows you to set all the public properties at the same time as constructing the object
  88.                        
  89. WARNING: All internal code details are subject to change, and any properties, methods, or functions NOT described above should not be used by external scripts for risk of failing to work in later updates to this library.
  90. */
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. namespace TrueColor {
  110.         const uint NumberOfFramesPerImage = 3;
  111.        
  112.         ANIM::Set FindCustomAnim() { //convenience
  113.                 uint customAnimID = 0;
  114.                 while (jjAnimSets[ANIM::CUSTOM[customAnimID]].firstAnim != 0) { //A loaded anim set will have a firstAnim value of 1 or higher.
  115.                         customAnimID += 1; //Keep searching...
  116.                         if (customAnimID == 256) {
  117.                                 jjDebug("No free animation sets found!");
  118.                                 return ANIM::SPAZ;
  119.                         }
  120.                 }
  121.                
  122.                 return ANIM::CUSTOM[customAnimID];
  123.         }
  124.        
  125.         bool _caching = false;
  126.         dictionary _savedBitmapsCache;
  127.         void EnableCaching(bool enable = true) {
  128.                 _caching = enable;
  129.         }
  130.        
  131.         array<uint8> __NearestColors(256);
  132.         void ProcessPalette() {
  133.                 array<uint8> brightnesses(256);
  134.                 for (uint i = 10; i <= 245; ++i) { //recreate JJ2's internal brightness values, which are what it uses for SPRITE::NEONGLOW
  135.                         const jjPALCOLOR color = jjPalette.color[i];
  136.                         brightnesses[i] = (7499 * color.blue + 38446 * color.green + 19591 * color.red) >> 16;
  137.                 }
  138.                
  139.                 for (int i = 0; i < 256; ++i) {
  140.                         int closestDistance = 1000;
  141.                         uint8 closestDistanceID = 0;
  142.                         for (int j = 10; j <= 245; ++j) {
  143.                                 if (j == 128) //don't use color 128, because that's used by swinging vines for transparency
  144.                                         continue;
  145.                                 const int distance = int(abs(i - brightnesses[j]));
  146.                                 if (distance < closestDistance) {
  147.                                         closestDistance = distance;
  148.                                         closestDistanceID = j;
  149.                                 }
  150.                         }
  151.                         __NearestColors[i] = closestDistanceID;
  152.                 }
  153.                
  154.                 if (_caching) {
  155.                         const auto keys = _savedBitmapsCache.getKeys();
  156.                         for (uint i = 0; i < keys.length; ++i)
  157.                                 cast<Bitmap>(_savedBitmapsCache[keys[i]]).saveDirectlyToFrames(parseUInt(keys[i].substr(1)), keys[i][0] == 'T'[0]);
  158.                 }
  159.         }
  160.  
  161.        
  162.         class Bitmap {
  163.                 private uint _width = 0, _height = 0;
  164.                 uint width {
  165.                         get const { return _width; }
  166.                 };
  167.                 uint height {
  168.                         get const { return _height; }
  169.                 };
  170.                 array<array<jjPALCOLOR>> pixels;
  171.                
  172.                 Bitmap() { pixels.resize(0); }
  173.                 private void resize(uint w, uint h) {
  174.                         _width = w;
  175.                         _height = h;
  176.                         pixels = array<array<jjPALCOLOR>>(width, array<jjPALCOLOR>(height));
  177.                 }
  178.                 Bitmap(uint w, uint h) {
  179.                         resize(w,h);
  180.                 }
  181.                 Bitmap(const string &in fileroot) {
  182.                         string filename = fileroot;
  183.                         if (!jjRegexMatch(filename.substr(filename.length - 4), "\\.bmp", true)) //case-insensitive match
  184.                                 filename += ".bmp";
  185.                         jjSTREAM file(filename);
  186.                         if (file.isEmpty()) {
  187.                                 jjDebug("File " + filename + " not found!");
  188.                                 return;
  189.                         }
  190.                         _loadFromStream(file);
  191.                 }
  192.                 Bitmap(jjSTREAM &in file) {
  193.                         if (file.isEmpty()) {
  194.                                 jjDebug("Cannot create a Bitmap from an empty stream.");
  195.                                 return;
  196.                         }
  197.                         _loadFromStream(file);
  198.                 }
  199.                 private void _loadFromStream(jjSTREAM &in file) {
  200.                         uint32 imageWidth, imageHeight;
  201.                         { //Bitmap file header
  202.                                 uint16 headerField; file.pop(headerField);
  203.                                 if (headerField != 0x4D42) {
  204.                                         jjDebug('Invalid file header (should be "BM")');
  205.                                         return;
  206.                                 }
  207.                                 uint32 fileSize; file.pop(fileSize);
  208.                                 if (fileSize != file.getSize() + 6) { //6 for bytes already read
  209.                                         jjDebug("Invalid internal filesize");
  210.                                         return;
  211.                                 }
  212.                                 file.discard(8);
  213.                         }
  214.                         { //DIB header
  215.                                 uint32 headerType; file.pop(headerType);
  216.                                 if (headerType != 40) { //"BITMAPINFOHEADER"
  217.                                         jjDebug("Unsupported BMP format");
  218.                                         return;
  219.                                 }
  220.                                 file.pop(imageWidth);
  221.                                 file.pop(imageHeight);
  222.                                 uint16 colorPlanes; file.pop(colorPlanes);
  223.                                 if (colorPlanes != 1) {
  224.                                         jjDebug("Invalid file");
  225.                                         return;
  226.                                 }
  227.                                 uint16 bitDepth; file.pop(bitDepth);
  228.                                 if (bitDepth != 24) {
  229.                                         jjDebug("Unsupported BMP format");
  230.                                         return;
  231.                                 }
  232.                                 uint32 compressionMethod; file.pop(compressionMethod);
  233.                                 if (compressionMethod != 0) {
  234.                                         jjDebug("Unsupported BMP format");
  235.                                         return;
  236.                                 }
  237.                                 uint32 imageSize; file.pop(imageSize);
  238.                                 if (imageSize != 0 && imageSize != imageWidth * imageHeight * 3) {
  239.                                         jjDebug("Unsupported file (width must be multiple of 4 pixels)");
  240.                                         return;
  241.                                 }
  242.                                 file.discard(8); //resolution weirdness
  243.                                 uint32 colorCount; file.pop(colorCount);
  244.                                 if (colorCount != 0) {
  245.                                         jjDebug("Unsupported BMP format");
  246.                                         return;
  247.                                 }
  248.                                 uint32 importantColorCount; file.pop(importantColorCount);
  249.                                 if (importantColorCount != 0) {
  250.                                         jjDebug("Unsupported BMP format");
  251.                                         return;
  252.                                 }
  253.                         }
  254.                         resize(imageWidth, imageHeight);
  255.                         for (int y = imageHeight - 1; y >= 0; --y)
  256.                                 for (uint x = 0; x < imageWidth; ++x) {
  257.                                         jjPALCOLOR color;
  258.                                         file.pop(color.blue); file.pop(color.green); file.pop(color.red);
  259.                                         pixels[x][y] = color;
  260.                                 }
  261.                 }
  262.                 Bitmap(const jjPIXELMAP &in pixelmap, const jjPAL &in palette = jjPalette) {
  263.                         resize(pixelmap.width, pixelmap.height);
  264.                         for (int x = _width - 1; x >= 0; --x)
  265.                                 for (int y = _height - 1; y >= 0; --y)
  266.                                         pixels[x][y] = palette.color[pixelmap[x,y]];
  267.                 }
  268.                 Bitmap(const Bitmap &in source, uint left, uint top, uint imageWidth, uint imageHeight) {
  269.                         if (left >= source.width)
  270.                                 return;
  271.                         if (top >= source.height)
  272.                                 return;
  273.                         if (left + imageWidth > source.width) imageWidth = source.width - left;
  274.                         if (top + imageHeight > source.height) imageHeight = source.height - top;
  275.                         resize(imageWidth, imageHeight);
  276.                         for (uint x = 0; x < imageWidth; ++x)
  277.                                 for (uint y = 0; y < imageHeight; ++y)
  278.                                         pixels[x][y] = source.pixels[left + x][top + y];
  279.                 }
  280.                
  281.                 void saveDirectlyToFrames(uint frameID, bool swingingVine = false) const {
  282.                         array<jjPIXELMAP@> maps(NumberOfFramesPerImage, null);
  283.                         for (uint c = 0; c < NumberOfFramesPerImage; ++c)
  284.                                 @maps[c] = @jjPIXELMAP(width, height);
  285.                         const jjPALCOLOR transparent(0, 0, 0);
  286.                         for (uint x = 0; x < width; ++x)
  287.                                 for (uint y = 0; y < height; ++y) {
  288.                                         const jjPALCOLOR src = pixels[x][y];
  289.                                         if (src != transparent) {
  290.                                                 maps[0][x,y] = __NearestColors[src.red];
  291.                                                 maps[1][x,y] = __NearestColors[src.green];
  292.                                                 maps[2][x,y] = __NearestColors[src.blue];
  293.                                         } else if (swingingVine)
  294.                                                 maps[0][x,y] = maps[1][x,y] = maps[2][x,y] = 128;
  295.                                 }
  296.                         for (uint subFrameID = 0; subFrameID < NumberOfFramesPerImage; ++subFrameID)
  297.                                 maps[subFrameID].save(jjAnimFrames[frameID + subFrameID]);
  298.                 }
  299.                 void saveToAnimFrames(uint frameID, const Coordinates@ coordinates = null) const {
  300.                         if (coordinates is null || coordinates.width == 0 || coordinates.height == 0)
  301.                                 @coordinates = @Coordinates(0, 0, width, height);
  302.                         Bitmap source(this, coordinates.left, coordinates.top, coordinates.width, coordinates.height);
  303.                         source.saveDirectlyToFrames(frameID, coordinates.swingingVine);
  304.                         if (_caching)
  305.                                 _savedBitmapsCache[(coordinates.swingingVine ? "T" : "F") + frameID] = source;
  306.                         for (uint subFrameID = 0; subFrameID < NumberOfFramesPerImage; ++subFrameID) {
  307.                                 jjANIMFRAME@ frame = jjAnimFrames[frameID + subFrameID];
  308.                                 frame.hotSpotX = coordinates.hotSpotX;
  309.                                 frame.hotSpotY = coordinates.hotSpotY;
  310.                                 frame.gunSpotX = coordinates.gunSpotX;
  311.                                 frame.gunSpotY = coordinates.gunSpotY;
  312.                                 frame.coldSpotX= coordinates.coldSpotX;
  313.                                 frame.coldSpotY= coordinates.coldSpotY;
  314.                         }
  315.                         jjAnimFrames[frameID].transparent = coordinates.transparent; //only need to set the first one
  316.                 }
  317.                
  318.                 void swizzle(COLOR::Component red, COLOR::Component green, COLOR::Component blue) {
  319.                         for (int x = _width - 1; x >= 0; --x)
  320.                                 for (int y = _height - 1; y >= 0; --y)
  321.                                         pixels[x][y].swizzle(red, green, blue);
  322.                 }
  323.         }
  324.        
  325.         class Coordinates {
  326.                 uint left = 0, right = 0, width = 0, top = 0, bottom = 0, height = 0;
  327.                 int hotSpotX = 0, hotSpotY = 0, gunSpotX = 0, gunSpotY = 0, coldSpotX = 0, coldSpotY = 0;
  328.                 bool transparent = false, swingingVine = false;
  329.                 Coordinates(){}
  330.                 Coordinates(uint l, uint t, uint w, uint h, int hX = 0, int hY = 0, int gX = 0, int gY = 0, int cX = 0, int cY = 0, bool tr = false, bool sv = false) {
  331.                         left = l; top = t;
  332.                         width = w; height = h;
  333.                         right = l+w; bottom = t+h;
  334.                         hotSpotX = hX; hotSpotY = hY;
  335.                         gunSpotX = gX; gunSpotY = gY;
  336.                         coldSpotX = cX; coldSpotY = cY;
  337.                         transparent = tr;
  338.                         swingingVine = sv;
  339.                 }
  340.         }
  341.        
  342.         void AllocateSpriteSheet(const ANIM::Set setID, const Bitmap& bitmap, const array<array<Coordinates>>& setCoordinates = array<array<Coordinates>>(1, array<Coordinates>(1))) {
  343.                 array<uint> animSizes(setCoordinates.length);
  344.                 for (uint i = 0; i < animSizes.length; ++i) {
  345.                         animSizes[i] = setCoordinates[i].length * NumberOfFramesPerImage;
  346.                 }
  347.                 jjAnimSets[setID].allocate(animSizes);
  348.                 for (uint animID = 0; animID < animSizes.length; ++animID) {
  349.                         const array<Coordinates>@ animCoordinates = @setCoordinates[animID];
  350.                         for (uint frameID = 0; frameID < animCoordinates.length; ++frameID)
  351.                                 bitmap.saveToAnimFrames(
  352.                                         jjAnimations[jjAnimSets[setID].firstAnim + animID].firstFrame + frameID * NumberOfFramesPerImage,
  353.                                         animCoordinates[frameID]
  354.                                 );
  355.                 }
  356.         }
  357.        
  358.         uint __getCurFrame(int setID, uint animation, uint frame) { //same code JJ2+ uses for converting to *FromCurFrame functions
  359.                 const jjANIMATION@ anim = jjAnimations[jjAnimSets[setID].firstAnim + animation];
  360.                 return anim.firstFrame + (frame % anim.frameCount);
  361.         }
  362.         void DrawSpriteFromCurFrame(float xPixel, float yPixel, uint sprite, int direction = 0, uint8 layerZ = 4, uint8 layerXY = 4, int8 playerID = -1) {
  363.                 if (!jjAnimFrames[sprite].transparent) {
  364.                         jjDrawSpriteFromCurFrame(xPixel, yPixel, sprite, direction, SPRITE::SINGLECOLOR, 0, layerZ, layerXY, playerID);
  365.                         jjDrawSpriteFromCurFrame(xPixel, yPixel, sprite, direction, SPRITE::NEONGLOW, 0, layerZ, layerXY, playerID);
  366.                         jjDrawSpriteFromCurFrame(xPixel, yPixel, sprite+1, direction, SPRITE::NEONGLOW, 1, layerZ, layerXY, playerID);
  367.                         jjDrawSpriteFromCurFrame(xPixel, yPixel, sprite+2, direction, SPRITE::NEONGLOW, 2, layerZ, layerXY, playerID);
  368.                 } else
  369.                         jjDrawSpriteFromCurFrame(xPixel, yPixel, sprite, direction, SPRITE::SHADOW, 0, layerZ, layerXY, playerID);
  370.                 jjDrawSpriteFromCurFrame(xPixel, yPixel, sprite, direction, SPRITE::NEONGLOW, 0, layerZ, layerXY, playerID);
  371.                 jjDrawSpriteFromCurFrame(xPixel, yPixel, sprite+1, direction, SPRITE::NEONGLOW, 1, layerZ, layerXY, playerID);
  372.                 jjDrawSpriteFromCurFrame(xPixel, yPixel, sprite+2, direction, SPRITE::NEONGLOW, 2, layerZ, layerXY, playerID);
  373.         }
  374.         void DrawSprite(float xPixel, float yPixel, int setID, uint8 animation, uint frame, int direction = 0, uint8 layerZ = 4, uint8 layerXY = 4, int8 playerID = -1) {
  375.                 DrawSpriteFromCurFrame(xPixel, yPixel, __getCurFrame(setID, animation, frame), direction, layerZ, layerXY, playerID);
  376.         }
  377.        
  378.         void DrawCanvasSpriteFromCurFrame(jjCANVAS@ canvas, int xPixel, int yPixel, uint sprite, int8 direction = 0) {
  379.                 if (!jjAnimFrames[sprite].transparent) {
  380.                         canvas.drawSpriteFromCurFrame(xPixel, yPixel, sprite, direction, SPRITE::SINGLECOLOR, 0);
  381.                         canvas.drawSpriteFromCurFrame(xPixel, yPixel, sprite, direction, SPRITE::NEONGLOW, 0);
  382.                         canvas.drawSpriteFromCurFrame(xPixel, yPixel, sprite+1, direction, SPRITE::NEONGLOW, 1);
  383.                         canvas.drawSpriteFromCurFrame(xPixel, yPixel, sprite+2, direction, SPRITE::NEONGLOW, 2);
  384.                 } else
  385.                         canvas.drawSpriteFromCurFrame(xPixel, yPixel, sprite, direction, SPRITE::SHADOW, 0);
  386.                 canvas.drawSpriteFromCurFrame(xPixel, yPixel, sprite, direction, SPRITE::NEONGLOW, 0);
  387.                 canvas.drawSpriteFromCurFrame(xPixel, yPixel, sprite+1, direction, SPRITE::NEONGLOW, 1);
  388.                 canvas.drawSpriteFromCurFrame(xPixel, yPixel, sprite+2, direction, SPRITE::NEONGLOW, 2);
  389.         }
  390.         void DrawCanvasSprite(jjCANVAS@ canvas, int xPixel, int yPixel, int setID, uint8 animation, uint frame, int8 direction = 0) {
  391.                 DrawCanvasSpriteFromCurFrame(canvas, xPixel, yPixel, __getCurFrame(setID, animation, frame), direction);
  392.         }
  393.        
  394.         void DrawResizedSpriteFromCurFrame(float xPixel, float yPixel, uint sprite, float xScale, float yScale, uint8 layerZ = 4, uint8 layerXY = 4, int8 playerID = -1) {
  395.                 if (!jjAnimFrames[sprite].transparent) {
  396.                         jjDrawResizedSpriteFromCurFrame(xPixel, yPixel, sprite, xScale, yScale, SPRITE::SINGLECOLOR, 0, layerZ, layerXY, playerID);
  397.                         jjDrawResizedSpriteFromCurFrame(xPixel, yPixel, sprite, xScale, yScale, SPRITE::NEONGLOW, 0, layerZ, layerXY, playerID);
  398.                         jjDrawResizedSpriteFromCurFrame(xPixel, yPixel, sprite+1, xScale, yScale, SPRITE::NEONGLOW, 1, layerZ, layerXY, playerID);
  399.                         jjDrawResizedSpriteFromCurFrame(xPixel, yPixel, sprite+2, xScale, yScale, SPRITE::NEONGLOW, 2, layerZ, layerXY, playerID);
  400.                 } else
  401.                         jjDrawResizedSpriteFromCurFrame(xPixel, yPixel, sprite, xScale, yScale, SPRITE::SHADOW, 0, layerZ, layerXY, playerID);
  402.                 jjDrawResizedSpriteFromCurFrame(xPixel, yPixel, sprite, xScale, yScale, SPRITE::NEONGLOW, 0, layerZ, layerXY, playerID);
  403.                 jjDrawResizedSpriteFromCurFrame(xPixel, yPixel, sprite+1, xScale, yScale, SPRITE::NEONGLOW, 1, layerZ, layerXY, playerID);
  404.                 jjDrawResizedSpriteFromCurFrame(xPixel, yPixel, sprite+2, xScale, yScale, SPRITE::NEONGLOW, 2, layerZ, layerXY, playerID);
  405.         }
  406.         void DrawResizedSprite(float xPixel, float yPixel, int setID, uint8 animation, uint frame, float xScale, float yScale, uint8 layerZ = 4, uint8 layerXY = 4, int8 playerID = -1) {
  407.                 DrawResizedSpriteFromCurFrame(xPixel, yPixel, __getCurFrame(setID, animation, frame), xScale, yScale, layerZ, layerXY, playerID);
  408.         }
  409.        
  410.         void DrawCanvasResizedSpriteFromCurFrame(jjCANVAS@ canvas, int xPixel, int yPixel, uint sprite, float xScale, float yScale) {
  411.                 if (!jjAnimFrames[sprite].transparent) {
  412.                         canvas.drawResizedSpriteFromCurFrame(xPixel, yPixel, sprite, xScale, yScale, SPRITE::SINGLECOLOR, 0);
  413.                         canvas.drawResizedSpriteFromCurFrame(xPixel, yPixel, sprite, xScale, yScale, SPRITE::NEONGLOW, 0);
  414.                         canvas.drawResizedSpriteFromCurFrame(xPixel, yPixel, sprite+1, xScale, yScale, SPRITE::NEONGLOW, 1);
  415.                         canvas.drawResizedSpriteFromCurFrame(xPixel, yPixel, sprite+2, xScale, yScale, SPRITE::NEONGLOW, 2);
  416.                 } else
  417.                         canvas.drawResizedSpriteFromCurFrame(xPixel, yPixel, sprite, xScale, yScale, SPRITE::SHADOW, 0);
  418.                 canvas.drawResizedSpriteFromCurFrame(xPixel, yPixel, sprite, xScale, yScale, SPRITE::NEONGLOW, 0);
  419.                 canvas.drawResizedSpriteFromCurFrame(xPixel, yPixel, sprite+1, xScale, yScale, SPRITE::NEONGLOW, 1);
  420.                 canvas.drawResizedSpriteFromCurFrame(xPixel, yPixel, sprite+2, xScale, yScale, SPRITE::NEONGLOW, 2);
  421.         }
  422.         void DrawCanvasResizedSprite(jjCANVAS@ canvas, int xPixel, int yPixel, int setID, uint8 animation, uint frame, float xScale, float yScale) {
  423.                 DrawCanvasResizedSpriteFromCurFrame(canvas, xPixel, yPixel, __getCurFrame(setID, animation, frame), xScale, yScale);
  424.         }
  425.        
  426.         void DrawRotatedSpriteFromCurFrame(float xPixel, float yPixel, uint sprite, int angle, float xScale = 1, float yScale = 1, uint8 layerZ = 4, uint8 layerXY = 4, int8 playerID = -1) {
  427.                 if (!jjAnimFrames[sprite].transparent) {
  428.                         jjDrawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite, angle, xScale, yScale, SPRITE::SINGLECOLOR, 0, layerZ, layerXY, playerID);
  429.                         jjDrawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite, angle, xScale, yScale, SPRITE::NEONGLOW, 0, layerZ, layerXY, playerID);
  430.                         jjDrawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite+1, angle, xScale, yScale, SPRITE::NEONGLOW, 1, layerZ, layerXY, playerID);
  431.                         jjDrawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite+2, angle, xScale, yScale, SPRITE::NEONGLOW, 2, layerZ, layerXY, playerID);
  432.                 } else
  433.                         jjDrawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite, angle, xScale, yScale, SPRITE::SHADOW, 0, layerZ, layerXY, playerID);
  434.                 jjDrawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite, angle, xScale, yScale, SPRITE::NEONGLOW, 0, layerZ, layerXY, playerID);
  435.                 jjDrawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite+1, angle, xScale, yScale, SPRITE::NEONGLOW, 1, layerZ, layerXY, playerID);
  436.                 jjDrawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite+2, angle, xScale, yScale, SPRITE::NEONGLOW, 2, layerZ, layerXY, playerID);
  437.         }
  438.         void DrawRotatedSprite(float xPixel, float yPixel, int setID, uint8 animation, uint frame, int angle, float xScale = 1, float yScale = 1, uint8 layerZ = 4, uint8 layerXY = 4, int8 playerID = -1) {
  439.                 DrawRotatedSpriteFromCurFrame(xPixel, yPixel, __getCurFrame(setID, animation, frame), angle, xScale, yScale, layerZ, layerXY, playerID);
  440.         }
  441.        
  442.         void DrawCanvasRotatedSpriteFromCurFrame(jjCANVAS@ canvas, int xPixel, int yPixel, uint sprite, int angle, float xScale = 1, float yScale = 1) {
  443.                 if (!jjAnimFrames[sprite].transparent) {
  444.                         canvas.drawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite, angle, xScale, yScale, SPRITE::SINGLECOLOR, 0);
  445.                         canvas.drawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite, angle, xScale, yScale, SPRITE::NEONGLOW, 0);
  446.                         canvas.drawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite+1, angle, xScale, yScale, SPRITE::NEONGLOW, 1);
  447.                         canvas.drawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite+2, angle, xScale, yScale, SPRITE::NEONGLOW, 2);
  448.                 } else
  449.                         canvas.drawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite, angle, xScale, yScale, SPRITE::SHADOW, 0);
  450.                 canvas.drawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite, angle, xScale, yScale, SPRITE::NEONGLOW, 0);
  451.                 canvas.drawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite+1, angle, xScale, yScale, SPRITE::NEONGLOW, 1);
  452.                 canvas.drawRotatedSpriteFromCurFrame(xPixel, yPixel, sprite+2, angle, xScale, yScale, SPRITE::NEONGLOW, 2);
  453.         }
  454.         void DrawCanvasRotatedSprite(jjCANVAS@ canvas, int xPixel, int yPixel, int setID, uint8 animation, uint frame, int angle, float xScale = 1, float yScale = 1) {
  455.                 DrawCanvasRotatedSpriteFromCurFrame(canvas, xPixel, yPixel, __getCurFrame(setID, animation, frame), angle, xScale, yScale);
  456.         }
  457.        
  458.         void DrawSwingingVineSpriteFromCurFrame(float xPixel, float yPixel, uint sprite, int length, int curvature, uint8 layerZ = 4, uint8 layerXY = 4, int8 playerID = -1) {
  459.                 if (!jjAnimFrames[sprite].transparent) {
  460.                         jjDrawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite, length, curvature, SPRITE::SINGLECOLOR, 0, layerZ, layerXY, playerID);
  461.                         jjDrawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite, length, curvature, SPRITE::NEONGLOW, 0, layerZ, layerXY, playerID);
  462.                         jjDrawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite+1, length, curvature, SPRITE::NEONGLOW, 1, layerZ, layerXY, playerID);
  463.                         jjDrawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite+2, length, curvature, SPRITE::NEONGLOW, 2, layerZ, layerXY, playerID);
  464.                 } else
  465.                         jjDrawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite, length, curvature, SPRITE::SHADOW, 0, layerZ, layerXY, playerID);
  466.                 jjDrawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite, length, curvature, SPRITE::NEONGLOW, 0, layerZ, layerXY, playerID);
  467.                 jjDrawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite+1, length, curvature, SPRITE::NEONGLOW, 1, layerZ, layerXY, playerID);
  468.                 jjDrawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite+2, length, curvature, SPRITE::NEONGLOW, 2, layerZ, layerXY, playerID);
  469.         }
  470.         void DrawSwingingVineSprite(float xPixel, float yPixel, int setID, uint8 animation, uint frame, int length, int curvature, uint8 layerZ = 4, uint8 layerXY = 4, int8 playerID = -1) {
  471.                 DrawSwingingVineSpriteFromCurFrame(xPixel, yPixel, __getCurFrame(setID, animation, frame), length, curvature, layerZ, layerXY, playerID);
  472.         }
  473.        
  474.         void DrawCanvasSwingingVineSpriteFromCurFrame(jjCANVAS@ canvas, int xPixel, int yPixel, uint sprite, int length, int curvature) {
  475.                 if (!jjAnimFrames[sprite].transparent) {
  476.                         canvas.drawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite, length, curvature, SPRITE::SINGLECOLOR, 0);
  477.                         canvas.drawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite, length, curvature, SPRITE::NEONGLOW, 0);
  478.                         canvas.drawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite+1, length, curvature, SPRITE::NEONGLOW, 1);
  479.                         canvas.drawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite+2, length, curvature, SPRITE::NEONGLOW, 2);
  480.                 } else
  481.                         canvas.drawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite, length, curvature, SPRITE::SHADOW, 0);
  482.                 canvas.drawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite, length, curvature, SPRITE::NEONGLOW, 0);
  483.                 canvas.drawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite+1, length, curvature, SPRITE::NEONGLOW, 1);
  484.                 canvas.drawSwingingVineSpriteFromCurFrame(xPixel, yPixel, sprite+2, length, curvature, SPRITE::NEONGLOW, 2);
  485.         }
  486.         void DrawCanvasSwingingVineSprite(jjCANVAS@ canvas, int xPixel, int yPixel, int setID, uint8 animation, uint frame, int length, int curvature) {
  487.                 DrawCanvasSwingingVineSpriteFromCurFrame(canvas, xPixel, yPixel, __getCurFrame(setID, animation, frame), length, curvature);
  488.         }
  489.        
  490.         void DrawObject(jjOBJ@ obj) {
  491.                 if (obj.freeze != 0 || obj.justHit != 0)
  492.                         obj.draw();
  493.                 else
  494.                         DrawSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, obj.direction);
  495.         }
  496. }