[
  {
    "path": ".github/FUNDING.yml",
    "content": "# These are supported funding model platforms\n\ngithub: @quinton-ashley\npatreon: p5play\nopen_collective: # Replace with a single Open Collective username\nko_fi: # Replace with a single Ko-fi username\ntidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel\ncommunity_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry\nliberapay: # Replace with a single Liberapay username\nissuehunt: # Replace with a single IssueHunt username\notechie: # Replace with a single Otechie username\nlfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry\ncustom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']\n"
  },
  {
    "path": "LICENSE.md",
    "content": "### GNU GENERAL PUBLIC LICENSE\n\nVersion 3, 29 June 2007\n\nCopyright (C) 2007 Free Software Foundation, Inc.\n<https://fsf.org/>\n\nEveryone is permitted to copy and distribute verbatim copies of this\nlicense document, but changing it is not allowed.\n\n### Preamble\n\nThe GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\nThe licenses for most software and other practical works are designed\nto take away your freedom to share and change the works. By contrast,\nthe GNU General Public License is intended to guarantee your freedom\nto share and change all versions of a program--to make sure it remains\nfree software for all its users. We, the Free Software Foundation, use\nthe GNU General Public License for most of our software; it applies\nalso to any other work released this way by its authors. You can apply\nit to your programs, too.\n\nWhen we speak of free software, we are referring to freedom, not\nprice. Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\nTo protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights. Therefore, you\nhave certain responsibilities if you distribute copies of the\nsoftware, or if you modify it: responsibilities to respect the freedom\nof others.\n\nFor example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received. You must make sure that they, too, receive\nor can get the source code. And you must show them these terms so they\nknow their rights.\n\nDevelopers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\nFor the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software. For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\nSome devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the\nmanufacturer can do so. This is fundamentally incompatible with the\naim of protecting users' freedom to change the software. The\nsystematic pattern of such abuse occurs in the area of products for\nindividuals to use, which is precisely where it is most unacceptable.\nTherefore, we have designed this version of the GPL to prohibit the\npractice for those products. If such problems arise substantially in\nother domains, we stand ready to extend this provision to those\ndomains in future versions of the GPL, as needed to protect the\nfreedom of users.\n\nFinally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish\nto avoid the special danger that patents applied to a free program\ncould make it effectively proprietary. To prevent this, the GPL\nassures that patents cannot be used to render the program non-free.\n\nThe precise terms and conditions for copying, distribution and\nmodification follow.\n\n### TERMS AND CONDITIONS\n\n#### 0. Definitions.\n\n\"This License\" refers to version 3 of the GNU General Public License.\n\n\"Copyright\" also means copyright-like laws that apply to other kinds\nof works, such as semiconductor masks.\n\n\"The Program\" refers to any copyrightable work licensed under this\nLicense. Each licensee is addressed as \"you\". \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\nTo \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of\nan exact copy. The resulting work is called a \"modified version\" of\nthe earlier work or a work \"based on\" the earlier work.\n\nA \"covered work\" means either the unmodified Program or a work based\non the Program.\n\nTo \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy. Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\nTo \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies. Mere interaction with a user\nthrough a computer network, with no transfer of a copy, is not\nconveying.\n\nAn interactive user interface displays \"Appropriate Legal Notices\" to\nthe extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License. If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n#### 1. Source Code.\n\nThe \"source code\" for a work means the preferred form of the work for\nmaking modifications to it. \"Object code\" means any non-source form of\na work.\n\nA \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\nThe \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form. A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\nThe \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities. However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work. For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\nThe Corresponding Source need not include anything that users can\nregenerate automatically from other parts of the Corresponding Source.\n\nThe Corresponding Source for a work in source code form is that same\nwork.\n\n#### 2. Basic Permissions.\n\nAll rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met. This License explicitly affirms your unlimited\npermission to run the unmodified Program. The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work. This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\nYou may make, run and propagate covered works that you do not convey,\nwithout conditions so long as your license otherwise remains in force.\nYou may convey covered works to others for the sole purpose of having\nthem make modifications exclusively for you, or provide you with\nfacilities for running those works, provided that you comply with the\nterms of this License in conveying all material for which you do not\ncontrol copyright. Those thus making or running the covered works for\nyou must do so exclusively on your behalf, under your direction and\ncontrol, on terms that prohibit them from making any copies of your\ncopyrighted material outside their relationship with you.\n\nConveying under any other circumstances is permitted solely under the\nconditions stated below. Sublicensing is not allowed; section 10 makes\nit unnecessary.\n\n#### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\nNo covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\nWhen you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such\ncircumvention is effected by exercising rights under this License with\nrespect to the covered work, and you disclaim any intention to limit\noperation or modification of the work as a means of enforcing, against\nthe work's users, your or third parties' legal rights to forbid\ncircumvention of technological measures.\n\n#### 4. Conveying Verbatim Copies.\n\nYou may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\nYou may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n#### 5. Conveying Modified Source Versions.\n\nYou may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these\nconditions:\n\n-   a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n-   b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under\n    section 7. This requirement modifies the requirement in section 4\n    to \"keep intact all notices\".\n-   c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy. This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged. This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n-   d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\nA compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit. Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n#### 6. Conveying Non-Source Forms.\n\nYou may convey a covered work in object code form under the terms of\nsections 4 and 5, provided that you also convey the machine-readable\nCorresponding Source under the terms of this License, in one of these\nways:\n\n-   a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n-   b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the Corresponding\n    Source from a network server at no charge.\n-   c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source. This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n-   d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge. You need not require recipients to copy the\n    Corresponding Source along with the object code. If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source. Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n-   e) Convey the object code using peer-to-peer transmission,\n    provided you inform other peers where the object code and\n    Corresponding Source of the work are being offered to the general\n    public at no charge under subsection 6d.\n\nA separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\nA \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal,\nfamily, or household purposes, or (2) anything designed or sold for\nincorporation into a dwelling. In determining whether a product is a\nconsumer product, doubtful cases shall be resolved in favor of\ncoverage. For a particular product received by a particular user,\n\"normally used\" refers to a typical or common use of that class of\nproduct, regardless of the status of the particular user or of the way\nin which the particular user actually uses, or expects or is expected\nto use, the product. A product is a consumer product regardless of\nwhether the product has substantial commercial, industrial or\nnon-consumer uses, unless such uses represent the only significant\nmode of use of the product.\n\n\"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to\ninstall and execute modified versions of a covered work in that User\nProduct from a modified version of its Corresponding Source. The\ninformation must suffice to ensure that the continued functioning of\nthe modified object code is in no case prevented or interfered with\nsolely because modification has been made.\n\nIf you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information. But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\nThe requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or\nupdates for a work that has been modified or installed by the\nrecipient, or for the User Product in which it has been modified or\ninstalled. Access to a network may be denied when the modification\nitself materially and adversely affects the operation of the network\nor violates the rules and protocols for communication across the\nnetwork.\n\nCorresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n#### 7. Additional Terms.\n\n\"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law. If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\nWhen you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit. (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.) You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\nNotwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders\nof that material) supplement the terms of this License with terms:\n\n-   a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n-   b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n-   c) Prohibiting misrepresentation of the origin of that material,\n    or requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n-   d) Limiting the use for publicity purposes of names of licensors\n    or authors of the material; or\n-   e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n-   f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions\n    of it) with contractual assumptions of liability to the recipient,\n    for any liability that these contractual assumptions directly\n    impose on those licensors and authors.\n\nAll other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10. If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term. If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\nIf you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\nAdditional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions; the\nabove requirements apply either way.\n\n#### 8. Termination.\n\nYou may not propagate or modify a covered work except as expressly\nprovided under this License. Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\nHowever, if you cease all violation of this License, then your license\nfrom a particular copyright holder is reinstated (a) provisionally,\nunless and until the copyright holder explicitly and finally\nterminates your license, and (b) permanently, if the copyright holder\nfails to notify you of the violation by some reasonable means prior to\n60 days after the cessation.\n\nMoreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\nTermination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License. If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n#### 9. Acceptance Not Required for Having Copies.\n\nYou are not required to accept this License in order to receive or run\na copy of the Program. Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance. However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work. These actions infringe copyright if you do\nnot accept this License. Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n#### 10. Automatic Licensing of Downstream Recipients.\n\nEach time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License. You are not responsible\nfor enforcing compliance by third parties with this License.\n\nAn \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations. If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\nYou may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License. For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n#### 11. Patents.\n\nA \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based. The\nwork thus licensed is called the contributor's \"contributor version\".\n\nA contributor's \"essential patent claims\" are all patent claims owned\nor controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version. For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\nEach contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\nIn the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement). To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\nIf you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients. \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\nIf, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\nA patent license is \"discriminatory\" if it does not include within the\nscope of its coverage, prohibits the exercise of, or is conditioned on\nthe non-exercise of one or more of the rights that are specifically\ngranted under this License. You may not convey a covered work if you\nare a party to an arrangement with a third party that is in the\nbusiness of distributing software, under which you make payment to the\nthird party based on the extent of your activity of conveying the\nwork, and under which the third party grants, to any of the parties\nwho would receive the covered work from you, a discriminatory patent\nlicense (a) in connection with copies of the covered work conveyed by\nyou (or copies made from those copies), or (b) primarily for and in\nconnection with specific products or compilations that contain the\ncovered work, unless you entered into that arrangement, or that patent\nlicense was granted, prior to 28 March 2007.\n\nNothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n#### 12. No Surrender of Others' Freedom.\n\nIf conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License. If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under\nthis License and any other pertinent obligations, then as a\nconsequence you may not convey it at all. For example, if you agree to\nterms that obligate you to collect a royalty for further conveying\nfrom those to whom you convey the Program, the only way you could\nsatisfy both those terms and this License would be to refrain entirely\nfrom conveying the Program.\n\n#### 13. Use with the GNU Affero General Public License.\n\nNotwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work. The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n#### 14. Revised Versions of this License.\n\nThe Free Software Foundation may publish revised and/or new versions\nof the GNU General Public License from time to time. Such new versions\nwill be similar in spirit to the present version, but may differ in\ndetail to address new problems or concerns.\n\nEach version is given a distinguishing version number. If the Program\nspecifies that a certain numbered version of the GNU General Public\nLicense \"or any later version\" applies to it, you have the option of\nfollowing the terms and conditions either of that numbered version or\nof any later version published by the Free Software Foundation. If the\nProgram does not specify a version number of the GNU General Public\nLicense, you may choose any version ever published by the Free\nSoftware Foundation.\n\nIf the Program specifies that a proxy can decide which future versions\nof the GNU General Public License can be used, that proxy's public\nstatement of acceptance of a version permanently authorizes you to\nchoose that version for the Program.\n\nLater license versions may give you additional or different\npermissions. However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n#### 15. Disclaimer of Warranty.\n\nTHERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT\nWARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND\nPERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE\nDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR\nCORRECTION.\n\n#### 16. Limitation of Liability.\n\nIN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR\nCONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES\nARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT\nNOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR\nLOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM\nTO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER\nPARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\n\n#### 17. Interpretation of Sections 15 and 16.\n\nIf the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\nEND OF TERMS AND CONDITIONS\n\n### How to Apply These Terms to Your New Programs\n\nIf you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these\nterms.\n\nTo do so, attach the following notices to the program. It is safest to\nattach them to the start of each source file to most effectively state\nthe exclusion of warranty; and each file should have at least the\n\"copyright\" line and a pointer to where the full notice is found.\n\n        <one line to give the program's name and a brief idea of what it does.>\n        Copyright (C) <year>  <name of author>\n\n        This program is free software: you can redistribute it and/or modify\n        it under the terms of the GNU General Public License as published by\n        the Free Software Foundation, either version 3 of the License, or\n        (at your option) any later version.\n\n        This program is distributed in the hope that it will be useful,\n        but WITHOUT ANY WARRANTY; without even the implied warranty of\n        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n        GNU General Public License for more details.\n\n        You should have received a copy of the GNU General Public License\n        along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper\nmail.\n\nIf the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n        <program>  Copyright (C) <year>  <name of author>\n        This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n        This is free software, and you are welcome to redistribute it\n        under certain conditions; type `show c' for details.\n\nThe hypothetical commands \\`show w' and \\`show c' should show the\nappropriate parts of the General Public License. Of course, your\nprogram's commands might be different; for a GUI interface, you would\nuse an \"about box\".\n\nYou should also get your employer (if you work as a programmer) or\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary. For more information on this, and how to apply and follow\nthe GNU GPL, see <https://www.gnu.org/licenses/>.\n\nThe GNU General Public License does not permit incorporating your\nprogram into proprietary programs. If your program is a subroutine\nlibrary, you may consider it more useful to permit linking proprietary\napplications with the library. If this is what you want to do, use the\nGNU Lesser General Public License instead of this License. But first,\nplease read <https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "# <img src=\"https://p5play.org/logo.svg\" width=\"64\"> p5.play ![](https://img.shields.io/github/package-json/v/quinton-ashley/p5.play) ![](https://img.shields.io/github/license/quinton-ashley/p5.play)\n\n[p5.play][] is a 2D game engine made by Computer Science teachers to help you turn your game ideas into JavaScript code!\n\n### Learn how to use p5.play at https://p5play.org\n\n### Join the [p5.play community Discord server][] to ask questions and meet other people making games with p5.play!\n\np5.play is currently led by Quinton Ashley [@quinton-ashley][] and was initiated by Paolo Pedercini [@molleindustria][]. If you have any questions or problems use the help channels on [discord][] or make an [issue report][] on this GitHub repository or email <info@p5play.org>\n\n## Support p5.play\n\nIt took thousands of hours for [@quinton-ashley][] to upgrade this open source project and he continues to maintain it! p5.play will always be available for free, but your support would be greatly appreciated. If you use p5.play professionally in your lessons or commercial games, please consider donating!\n\n[![Donate](https://img.shields.io/badge/PayPal-@qashto-green.svg)](https://paypal.me/qashto) [![Venmo](https://img.shields.io/badge/Venmo-@Quinton--Ashley-blue.svg)](https://venmo.com/Quinton-Ashley) [![Patreon](https://img.shields.io/badge/Patreon-@p5play-orange.svg)](https://www.patreon.com/p5play)\n\n## Development of p5.play\n\nTake a look at the [p5play-web][] GitHub repository for information about how to contribute to the development of p5.play.\n\n[p5.play]: https://p5play.org\n[issue report]: https://github.com/quinton-ashley/p5.play/issues\n[@quinton-ashley]: https://github.com/quinton-ashley\n[@molleindustria]: https://github.com/molleindustria\n[p5play-web]: https://github.com/quinton-ashley/p5play-web\n[p5.play community discord server]: https://discord.gg/3UTbqUgmPF\n[discord]: https://discord.gg/3UTbqUgmPF\n"
  },
  {
    "path": "p5.play.js",
    "content": "/**\n * p5.play\n *\n * @version 3.5\n * @author quinton-ashley\n * @year 2023\n * @license gpl-v3-only\n * @descripton p5.play is a 2D game engine that uses planck (Box2D) to simulate\n * physics and provides sprites, a tile system, input handling, and animations!\n */\np5.prototype.registerMethod('init', function p5PlayInit() {\n\tif (typeof window.planck == 'undefined') {\n\t\tthrow new Error('planck.js must be loaded before p5.play');\n\t}\n\n\t// store a reference to the p5 instance that p5play is being added to\n\tlet pInst = this;\n\n\tconst log = console.log; // shortcut\n\tthis.log = console.log;\n\n\tconst pl = planck;\n\t// set the velocity threshold to allow for slow moving objects\n\tpl.Settings.velocityThreshold = 0.19;\n\tlet plScale = 60;\n\n\tthis.p5play = this.p5play || {};\n\tthis.p5play.os ??= {\n\t\temulated: false\n\t};\n\tthis.p5play.autoDrawSprites ??= true;\n\tthis.p5play.autoUpdateSprites ??= true;\n\tthis.p5play.mouseTracking ??= true;\n\tthis.p5play.mouseSprite = null;\n\tthis.p5play.mouseSprites = [];\n\tthis.p5play.standardizeKeyboard = false;\n\n\t// change the angle mode to degrees\n\tthis.angleMode(p5.prototype.DEGREES);\n\n\t// scale to planck coordinates from p5 coordinates\n\tconst scaleTo = ({ x, y }, tileSize) => new pl.Vec2((x * tileSize) / plScale, (y * tileSize) / plScale);\n\tconst scaleXTo = (x, tileSize) => (x * tileSize) / plScale;\n\n\t// scale from planck coordinates to p5 coordinates\n\tconst scaleFrom = ({ x, y }, tileSize) => new pl.Vec2((x / tileSize) * plScale, (y / tileSize) * plScale);\n\tconst scaleXFrom = (x, tileSize) => (x / tileSize) * plScale;\n\n\tconst fixRound = (val) => (Math.abs(val - Math.round(val)) <= pl.Settings.linearSlop ? Math.round(val) : val);\n\tconst isArrowFunction = (fn) =>\n\t\t!/^(?:(?:\\/\\*[^(?:\\*\\/)]*\\*\\/\\s*)|(?:\\/\\/[^\\r\\n]*))*\\s*(?:(?:(?:async\\s(?:(?:\\/\\*[^(?:\\*\\/)]*\\*\\/\\s*)|(?:\\/\\/[^\\r\\n]*))*\\s*)?function|class)(?:\\s|(?:(?:\\/\\*[^(?:\\*\\/)]*\\*\\/\\s*)|(?:\\/\\/[^\\r\\n]*))*)|(?:[_$\\w][\\w0-9_$]*\\s*(?:\\/\\*[^(?:\\*\\/)]*\\*\\/\\s*)*\\s*\\()|(?:\\[\\s*(?:\\/\\*[^(?:\\*\\/)]*\\*\\/\\s*)*\\s*(?:(?:['][^']+['])|(?:[\"][^\"]+[\"]))\\s*(?:\\/\\*[^(?:\\*\\/)]*\\*\\/\\s*)*\\s*\\]\\())/.test(\n\t\t\tfn.toString()\n\t\t);\n\n\t/**\n\t * Checks if the given string contains a valid collider type\n\t * or collider type code letter:\n\t *\n\t * 'd' or 'dynamic'\n\t * 's' or 'static'\n\t * 'k' or 'kinematic'\n\t * 'n' or 'none'\n\t *\n\t * @param {String} t type name\n\t * @returns {Boolean} true if the given string contains a valid collider type\n\t */\n\tfunction isColliderType(t) {\n\t\tlet abr = t.slice(0, 2);\n\t\treturn t == 'd' || t == 's' || t == 'k' || t == 'n' || abr == 'dy' || abr == 'st' || abr == 'ki' || abr == 'no';\n\t}\n\n\t/**\n\t * Returns an array with the line length, angle, and number of sides of a regular polygon\n\t *\n\t * @param {String} n name of the regular polygon\n\t * @param {Number} l side length\n\t * @returns {Boolean} an array [line, angle, sides]\n\t */\n\tfunction getRegularPolygon(n, l) {\n\t\tif (n == 'triangle') l = [l, -120, 3];\n\t\telse if (n == 'square') l = [l, -90, 4];\n\t\telse if (n == 'pentagon') l = [l, -72, 5];\n\t\telse if (n == 'hexagon') l = [l, -60, 6];\n\t\telse if (n == 'septagon') l = [l, -51.4285714286, 7];\n\t\telse if (n == 'octagon') l = [l, -45, 8];\n\t\telse if (n == 'enneagon') l = [l, -40, 9];\n\t\telse if (n == 'decagon') l = [l, -36, 10];\n\t\telse if (n == 'hendecagon') l = [l, -32.7272727273, 11];\n\t\telse if (n == 'dodecagon') l = [l, -30, 12];\n\t\treturn l;\n\t}\n\n\tlet spriteProps = [\n\t\t'bounciness',\n\t\t'collider',\n\t\t'color',\n\t\t'density',\n\t\t'd',\n\t\t'debug',\n\t\t'diameter',\n\t\t'direction',\n\t\t// 'directionLock',\n\t\t'drag',\n\t\t'dynamic',\n\t\t'friction',\n\t\t'fill',\n\t\t'h',\n\t\t'height',\n\t\t'heading',\n\t\t'isSuperFast',\n\t\t'kinematic',\n\t\t'layer',\n\t\t'life',\n\t\t'mass',\n\t\t'rotation',\n\t\t'rotationDrag',\n\t\t'rotationLock',\n\t\t'rotationSpeed',\n\t\t'scale',\n\t\t'shape',\n\t\t'speed',\n\t\t'static',\n\t\t'stroke',\n\t\t'strokeWeight',\n\t\t'text',\n\t\t'textColor',\n\t\t'tileSize',\n\t\t'visible',\n\t\t'w',\n\t\t'width',\n\t\t'x',\n\t\t'y'\n\t];\n\n\tlet eventTypes = {\n\t\t_collisions: ['_collides', '_colliding', '_collided'],\n\t\t_overlappers: ['_overlaps', '_overlapping', '_overlapped']\n\t};\n\n\tp5.Vector.prototype._angleBetween = p5.Vector.prototype.angleBetween;\n\tp5.Vector.prototype.angleBetween = function (v) {\n\t\tlet a = this._angleBetween(v);\n\t\tif (!isNaN(a)) return a;\n\t\treturn 0;\n\t};\n\n\t/**\n\t * Look at the Sprite reference pages before reading these docs.\n\t *\n\t * https://p5play.org/learn/sprite.html\n\t *\n\t * Every sprite you create is added to the allSprites\n\t * group and put on the top layer, in front of all other\n\t * previously created sprites.\n\t *\n\t * @example\n\t *\n\t *   let rectangle = new Sprite(x, y, width, height);\n\t *\n\t *   let circle = new Sprite(x, y, diameter);\n\t *\n\t *   let line = new Sprite(x, y, [length, angle]);\n\t *\n\t * @class Sprite\n\t * @constructor\n\t * @param {String|SpriteAnimation|p5.Image} [aniName|ani|image]\n\t * @param {Number} x Horizontal position of the sprite\n\t * @param {Number} y Vertical position of the sprite\n\t * @param {Number} [width|diameter] Width of the placeholder rectangle and of\n\t * the collider until an image or new collider are set. *OR* If height is not\n\t * set then this parameter becomes the diameter of the placeholder circle.\n\t * @param {Number} [height] Height of the placeholder rectangle and of the collider\n\t * until an image or new collider are set\n\t * @param {String} [physics] collider type is 'dynamic' by default, can be\n\t * 'static', 'kinematic', or 'none'\n\t */\n\tclass Sprite {\n\t\tconstructor(x, y, w, h, collider) {\n\t\t\tthis.p = pInst;\n\t\t\tthis.idNum = this.p.world.spritesCreated;\n\t\t\tthis.p.world.spritesCreated++;\n\n\t\t\tlet args = [...arguments];\n\n\t\t\tlet group, ani;\n\n\t\t\tif (args[0] !== undefined && args[0] instanceof Group) {\n\t\t\t\tgroup = args[0];\n\t\t\t\targs = args.slice(1);\n\t\t\t}\n\n\t\t\tif (!args.length) this._noArgs = true;\n\n\t\t\tif (\n\t\t\t\targs[0] !== undefined &&\n\t\t\t\tisNaN(args[0]) &&\n\t\t\t\t(typeof args[0] == 'string' || args[0] instanceof SpriteAnimation || args[0] instanceof p5.Image)\n\t\t\t) {\n\t\t\t\t// shift\n\t\t\t\tani = args[0];\n\t\t\t\targs = args.slice(1);\n\t\t\t}\n\n\t\t\tif (args.length == 1 && typeof args[0] == 'number') {\n\t\t\t\tthrow new FriendlyError('Sprite', 0, [args[0]]);\n\t\t\t}\n\n\t\t\tx = args[0];\n\t\t\ty = args[1];\n\t\t\tw = args[2];\n\t\t\th = args[3];\n\t\t\tcollider = args[4];\n\t\t\tthis.originMode = 'center';\n\n\t\t\tif (Array.isArray(x)) {\n\t\t\t\tx = undefined;\n\t\t\t\ty = undefined;\n\t\t\t\tw = args[0];\n\t\t\t\th = args[1];\n\t\t\t\tcollider = args[2];\n\t\t\t}\n\n\t\t\t// if (w is chain array) or (diameter/side length and h is a\n\t\t\t// collider type or the name of a regular polygon)\n\t\t\tif (Array.isArray(w) || typeof h == 'string') {\n\t\t\t\tif (!isNaN(w)) w = Number(w);\n\t\t\t\tif (typeof w != 'number' && Array.isArray(w[0])) {\n\t\t\t\t\tthis.originMode = 'start';\n\t\t\t\t}\n\t\t\t\tif (h !== undefined) {\n\t\t\t\t\tif (Array.isArray(h)) {\n\t\t\t\t\t\tthrow new FriendlyError('Sprite', 1, [`[[${w}], [${h}]]`]);\n\t\t\t\t\t}\n\t\t\t\t\tif (isColliderType(h)) {\n\t\t\t\t\t\tcollider = h;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tw = getRegularPolygon(h, w);\n\t\t\t\t\t}\n\t\t\t\t\th = undefined;\n\t\t\t\t}\n\t\t\t} else if (isNaN(w)) {\n\t\t\t\tcollider = w;\n\t\t\t\tw = undefined;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Groups the sprite belongs to, including allSprites\n\t\t\t *\n\t\t\t * @property groups\n\t\t\t * @type {Array}\n\t\t\t * @default [allSprites]\n\t\t\t */\n\t\t\tthis.groups = [];\n\t\t\tthis.p.allSprites.push(this);\n\n\t\t\t/**\n\t\t\t * Keys are the animation label, values are SpriteAnimation objects.\n\t\t\t *\n\t\t\t * @property animations\n\t\t\t * @type {Object}\n\t\t\t */\n\t\t\tthis.animations = {};\n\n\t\t\t/**\n\t\t\t * If false, animations that are stopped before they are completed,\n\t\t\t * typically by a call to sprite.changeAni, will start at the frame\n\t\t\t * they were stopped at. If true, animations will always start playing from\n\t\t\t * frame 0 unless specified by the user in a separate anim.changeFrame\n\t\t\t * call.\n\t\t\t *\n\t\t\t * @property autoResetAnimations\n\t\t\t * @type {SpriteAnimation}\n\t\t\t * @default false\n\t\t\t */\n\t\t\tthis.autoResetAnimations;\n\n\t\t\t/**\n\t\t\t * True if the sprite was removed from the world\n\t\t\t *\n\t\t\t * @property removed\n\t\t\t * @type {Boolean}\n\t\t\t * @default false\n\t\t\t */\n\t\t\tthis.removed = false;\n\n\t\t\tif (group) {\n\t\t\t\tgroup.push(this);\n\t\t\t\tif (!ani) {\n\t\t\t\t\tfor (let _ani in group.animations) {\n\t\t\t\t\t\tani = _ani;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tgroup = this.p.allSprites;\n\t\t\t}\n\n\t\t\tif (group.dynamic) collider ??= 'dynamic';\n\t\t\tif (group.kinematic) collider ??= 'kinematic';\n\t\t\tif (group.static) collider ??= 'static';\n\t\t\tcollider ??= group.collider;\n\n\t\t\tthis._shape = group.shape;\n\n\t\t\t/**\n\t\t\t * Cycles before self removal.\n\t\t\t * Set it to initiate a countdown, every draw cycle the property is\n\t\t\t * reduced by 1 unit. If less than or equal to 0, this sprite will be removed.\n\t\t\t *\n\t\t\t * @property life\n\t\t\t * @type {Number}\n\t\t\t * @default 100000000\n\t\t\t */\n\t\t\tthis.life = 100000000;\n\n\t\t\t/**\n\t\t\t * The sprite's visibility.\n\t\t\t *\n\t\t\t * @property visible\n\t\t\t * @type {Boolean}\n\t\t\t * @default true\n\t\t\t */\n\t\t\tthis.visible = true;\n\n\t\t\t/**\n\t\t\t * Contains all the collision callback functions for this sprite\n\t\t\t * when it comes in contact with other sprites or groups.\n\t\t\t */\n\t\t\tthis._collides = {};\n\t\t\tthis._colliding = {};\n\t\t\tthis._collided = {};\n\n\t\t\tthis._overlap = {};\n\t\t\t/**\n\t\t\t * Contains all the overlap callback functions for this sprite\n\t\t\t * when it comes in contact with other sprites or groups.\n\t\t\t */\n\t\t\tthis._overlaps = {};\n\t\t\tthis._overlapping = {};\n\t\t\tthis._overlapped = {};\n\n\t\t\tthis._collisions = new Map();\n\t\t\tthis._overlappers = new Map();\n\n\t\t\tthis.tileSize = group.tileSize || 1;\n\n\t\t\tlet _this = this;\n\n\t\t\t// this.x and this.y are getters and setters that change this._pos internally\n\t\t\t// this.pos and this.position get this._position\n\t\t\tthis._pos = {\n\t\t\t\tx: 0,\n\t\t\t\ty: 0\n\t\t\t};\n\n\t\t\tthis._position = {\n\t\t\t\tget x() {\n\t\t\t\t\treturn _this.x;\n\t\t\t\t},\n\t\t\t\tset x(val) {\n\t\t\t\t\t_this.x = val;\n\t\t\t\t},\n\t\t\t\tget y() {\n\t\t\t\t\treturn _this.y;\n\t\t\t\t},\n\t\t\t\tset y(val) {\n\t\t\t\t\t_this.y = val;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// this._vel is used if the Sprite has no physics body\n\t\t\tthis._vel = {\n\t\t\t\tx: 0,\n\t\t\t\ty: 0\n\t\t\t};\n\n\t\t\t// this._velocity extends p5.Vector\n\t\t\tthis._velocity = pInst.createVector.call(pInst);\n\n\t\t\tObject.defineProperty(this._velocity, 'x', {\n\t\t\t\tget() {\n\t\t\t\t\tlet val;\n\t\t\t\t\tif (!_this.body) val = _this._vel.x;\n\t\t\t\t\telse val = _this.body.getLinearVelocity().x;\n\t\t\t\t\treturn fixRound(val / _this.tileSize);\n\t\t\t\t},\n\t\t\t\tset(val) {\n\t\t\t\t\tval *= _this.tileSize;\n\t\t\t\t\tif (_this.body) {\n\t\t\t\t\t\t_this.body.setLinearVelocity(new pl.Vec2(val, _this.body.getLinearVelocity().y));\n\t\t\t\t\t} else {\n\t\t\t\t\t\t_this._vel.x = val;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tObject.defineProperty(this._velocity, 'y', {\n\t\t\t\tget() {\n\t\t\t\t\tlet val;\n\t\t\t\t\tif (!_this.body) val = _this._vel.y;\n\t\t\t\t\telse val = _this.body.getLinearVelocity().y;\n\t\t\t\t\treturn fixRound(val / _this.tileSize);\n\t\t\t\t},\n\t\t\t\tset(val) {\n\t\t\t\t\tval *= _this.tileSize;\n\t\t\t\t\tif (_this.body) {\n\t\t\t\t\t\t_this.body.setLinearVelocity(new pl.Vec2(_this.body.getLinearVelocity().x, val));\n\t\t\t\t\t} else {\n\t\t\t\t\t\t_this._vel.y = val;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis._mirror = {\n\t\t\t\tx: 1,\n\t\t\t\ty: 1\n\t\t\t};\n\n\t\t\tthis.mirror = {\n\t\t\t\tget x() {\n\t\t\t\t\treturn _this._mirror.x < 0;\n\t\t\t\t},\n\t\t\t\tset x(val) {\n\t\t\t\t\t_this._mirror.x = val ? -1 : 1;\n\t\t\t\t},\n\t\t\t\tget y() {\n\t\t\t\t\treturn _this._mirror.y < 0;\n\t\t\t\t},\n\t\t\t\tset y(val) {\n\t\t\t\t\t_this._mirror.y = val ? -1 : 1;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tthis.layer = group.layer;\n\t\t\tthis.layer ??= this.p.allSprites.maxDepth() + 1;\n\t\t\tcollider ??= group.collider;\n\n\t\t\tif (!collider || typeof collider != 'string') {\n\t\t\t\tcollider = 'dynamic';\n\t\t\t}\n\t\t\tthis.collider = collider;\n\n\t\t\tx ??= group.x;\n\t\t\tif (x === undefined) {\n\t\t\t\tx = this.p.width / this.p.allSprites.tileSize / 2;\n\t\t\t\tthis._vertexMode = true;\n\t\t\t}\n\t\t\ty ??= group.y;\n\t\t\tif (y === undefined) y = this.p.height / this.p.allSprites.tileSize / 2;\n\t\t\tw ??= group.w || group.width || group.diameter;\n\t\t\th ??= group.h || group.height;\n\n\t\t\tif (typeof x == 'function') x = x(group.length - 1);\n\t\t\tif (typeof y == 'function') y = y(group.length - 1);\n\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\n\t\t\tif (ani) {\n\t\t\t\tif (ani instanceof p5.Image) {\n\t\t\t\t\tthis.addAni(ani);\n\t\t\t\t} else {\n\t\t\t\t\tif (typeof ani == 'string') this._changeAni(ani);\n\t\t\t\t\telse this._animation = ani.clone();\n\t\t\t\t}\n\t\t\t\tlet ts = this.tileSize;\n\t\t\t\tif (!w && (this.ani.w != 1 || this.ani.h != 1)) {\n\t\t\t\t\tw = this.ani.w / ts;\n\t\t\t\t\tif (this.shape != 'circle') {\n\t\t\t\t\t\th = this.ani.h / ts;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.mouse = new SpriteMouse();\n\n\t\t\tif (this.collider != 'none') {\n\t\t\t\tif (this._vertexMode) this.addCollider(w, h);\n\t\t\t\telse this.addCollider(0, 0, w, h);\n\t\t\t} else {\n\t\t\t\tthis.w = w || (this.tileSize > 1 ? 1 : 50);\n\t\t\t\tthis.h = h || this.w;\n\t\t\t\tif (w !== undefined && h === undefined) this._shape = 'circle';\n\t\t\t\telse this._shape = 'box';\n\t\t\t}\n\n\t\t\tthis._scale = new Scale();\n\n\t\t\tObject.defineProperty(this._scale, 'x', {\n\t\t\t\tget() {\n\t\t\t\t\treturn this._x;\n\t\t\t\t},\n\t\t\t\tset(val) {\n\t\t\t\t\tif (val == this._x) return;\n\t\t\t\t\tlet scalarX = val / this._x;\n\t\t\t\t\t_this._w *= scalarX;\n\t\t\t\t\t_this._hw *= scalarX;\n\t\t\t\t\t_this._resizeCollider({ x: scalarX, y: 1 });\n\t\t\t\t\tthis._x = val;\n\t\t\t\t\tthis._avg = (this._x + this._y) * 0.5;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tObject.defineProperty(this._scale, 'y', {\n\t\t\t\tget() {\n\t\t\t\t\treturn this._y;\n\t\t\t\t},\n\t\t\t\tset(val) {\n\t\t\t\t\tif (val == this._y) return;\n\t\t\t\t\tlet scalarY = val / this._y;\n\t\t\t\t\tif (_this._h) {\n\t\t\t\t\t\tthis._h *= scalarY;\n\t\t\t\t\t\tthis._hh *= scalarY;\n\t\t\t\t\t}\n\t\t\t\t\t_this._resizeCollider({ x: 1, y: scalarY });\n\t\t\t\t\tthis._y = val;\n\t\t\t\t\tthis._avg = (this._x + this._y) * 0.5;\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t/**\n\t\t\t * The sprite's position on the previous frame.\n\t\t\t *\n\t\t\t * @property prevPos\n\t\t\t * @type {object}\n\t\t\t */\n\t\t\tthis.prevPos = { x, y };\n\n\t\t\tthis._dest = { x, y };\n\t\t\tthis._destIdx = 0;\n\t\t\tthis.drag = 0;\n\n\t\t\t/**\n\t\t\t * When the sprite.debug property is set to true you can see the\n\t\t\t * sprite's physics body collider.\n\t\t\t *\n\t\t\t * @property debug\n\t\t\t * @type {boolean}\n\t\t\t * @default false\n\t\t\t */\n\t\t\tthis.debug = false;\n\n\t\t\tthis._shift = {};\n\n\t\t\tlet gvx = group.vel.x || 0;\n\t\t\tlet gvy = group.vel.y || 0;\n\t\t\tif (typeof gvx == 'function') gvx = gvx(group.length - 1);\n\t\t\tif (typeof gvy == 'function') gvy = gvy(group.length - 1);\n\t\t\tthis.vel.x = gvx;\n\t\t\tthis.vel.y = gvy;\n\n\t\t\tfor (let prop of spriteProps) {\n\t\t\t\tif (prop == 'collider' || prop == 'x' || prop == 'y') continue;\n\t\t\t\tlet val = group[prop];\n\t\t\t\tif (val === undefined) continue;\n\t\t\t\tif (typeof val == 'function') val = val(group.length - 1);\n\t\t\t\tif (typeof val == 'object') {\n\t\t\t\t\tthis[prop] = Object.assign({}, val);\n\t\t\t\t} else {\n\t\t\t\t\tthis[prop] = val;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// custom group properties \"sprite group traits\"\n\t\t\t// that are non-default sprite properties\n\t\t\tfor (let g of this.groups) {\n\t\t\t\tlet traits = {};\n\t\t\t\tlet props = Object.keys(g);\n\t\t\t\tfor (let prop of props) {\n\t\t\t\t\tif (!isNaN(prop) || prop[0] == '_') continue;\n\t\t\t\t\ttraits[prop] = null;\n\t\t\t\t}\n\n\t\t\t\t// delete these traits\n\t\t\t\tlet deletes = [\n\t\t\t\t\t'collider',\n\t\t\t\t\t'idNum',\n\t\t\t\t\t'p',\n\t\t\t\t\t'parent',\n\t\t\t\t\t'length',\n\t\t\t\t\t'_collides',\n\t\t\t\t\t'_colliding',\n\t\t\t\t\t'_collided',\n\t\t\t\t\t'_collisions',\n\t\t\t\t\t'_overlap',\n\t\t\t\t\t'_overlaps',\n\t\t\t\t\t'_overlapping',\n\t\t\t\t\t'_overlapped',\n\t\t\t\t\t'_overlappers',\n\t\t\t\t\t'animation',\n\t\t\t\t\t'animations',\n\t\t\t\t\t'autoCull',\n\t\t\t\t\t'Sprite',\n\t\t\t\t\t'GroupSprite',\n\t\t\t\t\t'Group',\n\t\t\t\t\t'SubGroup',\n\t\t\t\t\t'vel',\n\t\t\t\t\t'mirror',\n\t\t\t\t\t'mouse'\n\t\t\t\t];\n\t\t\t\tfor (let d of deletes) {\n\t\t\t\t\tdelete traits[d];\n\t\t\t\t}\n\n\t\t\t\tfor (let prop in traits) {\n\t\t\t\t\tlet val = g[prop];\n\t\t\t\t\tif (val === undefined) continue;\n\t\t\t\t\tif (typeof val == 'function') {\n\t\t\t\t\t\tif (isArrowFunction(val)) val = val();\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof val == 'object') {\n\t\t\t\t\t\tthis[prop] = Object.assign({}, val);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis[prop] = val;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * @property strokeWeight\n\t\t\t * @type {Number}\n\t\t\t * @default undefined\n\t\t\t */\n\t\t\tthis.strokeWeight;\n\n\t\t\tthis.color ??= this.p.color(this.p.random(30, 245), this.p.random(30, 245), this.p.random(30, 245));\n\n\t\t\tthis.textColor ??= this.p.color(0);\n\t\t\tthis.textSize ??= this.tileSize == 1 ? (this.p.canvas ? this.p.textSize() : 12) : 0.8;\n\n\t\t\tlet shouldCreateSensor = false;\n\t\t\tfor (let g of this.groups) {\n\t\t\t\tif (g._hasOverlaps) {\n\t\t\t\t\tshouldCreateSensor = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (shouldCreateSensor && !this._hasOverlaps) this._createSensors();\n\n\t\t\tthis._dimensionsUndefined = w === undefined && h === undefined;\n\t\t}\n\n\t\t/**\n\t\t * EXPERIMENTAL method! Subject to change!\n\t\t *\n\t\t * Adds a collider (fixture) to the sprite's physics body.\n\t\t *\n\t\t * It accepts parameters in a similar format to the Sprite\n\t\t * constructor except the first two parameters are x and y offsets,\n\t\t * the distance new collider should be from the center of the sprite.\n\t\t *\n\t\t * One limitation of the current implementation is that the collider\n\t\t * type can't be changed without losing every collider added to the\n\t\t * sprite besides the first. This will be fixed in a future release.\n\t\t *\n\t\t * @method addCollider\n\t\t * @param {Number} offsetX distance from the center of the sprite\n\t\t * @param {Number} offsetY distance from the center of the sprite\n\t\t * @param {Number} w width of the collider\n\t\t * @param {Number} h height of the collider\n\t\t */\n\t\taddCollider(offsetX, offsetY, w, h) {\n\t\t\tlet args = [...arguments];\n\t\t\tlet path, shape;\n\n\t\t\tif (args.length < 3) {\n\t\t\t\toffsetX = 0;\n\t\t\t\toffsetY = 0;\n\t\t\t\tw = args[0];\n\t\t\t\th = args[1];\n\t\t\t\tthis._vertexMode = true;\n\t\t\t}\n\n\t\t\toffsetX ??= 0;\n\t\t\toffsetY ??= 0;\n\t\t\tw ??= this._w;\n\t\t\tif (!this.body && this.shape && this.shape != 'circle') {\n\t\t\t\th ??= this._h;\n\t\t\t}\n\n\t\t\t// if (w is chain array) or (diameter/side length and h is a\n\t\t\t// collider type or the name of a regular polygon)\n\t\t\tif (Array.isArray(w) || typeof h == 'string') {\n\t\t\t\tif (!isNaN(w)) w = Number(w);\n\t\t\t\tif (typeof w != 'number' && Array.isArray(w[0])) {\n\t\t\t\t\tthis.originMode = 'start';\n\t\t\t\t}\n\t\t\t\tif (typeof h == 'string') {\n\t\t\t\t\tpath = getRegularPolygon(h, w);\n\t\t\t\t\th = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tpath = w;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (w !== undefined && h === undefined) shape ??= 'circle';\n\t\t\t\tshape ??= 'box';\n\t\t\t}\n\n\t\t\tif (shape == 'box' || shape == 'circle') {\n\t\t\t\tw ??= this.tileSize > 1 ? 1 : 50;\n\t\t\t\th ??= w;\n\t\t\t}\n\n\t\t\tlet props = {};\n\n\t\t\tlet dimensions;\n\n\t\t\t// the actual dimensions of the collider for a box or circle are a\n\t\t\t// little bit smaller so that they can slid past each other\n\t\t\t// when in a tile grid\n\t\t\tif (shape == 'box' || shape == 'circle') {\n\t\t\t\tdimensions = scaleTo({ x: w - 0.08, y: h - 0.08 }, this.tileSize);\n\t\t\t}\n\n\t\t\tlet s;\n\t\t\tif (shape == 'box') {\n\t\t\t\ts = pl.Box(dimensions.x / 2, dimensions.y / 2, scaleTo({ x: offsetX, y: offsetY }, this.tileSize), 0);\n\t\t\t} else if (shape == 'circle') {\n\t\t\t\ts = pl.Circle(scaleTo({ x: offsetX, y: offsetY }, this.tileSize), dimensions.x / 2);\n\t\t\t} else if (path) {\n\t\t\t\tlet vecs = [{ x: 0, y: 0 }];\n\t\t\t\tlet vert = { x: 0, y: 0 };\n\t\t\t\tlet min = { x: 0, y: 0 };\n\t\t\t\tlet max = { x: 0, y: 0 };\n\n\t\t\t\t// if the path is an array of position arrays\n\t\t\t\tlet usesVertices = Array.isArray(path[0]);\n\n\t\t\t\tfunction checkVert() {\n\t\t\t\t\tif (vert.x < min.x) min.x = vert.x;\n\t\t\t\t\tif (vert.y < min.y) min.y = vert.y;\n\t\t\t\t\tif (vert.x > max.x) max.x = vert.x;\n\t\t\t\t\tif (vert.y > max.y) max.y = vert.y;\n\t\t\t\t}\n\n\t\t\t\tlet x, y;\n\t\t\t\tif (usesVertices) {\n\t\t\t\t\tif (this._vertexMode) {\n\t\t\t\t\t\tx = path[0][0];\n\t\t\t\t\t\ty = path[0][1];\n\t\t\t\t\t\t// log(x, y);\n\t\t\t\t\t\tif (!this.body) {\n\t\t\t\t\t\t\tthis.x = x;\n\t\t\t\t\t\t\tthis.y = y;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tx = this.x - this._relativeOrigin.x;\n\t\t\t\t\t\t\ty = this.y - this._relativeOrigin.y;\n\t\t\t\t\t\t\tvecs.pop();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (let i = 0; i < path.length; i++) {\n\t\t\t\t\t\tif (this._vertexMode) {\n\t\t\t\t\t\t\tif (i == 0 && !this.body) continue;\n\t\t\t\t\t\t\t// verts are relative to the first vert\n\t\t\t\t\t\t\tvert.x = path[i][0] - x;\n\t\t\t\t\t\t\tvert.y = path[i][1] - y;\n\t\t\t\t\t\t\tlog(i, vert.x, vert.y);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tvert.x += path[i][0];\n\t\t\t\t\t\t\tvert.y += path[i][1];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvecs.push({ x: vert.x, y: vert.y });\n\n\t\t\t\t\t\tcheckVert();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlet rep = 1;\n\t\t\t\t\tif (path.length % 2) rep = path[path.length - 1];\n\t\t\t\t\tlet mod = rep > 0 ? 1 : -1;\n\t\t\t\t\trep = Math.abs(rep);\n\t\t\t\t\tlet ang = 0;\n\t\t\t\t\tfor (let i = 0; i < rep; i++) {\n\t\t\t\t\t\tfor (let j = 0; j < path.length - 1; j += 2) {\n\t\t\t\t\t\t\tlet len = path[j];\n\t\t\t\t\t\t\tang += path[j + 1];\n\t\t\t\t\t\t\tvert.x += len * this.p.cos(ang);\n\t\t\t\t\t\t\tvert.y += len * this.p.sin(ang);\n\t\t\t\t\t\t\tvecs.push({ x: vert.x, y: vert.y });\n\n\t\t\t\t\t\t\tcheckVert();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tang *= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\tMath.abs(Math.abs(vecs[0].x) - Math.abs(vecs[vecs.length - 1].x)) <= pl.Settings.linearSlop &&\n\t\t\t\t\tMath.abs(Math.abs(vecs[0].y) - Math.abs(vecs[vecs.length - 1].y)) <= pl.Settings.linearSlop\n\t\t\t\t) {\n\t\t\t\t\tshape = 'polygon';\n\t\t\t\t\tthis.originMode = 'center';\n\t\t\t\t} else {\n\t\t\t\t\tshape = 'chain';\n\t\t\t\t}\n\n\t\t\t\tw = max.x - min.x;\n\t\t\t\tthis._hw = w * 0.5;\n\t\t\t\th = max.y - min.y;\n\t\t\t\tthis._hh = h * 0.5;\n\n\t\t\t\tlet isConvex = false;\n\t\t\t\tif (shape == 'polygon' && this._isConvexPoly(vecs.slice(0, -1))) {\n\t\t\t\t\tisConvex = true;\n\t\t\t\t}\n\n\t\t\t\tif (this.originMode == 'start') {\n\t\t\t\t\tfor (let i = 0; i < vecs.length; i++) {\n\t\t\t\t\t\tvecs[i] = scaleTo(vecs[i], this.tileSize);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// the center relative to the first vertex\n\t\t\t\t\tlet centerX = 0;\n\t\t\t\t\tlet centerY = 0;\n\t\t\t\t\t// use centroid of a triangle method to get center\n\t\t\t\t\t// average of all vertices\n\t\t\t\t\tlet sumX = 0;\n\t\t\t\t\tlet sumY = 0;\n\n\t\t\t\t\tlet vl = vecs.length;\n\t\t\t\t\t// last vertex is same as first\n\t\t\t\t\tif (shape == 'polygon' || isConvex) vl--;\n\t\t\t\t\tfor (let i = 0; i < vl; i++) {\n\t\t\t\t\t\tsumX += vecs[i].x;\n\t\t\t\t\t\tsumY += vecs[i].y;\n\t\t\t\t\t}\n\t\t\t\t\tcenterX = sumX / vl;\n\t\t\t\t\tcenterY = sumY / vl;\n\n\t\t\t\t\tif (!this.body) {\n\t\t\t\t\t\tthis._relativeOrigin = { x: centerX, y: centerY };\n\t\t\t\t\t}\n\n\t\t\t\t\t// use bounding box method to get center\n\t\t\t\t\t// not how planck does it!\n\t\t\t\t\t// centerX = this._hw - min.x;\n\t\t\t\t\t// centerY = this._hh - min.y;\n\n\t\t\t\t\tif (this._vertexMode && usesVertices) {\n\t\t\t\t\t\tif (!this.body) {\n\t\t\t\t\t\t\t// repositions the sprite's x, y coordinates\n\t\t\t\t\t\t\t// to be in the center of the shape\n\t\t\t\t\t\t\tthis.x += centerX;\n\t\t\t\t\t\t\tthis.y += centerY;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcenterX = this._relativeOrigin.x;\n\t\t\t\t\t\t\tcenterY = this._relativeOrigin.y;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (let i = 0; i < vecs.length; i++) {\n\t\t\t\t\t\tlet vec = vecs[i];\n\t\t\t\t\t\tvecs[i] = scaleTo({ x: vec.x + offsetX - centerX, y: vec.y + offsetY - centerY }, this.tileSize);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!isConvex || vecs.length - 1 > pl.Settings.maxPolygonVertices || this._shape == 'chain') {\n\t\t\t\t\tshape = 'chain';\n\t\t\t\t}\n\n\t\t\t\tif (shape == 'polygon') {\n\t\t\t\t\ts = pl.Polygon(vecs);\n\t\t\t\t} else if (shape == 'chain') {\n\t\t\t\t\ts = pl.Chain(vecs, false);\n\t\t\t\t\tprops.density = 0;\n\t\t\t\t\tprops.restitution = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprops.shape = s;\n\t\t\tprops.density ??= this.density || 5;\n\t\t\tprops.friction ??= this.friction || 0.5;\n\t\t\tprops.restitution ??= this.bounciness || 0.2;\n\n\t\t\tif (!this.body) {\n\t\t\t\tthis.body = this.p.world.createBody({\n\t\t\t\t\tposition: scaleTo({ x: this.x, y: this.y }, this.tileSize),\n\t\t\t\t\ttype: this.collider\n\t\t\t\t});\n\t\t\t\tthis.body.sprite = this;\n\t\t\t}\n\t\t\tif (!this._shape) {\n\t\t\t\tthis._shape = shape;\n\t\t\t}\n\t\t\tthis.body.createFixture(props);\n\n\t\t\tthis._w = w;\n\t\t\tthis._hw = w * 0.5;\n\n\t\t\tif (shape == 'circle') {\n\t\t\t\tthis._diameter = w;\n\t\t\t} else {\n\t\t\t\tthis._h = h;\n\t\t\t\tthis._hh = h * 0.5;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Removes the physics body colliders from the sprite but not\n\t\t * overlap sensors.\n\t\t *\n\t\t * @private _removeColliders\n\t\t */\n\t\t_removeColliders() {\n\t\t\tthis._collides = {};\n\t\t\tthis._colliding = {};\n\t\t\tthis._collided = {};\n\t\t\tthis._removeFixtures(false);\n\t\t}\n\n\t\t/**\n\t\t * EXPERIMENTAL! This function doesn't work yet and will be changed.\n\t\t *\n\t\t * Adds a joint between this sprite and another sprite.\n\t\t *\n\t\t * @param {Sprite} spriteB the sprite to add a joint to\n\t\t * @param {String} [type] the type of joint\n\t\t * @param {Object} [props] the joint options\n\t\t */\n\t\taddJoint(spriteB, type, props) {\n\t\t\tlet spriteA = this;\n\t\t\tprops ??= {};\n\t\t\t/*\n\t\t\t * frequencyHz, dampingRatio, collideConnected, userData, ratio,\n\t\t\t * enableLimit, enableMotor, lowerAngle, maxMotorTorque\n\t\t\t * maxMotorForce, motorSpeed, referenceAngle, upperAngle, maxForce\n\t\t\t * maxTorque, localAxisA, angularOffset, joint1, joint2,\n\t\t\t * correctionFactor\n\t\t\t */\n\t\t\tif (props.motorSpeed) props.enableMotor = true;\n\n\t\t\t// function genProps(a, b) {\n\t\t\tprops = Object.assign(props, {\n\t\t\t\tbodyA: spriteA.body,\n\t\t\t\tbodyB: spriteB.body,\n\t\t\t\tlength: props.length != undefined ? scaleXTo(props.length) : null,\n\t\t\t\tmaxLength: props.maxLength != undefined ? scaleXTo(props.maxLength) : null,\n\t\t\t\tlengthA: props.lengthA != undefined ? scaleXTo(props.lengthA) : null,\n\t\t\t\tlengthB: props.lengthB != undefined ? scaleXTo(props.lengthB) : null,\n\t\t\t\tgroundAnchorA: props.groundAnchorA ? scaleXTo(props.groundAnchorA) : new pl.Vec2(0, 0),\n\t\t\t\tgroundAnchorB: props.groundAnchorB ? scaleXTo(props.groundAnchorB) : new pl.Vec2(0, 0),\n\t\t\t\tupperTranslation: props.upperTranslation ? scaleXTo(props.upperTranslation) : 1,\n\t\t\t\tlowerTranslation: props.lowerTranslation ? scaleXTo(props.lowerTranslation) : 1,\n\t\t\t\tlinearOffset: props.linearOffset ? scaleTo(props.linearOffset) : new pl.Vec2(0, 0)\n\t\t\t});\n\t\t\tif (props.anchorA) {\n\t\t\t\tprops.localAnchorA = scaleTo(props.anchorA);\n\t\t\t} else if (props.localAnchorA) {\n\t\t\t\tprops.localAnchorA = scaleTo(props.localAnchorA);\n\t\t\t} else {\n\t\t\t\tprops.localAnchorA = new pl.Vec2(0, 0);\n\t\t\t}\n\t\t\tif (props.anchorB) {\n\t\t\t\tprops.localAnchorB = scaleTo(props.anchorB);\n\t\t\t} else if (props.localAnchorB) {\n\t\t\t\tprops.localAnchorB = scaleTo(props.localAnchorB);\n\t\t\t} else {\n\t\t\t\tprops.localAnchorB = new pl.Vec2(0, 0);\n\t\t\t}\n\t\t\t// \treturn props;\n\t\t\t// }\n\n\t\t\ttype ??= 'distance';\n\t\t\tlet j;\n\t\t\tif (type == 'distance') {\n\t\t\t\tj = pl.DistanceJoint(props);\n\t\t\t} else if (type == 'orbit') {\n\t\t\t\t// let s = new Sprite([\n\t\t\t\t// \t[spriteA.x, spriteA.y],\n\t\t\t\t// \t[spriteB.x, spriteB.y]\n\t\t\t\t// ]);\n\t\t\t\t// s.overlaps(allSprites);\n\t\t\t\t// j = pl.DistanceJoint(genProps(spriteA, s));\n\t\t\t\t// this.p.world.createJoint(j);\n\t\t\t\t// genProps(s, spriteB);\n\t\t\t\t// j = pl.RevoluteJoint(props, s.body, spriteB.body, spriteB.body.getWorldCenter());\n\t\t\t} else if (type == 'pulley') {\n\t\t\t\tj = pl.PulleyJoint(props);\n\t\t\t} else if (type == 'wheel') {\n\t\t\t\tj = pl.WheelJoint(props);\n\t\t\t} else if (type == 'rope') {\n\t\t\t\tj = pl.RopeJoint(props);\n\t\t\t} else if (type == 'weld') {\n\t\t\t\tj = pl.WeldJoint(props);\n\t\t\t} else if (type == 'revolute') {\n\t\t\t\tj = pl.RevoluteJoint(props, spriteA.body, spriteB.body, spriteA.body.getWorldCenter());\n\t\t\t} else if (type == 'gear') {\n\t\t\t\tj = pl.GearJoint(props);\n\t\t\t} else if (type == 'friction') {\n\t\t\t\tj = pl.FrictionJoint(props);\n\t\t\t} else if (type == 'motor') {\n\t\t\t\tj = pl.MotorJoint(props);\n\t\t\t} else if (type == 'prismatic') {\n\t\t\t\tj = pl.PrismaticJoint(props);\n\t\t\t} else if (type == 'mouse') {\n\t\t\t\t/*j = new box2d.b2MouseJointDef();\n        j.bodyA = bodyA!=null?bodyA.body:b2world.CreateBody(new box2d.b2BodyDef());\n        j.bodyB = bodyB.body;\n        j.target = b2scaleTo(props.xy);\n        j.collideConnected = true;\n        j.maxForce = props.maxForce||(1000.0 * bodyB.body.GetMass());\n        j.frequencyHz = props.frequency||5;  // Try a value less than 5 (0 for no elasticity)\n        j.dampingRatio = props.damping||0.9; // Ranges between 0 and 1 (1 for no springiness)\n        bodyB.body.SetAwake(true);\n        bodyA=bodyB;*/\n\t\t\t}\n\t\t\treturn this.p.world.createJoint(j);\n\t\t}\n\n\t\t/**\n\t\t * Removes overlap sensors from the sprite.\n\t\t *\n\t\t * @private _removeSensors\n\t\t */\n\t\t_removeSensors() {\n\t\t\tthis._overlap = {};\n\t\t\tthis._overlaps = {};\n\t\t\tthis._overlapping = {};\n\t\t\tthis._overlapped = {};\n\t\t\tthis._removeFixtures(true);\n\t\t}\n\n\t\t// removes sensors or colliders\n\t\t_removeFixtures(isSensor) {\n\t\t\tlet prevFxt;\n\t\t\tfor (let fxt = this.fixtureList; fxt; fxt = fxt.getNext()) {\n\t\t\t\tif (fxt.m_isSensor == isSensor) {\n\t\t\t\t\tlet _fxt = fxt.m_next;\n\t\t\t\t\tfxt.destroyProxies(this.p.world.m_broadPhase);\n\t\t\t\t\tif (!prevFxt) {\n\t\t\t\t\t\tthis.body.m_fixtureList = _fxt;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tprevFxt.m_next = _fxt;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tprevFxt = fxt;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Clones the collider's props to be transferred to a new collider.\n\t\t * @private\n\t\t */\n\t\t_cloneBodyProps() {\n\t\t\tlet body = {};\n\t\t\tlet props = [...spriteProps];\n\t\t\tlet deletes = [\n\t\t\t\t'w',\n\t\t\t\t'h',\n\t\t\t\t'width',\n\t\t\t\t'height',\n\t\t\t\t'shape',\n\t\t\t\t'd',\n\t\t\t\t'diameter',\n\t\t\t\t'dynamic',\n\t\t\t\t'static',\n\t\t\t\t'kinematic',\n\t\t\t\t'collider',\n\t\t\t\t'heading',\n\t\t\t\t'direction'\n\t\t\t];\n\t\t\tfor (let del of deletes) {\n\t\t\t\tlet i = props.indexOf(del);\n\t\t\t\tif (i >= 0) props.splice(i, 1);\n\t\t\t}\n\t\t\tfor (let prop of props) {\n\t\t\t\tbody[prop] = this[prop];\n\t\t\t}\n\t\t\treturn body;\n\t\t}\n\n\t\t// get aabb() {\n\t\t// \treturn getAABB(this);\n\t\t// }\n\n\t\t// set advance(val) {\n\t\t// \tthis.body.advance(val);\n\t\t// }\n\t\t// set angularImpulse(val) {\n\t\t// \tthis.body.applyAngularImpulse(val, true);\n\t\t// }\n\n\t\t/**\n\t\t * This property disables the ability for a sprite to \"sleep\".\n\t\t *\n\t\t * \"Sleeping\" sprites are not included in the physics simulation, a\n\t\t * sprite starts \"sleeping\" when it stops moving and doesn't collide\n\t\t * with anything that it wasn't already _touching.\n\t\t *\n\t\t * @property allowSleeping\n\t\t * @type {Boolean}\n\t\t * @default true\n\t\t */\n\t\tget allowSleeping() {\n\t\t\treturn this.body.getSleepingAllowed();\n\t\t}\n\n\t\tset allowSleeping(val) {\n\t\t\tthis.body.setSleepingAllowed(val);\n\t\t}\n\n\t\t/**\n\t\t * Reference to the sprite's current animation.\n\t\t *\n\t\t * @property animation\n\t\t * @type {SpriteAnimation}\n\t\t */\n\t\tget animation() {\n\t\t\treturn this._animation;\n\t\t}\n\t\tset animation(val) {\n\t\t\tthis.changeAni(val);\n\t\t}\n\n\t\tget ani() {\n\t\t\treturn this._animation;\n\t\t}\n\t\tset ani(val) {\n\t\t\tthis.changeAni(val);\n\t\t}\n\n\t\tget anis() {\n\t\t\treturn this.animations;\n\t\t}\n\n\t\t/**\n\t\t * The bounciness of the sprite's physics body.\n\t\t *\n\t\t * @property bounciness\n\t\t * @type {Number}\n\t\t * @default 0.2\n\t\t */\n\t\tget bounciness() {\n\t\t\tif (!this.fixture) return;\n\t\t\treturn this.fixture.getRestitution();\n\t\t}\n\t\tset bounciness(val) {\n\t\t\tfor (let fxt = this.fixtureList; fxt; fxt = fxt.getNext()) {\n\t\t\t\tfxt.setRestitution(val);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * The center of mass of the sprite's physics body.\n\t\t *\n\t\t * @property centerOfMass\n\t\t * @type {Number}\n\t\t */\n\t\tget centerOfMass() {\n\t\t\treturn scaleFrom(this.body.getWorldCenter(), this.tileSize);\n\t\t}\n\n\t\t/**\n\t\t * The sprite's collider type. Default is 'dynamic'.\n\t\t *\n\t\t * The collider type can be one of the following strings:\n\t\t * 'dynamic', 'static', 'kinematic', 'none'.\n\t\t *\n\t\t * @property collider\n\t\t * @type {String}\n\t\t * @default 'dynamic'\n\t\t */\n\t\tget collider() {\n\t\t\treturn this._collider;\n\t\t}\n\t\tset collider(val) {\n\t\t\tval = val.toLowerCase();\n\t\t\tlet c = val[0];\n\t\t\tif (c == 'd') val = 'dynamic';\n\t\t\tif (c == 's') val = 'static';\n\t\t\tif (c == 'k') val = 'kinematic';\n\t\t\tif (c == 'n') val = 'none';\n\n\t\t\tif (this._collider === undefined) {\n\t\t\t\tthis._collider = val;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (val == this._collider) return;\n\n\t\t\tlet oldCollider = this._collider;\n\n\t\t\tthis._collider = val;\n\t\t\tif (oldCollider !== undefined) this._reset();\n\t\t}\n\n\t\t_reset() {\n\t\t\tlet bodyProps;\n\t\t\tif (this._collider != 'none') {\n\t\t\t\tbodyProps = this._cloneBodyProps();\n\t\t\t}\n\n\t\t\tlet v;\n\t\t\tif (this._shape == 'chain' || this._shape == 'polygon') {\n\t\t\t\tv = this._getVertices(true);\n\t\t\t\tthis._vertexMode = true;\n\t\t\t}\n\n\t\t\t// remove body\n\t\t\tif (this.body) {\n\t\t\t\tthis.p.world.destroyBody(this.body);\n\t\t\t\tthis.body = undefined;\n\t\t\t}\n\n\t\t\t// replace colliders and overlap sensors\n\t\t\tif (this._collider != 'none') {\n\t\t\t\tif (v) {\n\t\t\t\t\tthis.addCollider(0, 0, v);\n\t\t\t\t} else {\n\t\t\t\t\tthis.addCollider();\n\t\t\t\t}\n\t\t\t\tif (this._hasOverlaps) {\n\t\t\t\t\tthis._createSensors();\n\t\t\t\t}\n\t\t\t\tfor (let prop in bodyProps) {\n\t\t\t\t\tif (bodyProps[prop] !== undefined) {\n\t\t\t\t\t\tthis[prop] = bodyProps[prop];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t_parseColor(val) {\n\t\t\tif (val instanceof p5.Color) {\n\t\t\t\treturn val;\n\t\t\t} else if (typeof val != 'object') {\n\t\t\t\tif (typeof val == 'string' && val.length == 1) {\n\t\t\t\t\treturn this.p.colorPal(val);\n\t\t\t\t} else {\n\t\t\t\t\treturn this.p.color(val);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this.p.color(...val.levels);\n\t\t}\n\n\t\t/**\n\t\t * The sprite's current color. By default sprites get a random color.\n\t\t *\n\t\t * @property color\n\t\t * @type {p5.Color}\n\t\t * @default random color\n\t\t */\n\t\tget color() {\n\t\t\treturn this._color;\n\t\t}\n\t\tset color(val) {\n\t\t\tthis._color = this._parseColor(val);\n\t\t}\n\t\t/**\n\t\t * @deprecated shapeColor\n\t\t */\n\t\tget shapeColor() {\n\t\t\treturn this._color;\n\t\t}\n\t\tset shapeColor(val) {\n\t\t\tthis.color = val;\n\t\t}\n\n\t\t/**\n\t\t * Alias for sprite.fillColor\n\t\t *\n\t\t * @property fill\n\t\t * @type {p5.Color}\n\t\t * @default random color\n\t\t */\n\t\tget fill() {\n\t\t\treturn this._color;\n\t\t}\n\t\tset fill(val) {\n\t\t\tthis._color = this._parseColor(val);\n\t\t}\n\n\t\t/**\n\t\t * Alias for sprite.color\n\t\t *\n\t\t * @property fillColor\n\t\t * @type {p5.Color}\n\t\t * @default random color\n\t\t */\n\t\tget fillColor() {\n\t\t\treturn this._color;\n\t\t}\n\t\tset fillColor(val) {\n\t\t\tthis._color = this._parseColor(val);\n\t\t}\n\n\t\t/**\n\t\t * Alias for sprite.strokeColor\n\t\t *\n\t\t * @property stroke\n\t\t * @type {p5.Color}\n\t\t */\n\t\tget stroke() {\n\t\t\treturn this._stroke;\n\t\t}\n\t\tset stroke(val) {\n\t\t\tthis._stroke = this._parseColor(val);\n\t\t}\n\n\t\t/**\n\t\t * The sprite's stroke current color. By default the stroke of a sprite\n\t\t * indicates its collider type.\n\t\t *\n\t\t * @property strokeColor\n\t\t * @type {p5.Color}\n\t\t */\n\t\tget strokeColor() {\n\t\t\treturn this._stroke;\n\t\t}\n\t\tset strokeColor(val) {\n\t\t\tthis._stroke = this._parseColor(val);\n\t\t}\n\n\t\t/**\n\t\t * The sprite's current text color. Black by default.\n\t\t *\n\t\t * @property textColor\n\t\t * @type {p5.Color}\n\t\t * @default black (#000000)\n\t\t */\n\t\tget textColor() {\n\t\t\treturn this._textColor;\n\t\t}\n\t\tset textColor(val) {\n\t\t\tthis._textColor = this._parseColor(val);\n\t\t}\n\n\t\t/**\n\t\t * The density of the sprite's physics body.\n\t\t *\n\t\t * @property density\n\t\t * @type {Number}\n\t\t */\n\t\tget density() {\n\t\t\tif (!this.fixture) return;\n\t\t\treturn this.fixture.getDensity();\n\t\t}\n\t\tset density(val) {\n\t\t\tfor (let fxt = this.fixtureList; fxt; fxt = fxt.getNext()) {\n\t\t\t\tfxt.setDensity(val);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Use .layer instead.\n\t\t *\n\t\t * @deprecated depth\n\t\t */\n\t\tget depth() {\n\t\t\tconsole.warn('sprite.depth is deprecated, use sprite.layer instead');\n\t\t\treturn this.layer;\n\t\t}\n\t\tset depth(val) {\n\t\t\tconsole.warn('sprite.depth is deprecated, use sprite.layer instead');\n\t\t\tthis.layer = val;\n\t\t}\n\n\t\t/**\n\t\t * The angle of the sprite's movement or it's rotation angle if the\n\t\t * sprite is not moving.\n\t\t *\n\t\t * @property direction\n\t\t * @type {Number}\n\t\t * @default 0 (\"right\")\n\t\t */\n\t\tget direction() {\n\t\t\tif (this.body && (this.vel.x !== 0 || this.vel.y !== 0)) {\n\t\t\t\treturn this.p.atan2(this.vel.y, this.vel.x);\n\t\t\t}\n\t\t\tif (!this._direction) return this.rotation;\n\t\t\treturn this._direction;\n\t\t}\n\t\tset direction(val) {\n\t\t\tif (typeof val == 'string') {\n\t\t\t\tthis._heading = val;\n\n\t\t\t\tlet dir = val.toLowerCase().replaceAll(/[ _-]/g, '');\n\t\t\t\tlet dirs = {\n\t\t\t\t\tup: -90,\n\t\t\t\t\tdown: 90,\n\t\t\t\t\tleft: 180,\n\t\t\t\t\tright: 0,\n\t\t\t\t\tupright: -45,\n\t\t\t\t\trightup: -45,\n\t\t\t\t\tupleft: -135,\n\t\t\t\t\tleftup: -135,\n\t\t\t\t\tdownright: 45,\n\t\t\t\t\trightdown: 45,\n\t\t\t\t\tdownleft: 135,\n\t\t\t\t\tleftdown: 135,\n\t\t\t\t\tforward: this.rotation,\n\t\t\t\t\tbackward: this.rotation + 180\n\t\t\t\t};\n\t\t\t\tval = dirs[dir];\n\t\t\t}\n\n\t\t\tthis._direction = val;\n\t\t\tlet speed = this.speed;\n\t\t\tthis.vel.x = this.p.cos(val) * speed;\n\t\t\tthis.vel.y = this.p.sin(val) * speed;\n\t\t}\n\n\t\t/**\n\t\t * The amount of resistance a sprite has to being moved.\n\t\t *\n\t\t * @property drag\n\t\t * @type {Number}\n\t\t * @default 0\n\t\t */\n\t\tget drag() {\n\t\t\tif (this.body) return this.body.getLinearDamping();\n\t\t\telse return Infinity;\n\t\t}\n\t\tset drag(val) {\n\t\t\tif (this.body) this.body.setLinearDamping(val);\n\t\t}\n\n\t\t/**\n\t\t * Displays the sprite.\n\t\t *\n\t\t * This function is called automatically at\n\t\t * the end of each p5.js draw function call but it can also be run\n\t\t * separately to customize the order sprites are drawn in relation\n\t\t * to other stuff drawn to the p5.js canvas. Also see the sprite.layer\n\t\t * property.\n\t\t *\n\t\t * A sprite's draw function can be overridden with a\n\t\t * custom draw function, in which the center of the sprite is\n\t\t * at (0, 0).\n\t\t *\n\t\t * @example\n\t\t * sprite.draw = function() {\n\t\t *   // an oval\n\t\t *   ellipse(0,0,20,10);\n\t\t * }\n\t\t *\n\t\t * @method draw\n\t\t */\n\t\tget draw() {\n\t\t\treturn this._display;\n\t\t}\n\n\t\tset draw(val) {\n\t\t\tthis._draw = val;\n\t\t}\n\n\t\t/**\n\t\t * True if the sprite's physics body is dynamic.\n\t\t *\n\t\t * @property dynamic\n\t\t * @type {Boolean}\n\t\t * @default true\n\t\t */\n\t\tget dynamic() {\n\t\t\tif (!this.body) return undefined;\n\t\t\treturn this.body.isDynamic();\n\t\t}\n\t\tset dynamic(val) {\n\t\t\tif (val) this.collider = 'dynamic';\n\t\t}\n\n\t\t/**\n\t\t * If true the sprite can not rotate.\n\t\t *\n\t\t * @property rotationLock\n\t\t * @type {Boolean}\n\t\t * @default false\n\t\t */\n\t\tget rotationLock() {\n\t\t\tif (!this.body) return undefined;\n\t\t\treturn this.body.isFixedRotation();\n\t\t}\n\t\tset rotationLock(val) {\n\t\t\tif (this.body) this.body.setFixedRotation(val);\n\t\t}\n\n\t\t/**\n\t\t * Returns the first node in a linked list of the planck physics\n\t\t * body's fixtures.\n\t\t */\n\t\tget fixture() {\n\t\t\treturn this.fixtureList;\n\t\t}\n\t\t/**\n\t\t * Returns the first node in a linked list of the planck physics\n\t\t * body's fixtures.\n\t\t */\n\t\tget fixtureList() {\n\t\t\tif (!this.body) return null;\n\t\t\treturn this.body.getFixtureList();\n\t\t}\n\n\t\t/**\n\t\t * The amount the sprite's physics body resists moving\n\t\t * when rubbing against another physics body.\n\t\t *\n\t\t * @property friction\n\t\t * @type {Number}\n\t\t * @default 0.5\n\t\t */\n\t\tget friction() {\n\t\t\tif (!this.fixture) return;\n\t\t\treturn this.fixture.getFriction();\n\t\t}\n\t\tset friction(val) {\n\t\t\tfor (let fxt = this.fixtureList; fxt; fxt = fxt.getNext()) {\n\t\t\t\tfxt.setFriction(val);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * The sprite's heading. This is a string that can be set to\n\t\t * \"up\", \"down\", \"left\", \"right\", \"upRight\", \"upLeft\", \"downRight\"\n\t\t *\n\t\t * It ignores cardinal direction word order, capitalization, spaces,\n\t\t * underscores, and dashes.\n\t\t *\n\t\t * @property heading\n\t\t * @type {String}\n\t\t * @default undefined\n\t\t */\n\t\tget heading() {\n\t\t\treturn this._heading;\n\t\t}\n\t\tset heading(val) {\n\t\t\tthis.direction = val;\n\t\t}\n\n\t\t/**\n\t\t * Use .static instead.\n\t\t *\n\t\t * @deprecated immovable\n\t\t */\n\t\tget immovable() {\n\t\t\tconsole.warn('sprite.immovable is deprecated, use sprite.static instead');\n\t\t\treturn this.body.isStatic();\n\t\t}\n\t\tset immovable(val) {\n\t\t\tconsole.warn('sprite.immovable is deprecated, use sprite.static instead');\n\t\t\tif (val) this.body.setStatic();\n\t\t}\n\t\t// set impulse(val) {\n\t\t// \tthis.body.applyLinearImpulse(val, this.body.getWorldCenter(), true);\n\t\t// }\n\t\t// get inertia() {\n\t\t// \treturn this.body.getInertia();\n\t\t// }\n\n\t\t/**\n\t\t * A reference to the sprite's current image.\n\t\t *\n\t\t * @property img\n\t\t * @type {SpriteAnimation}\n\t\t */\n\t\tget img() {\n\t\t\treturn this._animation.frameImage;\n\t\t}\n\t\tset img(val) {\n\t\t\tthis.changeAni(val);\n\t\t}\n\n\t\t/**\n\t\t * A reference to the sprite's current image.\n\t\t *\n\t\t * @property image\n\t\t * @type {SpriteAnimation}\n\t\t */\n\t\tget image() {\n\t\t\treturn this._animation.frameImage;\n\t\t}\n\t\tset image(val) {\n\t\t\tthis.changeAni(val);\n\t\t}\n\n\t\t/**\n\t\t * True if the sprite is moving.\n\t\t *\n\t\t * @property isMoving\n\t\t * @type {Boolean}\n\t\t * @readonly\n\t\t */\n\t\tget isMoving() {\n\t\t\treturn this.vel.x != 0 || this.vel.y != 0;\n\t\t}\n\n\t\t/**\n\t\t * Set this to true if the sprite goes really fast to prevent\n\t\t * inaccurate physics simulation.\n\t\t *\n\t\t * @property isSuperFast\n\t\t * @type {Boolean}\n\t\t * @default false\n\t\t */\n\t\tget isSuperFast() {\n\t\t\tif (!this.body) return undefined;\n\t\t\treturn this.body.isBullet();\n\t\t}\n\t\tset isSuperFast(val) {\n\t\t\tif (this.body) this.body.setBullet(val);\n\t\t}\n\n\t\t// get joint() {\n\t\t// \treturn this.body.getJointList().joint;\n\t\t// }\n\t\t// get jointList() {\n\t\t// \treturn this.body.getJointList();\n\t\t// }\n\n\t\t/**\n\t\t * True if the sprite's physics body is kinematic.\n\t\t *\n\t\t * @property kinematic\n\t\t * @type {Boolean}\n\t\t * @default false\n\t\t */\n\t\tget kinematic() {\n\t\t\tif (!this.body) return undefined;\n\t\t\treturn this.body.isKinematic();\n\t\t}\n\t\tset kinematic(val) {\n\t\t\tif (val) this.collider = 'kinematic';\n\t\t}\n\t\t/**\n\t\t * The mass of the sprite's physics body.\n\t\t *\n\t\t * @property mass\n\t\t * @type {Number}\n\t\t */\n\t\tget mass() {\n\t\t\tif (!this.body) return undefined;\n\t\t\treturn this.body.getMass();\n\t\t}\n\t\tset mass(val) {\n\t\t\tif (!this.body) return;\n\t\t\tlet t = this.massData;\n\t\t\tt.mass = val;\n\t\t\tthis.body.setMassData(t);\n\t\t}\n\n\t\tget massData() {\n\t\t\tconst t = { I: 0, center: new pl.Vec2(0, 0), mass: 0 };\n\t\t\tthis.body.getMassData(t);\n\t\t\tt.center = scaleFrom(t.center, this.tileSize);\n\t\t\treturn t;\n\t\t}\n\t\t// set massData(val) {\n\t\t// \tval.center = scaleTo(val.center);\n\t\t// \tthis.body.setMassData(val);\n\t\t// }\n\n\t\t// get next() {\n\t\t// \treturn this.body.getNext();\n\t\t// }\n\n\t\t/**\n\t\t * Verbose alias for sprite.prevPos\n\t\t *\n\t\t * @property previousPosition\n\t\t * @type {object}\n\t\t */\n\t\tget previousPosition() {\n\t\t\treturn this.prevPos;\n\t\t}\n\t\tset previousPosition(val) {\n\t\t\tthis.prevPos = val;\n\t\t}\n\n\t\t/**\n\t\t * The angle of the sprite's rotation, not the direction it is moving.\n\t\t *\n\t\t * @property rotation\n\t\t * @type {Number}\n\t\t * @default 0\n\t\t */\n\t\tget rotation() {\n\t\t\tif (!this.body) return this._angle || 0;\n\t\t\tif (this.p._angleMode === p5.prototype.DEGREES) {\n\t\t\t\treturn p5.prototype.degrees(this.body.getAngle());\n\t\t\t}\n\t\t\treturn this.body.getAngle();\n\t\t}\n\t\tset rotation(val) {\n\t\t\tif (this.body) {\n\t\t\t\tif (this.p._angleMode === p5.prototype.DEGREES) {\n\t\t\t\t\tthis.body.setAngle(p5.prototype.radians(val));\n\t\t\t\t} else {\n\t\t\t\t\tthis.body.setAngle(val);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis._angle = val;\n\t\t\t}\n\t\t}\n\t\t/**\n\t\t * The amount the sprite resists rotating.\n\t\t *\n\t\t * @property rotationDrag\n\t\t * @type {Number}\n\t\t * @default 0\n\t\t */\n\t\tget rotationDrag() {\n\t\t\tif (!this.body) return undefined;\n\t\t\treturn this.body.getAngularDamping();\n\t\t}\n\t\tset rotationDrag(val) {\n\t\t\tif (this.body) this.body.setAngularDamping(val);\n\t\t}\n\t\t/**\n\t\t * The speed of the sprite's rotation.\n\t\t *\n\t\t * @property rotationSpeed\n\t\t * @type {Number}\n\t\t * @default 0\n\t\t */\n\t\tget rotationSpeed() {\n\t\t\tif (this.body) return this.body.getAngularVelocity();\n\t\t\treturn this._rotationSpeed || 0;\n\t\t}\n\t\tset rotationSpeed(val) {\n\t\t\tif (this.body) this.body.setAngularVelocity(val);\n\t\t\telse this._rotationSpeed = val;\n\t\t}\n\n\t\t/**\n\t\t * Scale of the sprite's physics body. Default is {x: 1, y: 1}\n\t\t *\n\t\t * The getter for sprite.scale returns the scale as an object with\n\t\t * x and y properties.\n\t\t *\n\t\t * The valueOf function for sprite.scale returns the scale as a\n\t\t * number. This enables users to do things like `sprite.scale *= 2`\n\t\t * to double the sprite's scale.\n\t\t *\n\t\t * @property scale\n\t\t * @type {Number|Object}\n\t\t * @default 1\n\t\t */\n\t\tget scale() {\n\t\t\treturn this._scale;\n\t\t}\n\t\tset scale(val) {\n\t\t\tif (val <= 0) val = 0.01;\n\t\t\tif (typeof val === 'number') {\n\t\t\t\tval = { x: val, y: val };\n\t\t\t}\n\t\t\tif (val.x == this._scale._x && val.y == this._scale._y) return;\n\n\t\t\tlet scalars = {\n\t\t\t\tx: val.x / this._scale._x,\n\t\t\t\ty: val.y / this._scale._y\n\t\t\t};\n\n\t\t\tthis._w *= scalars.x;\n\t\t\tthis._hw *= scalars.x;\n\t\t\tif (this._h) {\n\t\t\t\tthis._h *= scalars.y;\n\t\t\t\tthis._hh *= scalars.y;\n\t\t\t}\n\t\t\tthis._resizeCollider(scalars);\n\n\t\t\tthis._scale._x = val.x;\n\t\t\tthis._scale._y = val.y;\n\t\t\tthis._scale._avg = val.x;\n\t\t}\n\n\t\t/**\n\t\t * Wake a sprite up or put it to sleep.\n\t\t *\n\t\t * \"Sleeping\" sprites are not included in the physics simulation, a\n\t\t * sprite starts \"sleeping\" when it stops moving and doesn't collide\n\t\t * with anything that it wasn't already _touching.\n\t\t *\n\t\t * @property sleeping\n\t\t * @type {Boolean}\n\t\t * @default true\n\t\t */\n\t\tget sleeping() {\n\t\t\tif (this.body) return !this.body.isAwake();\n\t\t\treturn undefined;\n\t\t}\n\n\t\tset sleeping(val) {\n\t\t\tif (this.body) this.body.setAwake(!val);\n\t\t}\n\n\t\t/**\n\t\t * @deprecated\n\t\t */\n\t\tgetSpeed() {\n\t\t\tconsole.warn('getSpeed() is deprecated, use sprite.speed instead');\n\t\t\treturn this.speed;\n\t\t}\n\n\t\t/**\n\t\t * The sprite's speed.\n\t\t *\n\t\t * @property speed\n\t\t * @type {Number}\n\t\t * @default 0\n\t\t */\n\t\tget speed() {\n\t\t\treturn this.p.createVector(this.vel.x, this.vel.y).mag();\n\t\t}\n\t\tset speed(val) {\n\t\t\tlet angle = this.direction;\n\t\t\tthis.vel.x = this.p.cos(angle) * val;\n\t\t\tthis.vel.y = this.p.sin(angle) * val;\n\t\t}\n\n\t\t/**\n\t\t * Is the sprite's physics collider static?\n\t\t *\n\t\t * @property static\n\t\t * @type {Boolean}\n\t\t * @default false\n\t\t */\n\t\tget static() {\n\t\t\tif (!this.body) return undefined;\n\t\t\treturn this.body.isStatic();\n\t\t}\n\t\tset static(val) {\n\t\t\tif (val) this.collider = 'static';\n\t\t}\n\n\t\t/**\n\t\t * The sprite's vertices.\n\t\t *\n\t\t * @property vertices\n\t\t * @type {Array} An array of p5.Vector objects.\n\t\t * @readonly\n\t\t */\n\t\tget vertices() {\n\t\t\treturn this._getVertices();\n\t\t}\n\n\t\t_getVertices(output2DArrays) {\n\t\t\tlet f = this.fixture;\n\t\t\twhile (f.m_next) f = f.m_next;\n\t\t\tlet s = f.getShape();\n\t\t\tlet v = [...s.m_vertices];\n\t\t\tif (s.m_type == 'polygon') v.unshift(v.at(-1));\n\t\t\tlet x = this.x;\n\t\t\tlet y = this.y;\n\t\t\tfor (let i = 0; i < v.length; i++) {\n\t\t\t\tlet arr = [fixRound((v[i].x / this.tileSize) * plScale + x), fixRound((v[i].y / this.tileSize) * plScale + y)];\n\t\t\t\tlog(arr);\n\t\t\t\tif (output2DArrays) v[i] = arr;\n\t\t\t\telse v[i] = pInst.createVector(arr[0], arr[1]);\n\t\t\t}\n\t\t\treturn v;\n\t\t}\n\n\t\t// TODO set vertices\n\n\t\t/**\n\t\t * The horizontal position of the sprite.\n\t\t * @property x\n\t\t * @type {Number}\n\t\t */\n\t\tget x() {\n\t\t\tif (!this.body) return this._pos.x;\n\t\t\tlet x = (this.body.getPosition().x / this.tileSize) * plScale;\n\t\t\treturn fixRound(x);\n\t\t}\n\t\tset x(val) {\n\t\t\tif (this.body) {\n\t\t\t\tlet pos = new pl.Vec2((val * this.tileSize) / plScale, this.body.getPosition().y);\n\t\t\t\tthis.body.setPosition(pos);\n\t\t\t}\n\t\t\tthis._pos.x = val;\n\t\t}\n\t\t/**\n\t\t * The vertical position of the sprite.\n\t\t * @property y\n\t\t * @type {Number}\n\t\t */\n\t\tget y() {\n\t\t\tif (!this.body) return this._pos.y;\n\t\t\tlet y = (this.body.getPosition().y / this.tileSize) * plScale;\n\t\t\treturn fixRound(y);\n\t\t}\n\t\tset y(val) {\n\t\t\tif (this.body) {\n\t\t\t\tlet pos = new pl.Vec2(this.body.getPosition().x, (val * this.tileSize) / plScale);\n\t\t\t\tthis.body.setPosition(pos);\n\t\t\t}\n\t\t\tthis._pos.y = val;\n\t\t}\n\t\t/**\n\t\t * Set the position vector {x, y}\n\t\t *\n\t\t * @property pos\n\t\t * @type {Object}\n\t\t */\n\t\tset pos(val) {\n\t\t\tlet pos = new pl.Vec2((val.x * this.tileSize) / plScale, (val.y * this.tileSize) / plScale);\n\t\t\t_this.body.setPosition(pos);\n\t\t}\n\t\t/**\n\t\t * The width of the sprite.\n\t\t * @property w\n\t\t * @type {Number}\n\t\t */\n\t\tget w() {\n\t\t\treturn this._w;\n\t\t}\n\t\tset w(val) {\n\t\t\tif (val < 0) val = 0.01;\n\t\t\tif (val == this._w) return;\n\t\t\tthis._dimensionsUndefined = false;\n\t\t\tlet scalarX = val / this._w;\n\t\t\tthis._w = val;\n\t\t\tthis._hw = val * 0.5;\n\t\t\tthis._resizeCollider({ x: scalarX, y: 1 });\n\t\t}\n\t\t/**\n\t\t * Half the width of the sprite.\n\t\t * @property hw\n\t\t * @type {Number}\n\t\t */\n\t\tget hw() {\n\t\t\treturn this._hw;\n\t\t}\n\t\tset hw(val) {\n\t\t\tthrow new FriendlyError('Sprite.hw');\n\t\t}\n\t\t/**\n\t\t * The width of the sprite.\n\t\t * @property width\n\t\t * @type {Number}\n\t\t */\n\t\tget width() {\n\t\t\treturn this.w;\n\t\t}\n\t\tset width(val) {\n\t\t\tthis.w = val;\n\t\t}\n\t\t/**\n\t\t * Half the width of the sprite.\n\t\t * @property halfWidth\n\t\t * @type {Number}\n\t\t */\n\t\tget halfWidth() {\n\t\t\treturn this.hw;\n\t\t}\n\t\tset halfWidth(val) {\n\t\t\tthrow new FriendlyError('Sprite.hw');\n\t\t}\n\t\t/**\n\t\t * The height of the sprite.\n\t\t * @property h\n\t\t * @type {Number}\n\t\t */\n\t\tget h() {\n\t\t\tif (this.shape == 'circle') return this._w;\n\t\t\treturn this._h;\n\t\t}\n\t\tset h(val) {\n\t\t\tif (val < 0) val = 0.01;\n\t\t\tif (this.shape == 'circle') {\n\t\t\t\tthis.w = val;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (val == this._h) return;\n\t\t\tthis._dimensionsUndefined = false;\n\t\t\tlet scalarY = val / this._h;\n\t\t\tthis._h = val;\n\t\t\tthis._hh = val * 0.5;\n\t\t\tthis._resizeCollider({ x: 1, y: scalarY });\n\t\t}\n\t\t/**\n\t\t * Half the height of the sprite.\n\t\t * @property hh\n\t\t * @type {Number}\n\t\t */\n\t\tget hh() {\n\t\t\treturn this._hh || this._hw;\n\t\t}\n\t\tset hh(val) {\n\t\t\tthrow new FriendlyError('Sprite.hh');\n\t\t}\n\t\t/**\n\t\t * The height of the sprite.\n\t\t * @property height\n\t\t * @type {Number}\n\t\t */\n\t\tget height() {\n\t\t\treturn this.h;\n\t\t}\n\t\tset height(val) {\n\t\t\tthis.h = val;\n\t\t}\n\t\t/**\n\t\t * Half the height of the sprite.\n\t\t * @property halfHeight\n\t\t * @type {Number}\n\t\t */\n\t\tget halfHeight() {\n\t\t\treturn this.hh;\n\t\t}\n\t\tset halfHeight(val) {\n\t\t\tthrow new FriendlyError('Sprite.hh');\n\t\t}\n\t\t/**\n\t\t * The diameter of a circular sprite.\n\t\t * @property d\n\t\t * @type {Number}\n\t\t */\n\t\tget d() {\n\t\t\tthis._diameter ??= this.w;\n\t\t\treturn this._diameter;\n\t\t}\n\t\tset d(val) {\n\t\t\tif (val < 0) {\n\t\t\t\tthis.remove();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet shapeChange = this.shape != 'circle';\n\t\t\tif (!shapeChange) {\n\t\t\t\tif (this._diameter == val) return;\n\t\t\t\tthis._diameter = val;\n\t\t\t} else {\n\t\t\t\tlet bodyProps;\n\t\t\t\tif (this._collider == 'none') {\n\t\t\t\t\tbodyProps = this._cloneBodyProps();\n\t\t\t\t}\n\t\t\t\tthis._removeSensors();\n\t\t\t\tthis._removeColliders();\n\t\t\t\tthis._h = undefined;\n\t\t\t\tthis._shape = undefined;\n\t\t\t\tif (this._collider != 'none') {\n\t\t\t\t\tthis.addCollider(0, 0, val);\n\t\t\t\t\tfor (let prop in bodyProps) {\n\t\t\t\t\t\tif (bodyProps[prop] !== undefined) {\n\t\t\t\t\t\t\tthis[prop] = bodyProps[prop];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis._shape = 'circle';\n\t\t\t}\n\t\t\tlet scalar = val / this._w;\n\t\t\tthis._w = val;\n\t\t\tthis._hw = val * 0.5;\n\t\t\tthis._h = val;\n\t\t\tthis._hh = this._hw;\n\t\t\tif (shapeChange) return;\n\t\t\tthis._resizeCollider({ x: scalar, y: scalar });\n\t\t}\n\t\t/**\n\t\t * The diameter of a circular sprite.\n\t\t * @property diameter\n\t\t * @type {Number}\n\t\t */\n\t\tget diameter() {\n\t\t\treturn this.d;\n\t\t}\n\t\tset diameter(val) {\n\t\t\tthis.d = val;\n\t\t}\n\n\t\t/**\n\t\t * The radius of a circular sprite.\n\t\t * @property r\n\t\t * @type {Number}\n\t\t */\n\t\tget r() {\n\t\t\treturn this._hw;\n\t\t}\n\t\tset r(val) {\n\t\t\tthis.d = val * 2;\n\t\t}\n\n\t\t/**\n\t\t * The radius of a circular sprite.\n\t\t * @property radius\n\t\t * @type {Number}\n\t\t */\n\t\tget radius() {\n\t\t\treturn this._hw;\n\t\t}\n\t\tset radius(val) {\n\t\t\tthis.d = val * 2;\n\t\t}\n\n\t\t/**\n\t\t * Resizes the collider of the sprite.\n\t\t *\n\t\t * @private _resizeCollider\n\t\t * @param {*} scalars The x and y scalars to resize the collider by.\n\t\t */\n\t\t_resizeCollider(scalars) {\n\t\t\tif (!this.body) return;\n\n\t\t\tif (this.shape == 'circle') {\n\t\t\t\tlet fxt = this.fixture;\n\t\t\t\tlet sh = fxt.m_shape;\n\t\t\t\tsh.m_radius *= scalars.x;\n\t\t\t} else {\n\t\t\t\tfor (let fxt = this.fixtureList; fxt; fxt = fxt.getNext()) {\n\t\t\t\t\tif (fxt.m_isSensor) continue;\n\t\t\t\t\tlet sh = fxt.m_shape;\n\t\t\t\t\tfor (let vert of sh.m_vertices) {\n\t\t\t\t\t\tvert.x *= scalars.x;\n\t\t\t\t\t\tvert.y *= scalars.y;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.collider == 'static') this.body.synchronizeFixtures();\n\t\t}\n\n\t\t/**\n\t\t * Validate convexity.\n\t\t *\n\t\t * @private _isConvexPoly\n\t\t * @param vecs {Array} an array of planck.Vec2 vertices\n\t\t * @returns true if the polygon is convex\n\t\t */\n\t\t_isConvexPoly(vecs) {\n\t\t\tloopk: for (let k = 0; k < 2; k++) {\n\t\t\t\tif (k == 1) vecs = vecs.reverse();\n\t\t\t\tfor (let i = 0; i < vecs.length; ++i) {\n\t\t\t\t\tconst i1 = i;\n\t\t\t\t\tconst i2 = i < vecs.length - 1 ? i1 + 1 : 0;\n\t\t\t\t\tconst p = vecs[i1];\n\t\t\t\t\tconst e = pl.Vec2.sub(vecs[i2], p);\n\n\t\t\t\t\tfor (let j = 0; j < vecs.length; ++j) {\n\t\t\t\t\t\tif (j == i1 || j == i2) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst v = pl.Vec2.sub(vecs[j], p);\n\t\t\t\t\t\tconst c = pl.Vec2.cross(e, v);\n\t\t\t\t\t\tif (c < 0.0) {\n\t\t\t\t\t\t\tif (k == 0) continue loopk;\n\t\t\t\t\t\t\telse return false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t}\n\n\t\t/**\n\t\t * The kind of shape: 'box', 'circle', 'chain', or 'polygon'.\n\t\t *\n\t\t * @property shape\n\t\t * @type {String}\n\t\t * @default box\n\t\t */\n\t\tget shape() {\n\t\t\treturn this._shape;\n\t\t}\n\n\t\tset shape(val) {\n\t\t\tif (val == this._shape) return;\n\n\t\t\tlet validShapes = ['box', 'circle', 'chain', 'polygon'];\n\t\t\tif (validShapes.indexOf(val) == -1) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Invalid shape type: \"' + val + '\"\\nThe valid shape types are: \"' + validShapes.join('\", \"') + '\"'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (val == 'circle') {\n\t\t\t\tthis.d = this.w;\n\t\t\t} else {\n\t\t\t\tthis._shape = val;\n\t\t\t\tthis._reset();\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * You can set the sprite's update function to your own custom\n\t\t * update function that will be run after every draw call or when\n\t\t * the updateSprites function is called.\n\t\t *\n\t\t * @method update\n\t\t */\n\t\tget update() {\n\t\t\treturn this._update;\n\t\t}\n\n\t\tset update(val) {\n\t\t\tthis._customUpdate = val;\n\t\t}\n\n\t\tget pos() {\n\t\t\treturn this._position;\n\t\t}\n\n\t\tset pos(val) {\n\t\t\tthis.x = val.x;\n\t\t\tthis.y = val.y;\n\t\t}\n\n\t\tget position() {\n\t\t\treturn this._position;\n\t\t}\n\n\t\tset position(val) {\n\t\t\tthis.pos = val;\n\t\t}\n\n\t\tget vel() {\n\t\t\treturn this._velocity;\n\t\t}\n\n\t\tset vel(val) {\n\t\t\tthis.vel.x = val.x;\n\t\t\tthis.vel.y = val.y;\n\t\t}\n\n\t\tset velocity(val) {\n\t\t\tthis.vel = val;\n\t\t}\n\n\t\tget velocity() {\n\t\t\treturn this._velocity;\n\t\t}\n\n\t\t/**\n\t\t * Updates the sprite. Called automatically at the end of the draw\n\t\t * cycle.\n\t\t *\n\t\t * @private _update\n\t\t */\n\t\t_update() {\n\t\t\tif (this.animation) this.animation.update();\n\n\t\t\tif (!this.body) {\n\t\t\t\tthis.rotation += this._rotationSpeed;\n\t\t\t\tthis.x += this.vel.x;\n\t\t\t\tthis.y += this.vel.y;\n\t\t\t}\n\n\t\t\tfor (let prop in this.mouse) {\n\t\t\t\tif (this.mouse[prop] == -1) this.mouse[prop] = 0;\n\t\t\t}\n\n\t\t\tlet a = this;\n\t\t\tfor (let event in eventTypes) {\n\t\t\t\tfor (let entry of this[event]) {\n\t\t\t\t\tlet contactType;\n\t\t\t\t\tlet b = entry[0];\n\t\t\t\t\tlet f = entry[1] + 1;\n\t\t\t\t\tthis[event].set(b, f);\n\t\t\t\t\tif (f == 0) {\n\t\t\t\t\t\tthis[event].delete(b);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else if (f == -1) {\n\t\t\t\t\t\tcontactType = eventTypes[event][2];\n\t\t\t\t\t} else if (f == 1) {\n\t\t\t\t\t\tcontactType = eventTypes[event][0];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontactType = eventTypes[event][1];\n\t\t\t\t\t}\n\t\t\t\t\tif (b instanceof Group) continue;\n\n\t\t\t\t\tlet cb = _findContactCB(contactType, a, b);\n\t\t\t\t\tif (typeof cb == 'function') cb(a, b, f);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this._customUpdate) this._customUpdate();\n\t\t}\n\n\t\t/**\n\t\t * Default draw\n\t\t *\n\t\t * @private _draw\n\t\t */\n\t\t_draw() {\n\t\t\tif (this.strokeWeight) this.p.strokeWeight(this.strokeWeight);\n\t\t\tif (this.animation && !this.debug) {\n\t\t\t\tthis.animation.draw(0, 0, 0, this._scale.x, this._scale.y);\n\t\t\t} else if (this.fixture != null) {\n\t\t\t\tif (this._shape == 'chain') this.p.stroke(this.stroke || this.color);\n\t\t\t\telse if (this._stroke) this.p.stroke(this._stroke);\n\t\t\t\tfor (let fxt = this.fixtureList; fxt; fxt = fxt.getNext()) {\n\t\t\t\t\tthis._drawFixture(fxt);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.p.stroke(this._stroke || 120);\n\t\t\t\tif (this._shape == 'box') {\n\t\t\t\t\tthis.p.rect(0, 0, this.w * this.tileSize, this.h * this.tileSize);\n\t\t\t\t} else if (this._shape == 'circle') {\n\t\t\t\t\tthis.p.circle(0, 0, this.d * this.tileSize);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (this.text !== undefined) {\n\t\t\t\tthis.p.textAlign(this.p.CENTER, this.p.CENTER);\n\t\t\t\tthis.p.fill(this.textColor);\n\t\t\t\tthis.p.textSize(this.textSize * this.tileSize);\n\t\t\t\tthis.p.text(this.text, 0, 0);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Displays the Sprite with rotation and scaling applied before\n\t\t * the sprite's draw function is called.\n\t\t *\n\t\t * @private _display\n\t\t */\n\t\t_display() {\n\t\t\tlet x = this.p.width * 0.5 - this.p.world.origin.x + this.x * this.tileSize;\n\t\t\tlet y = this.p.height * 0.5 - this.p.world.origin.y + this.y * this.tileSize;\n\n\t\t\t// skip drawing for out-of-view bodies, but\n\t\t\t// edges can be very long, so they still should be drawn\n\t\t\tif (\n\t\t\t\tthis.shape != 'chain' &&\n\t\t\t\tthis.p.camera.active &&\n\t\t\t\t(x + this.w < this.p.camera.bound.min.x ||\n\t\t\t\t\tx - this.w > this.p.camera.bound.max.x ||\n\t\t\t\t\ty + this.h < this.p.camera.bound.min.y ||\n\t\t\t\t\ty - this.h > this.p.camera.bound.max.y)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tx = fixRound(x);\n\t\t\tx -= (this.w * this.tileSize) % 2 ? 0.5 : 0;\n\t\t\ty = fixRound(y);\n\t\t\ty -= (this.h * this.tileSize) % 2 ? 0.5 : 0;\n\n\t\t\t// x += this.tileSize * 0.015;\n\t\t\t// y += this.tileSize * 0.015;\n\n\t\t\tthis.p.push();\n\t\t\tthis.p.imageMode(p5.prototype.CENTER);\n\t\t\tthis.p.rectMode(p5.prototype.CENTER);\n\t\t\tthis.p.ellipseMode(p5.prototype.CENTER);\n\n\t\t\tthis.p.translate(x, y);\n\t\t\tif (this.rotation) this.p.rotate(this.rotation);\n\t\t\tthis.p.scale(this._mirror.x, this._mirror.y);\n\n\t\t\tthis.p.fill(this.color);\n\n\t\t\tthis._draw();\n\n\t\t\tthis.p.pop();\n\t\t\tthis.p.p5play.autoDrawSprites = false;\n\n\t\t\tthis._cameraActiveWhenDrawn = this.p.camera.active;\n\t\t}\n\n\t\t/**\n\t\t * Draws a fixture. Used to draw the sprite's physics body.\n\t\t *\n\t\t * @private _drawFixture\n\t\t */\n\t\t_drawFixture(fxt) {\n\t\t\tconst sh = fxt.m_shape;\n\t\t\tif (sh.m_type == 'polygon' || sh.m_type == 'chain') {\n\t\t\t\tif (sh.m_type == 'chain') {\n\t\t\t\t\tthis.p.push();\n\t\t\t\t\tthis.p.noFill();\n\t\t\t\t}\n\t\t\t\tlet v = sh.m_vertices;\n\t\t\t\tthis.p.beginShape();\n\t\t\t\tfor (let i = 0; i < v.length; i++) {\n\t\t\t\t\tthis.p.vertex(v[i].x * plScale, v[i].y * plScale);\n\t\t\t\t}\n\t\t\t\tif (sh.m_type != 'chain') this.p.endShape(p5.prototype.CLOSE);\n\t\t\t\telse {\n\t\t\t\t\tthis.p.endShape();\n\t\t\t\t\tthis.p.pop();\n\t\t\t\t}\n\t\t\t} else if (sh.m_type == 'circle') {\n\t\t\t\tconst d = sh.m_radius * 2 * plScale;\n\t\t\t\tthis.p.ellipse(sh.m_p.x * plScale, sh.m_p.y * plScale, d, d);\n\t\t\t} else if (sh.m_type == 'edge') {\n\t\t\t\tthis.p.line(\n\t\t\t\t\tsh.m_vertex1.x * plScale,\n\t\t\t\t\tsh.m_vertex1.y * plScale,\n\t\t\t\t\tsh.m_vertex2.x * plScale,\n\t\t\t\t\tsh.m_vertex2.y * plScale\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Apply a force that is scaled to the sprite's mass.\n\t\t *\n\t\t * @method applyForce\n\t\t * @param {p5.Vector|Array} forceVector force vector\n\t\t * @param {p5.Vector|Array} [forceOrigin] force origin\n\t\t */\n\t\tapplyForce(forceVector, forceOrigin) {\n\t\t\tif (!this.body) return;\n\t\t\tif (Array.isArray(forceVector)) {\n\t\t\t\tforceVector = new pl.Vec2(forceVector[0], forceVector[1]);\n\t\t\t} else {\n\t\t\t\tforceVector = new pl.Vec2(forceVector.x || 0, forceVector.y || 0);\n\t\t\t}\n\t\t\tif (forceOrigin) {\n\t\t\t\tif (Array.isArray(forceOrigin)) {\n\t\t\t\t\tforceOrigin = new pl.Vec2(forceOrigin[0], forceOrigin[1]);\n\t\t\t\t} else {\n\t\t\t\t\tforceOrigin = new pl.Vec2(forceOrigin.x || 0, forceOrigin.y || 0);\n\t\t\t\t}\n\t\t\t\tthis.body.applyForce(forceVector.mul(this.body.m_mass), forceOrigin, false);\n\t\t\t} else {\n\t\t\t\tthis.body.applyForceToCenter(forceVector.mul(this.body.m_mass), false);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Apply a torque on the sprite's physics body.\n\t\t * Torque is the force that causes rotation.\n\t\t * A positive torque will rotate the sprite clockwise.\n\t\t * A negative torque will rotate the sprite counter-clockwise.\n\t\t *\n\t\t * @method applyTorque\n\t\t * @param {Number} torque The amount of torque to apply.\n\t\t */\n\t\tapplyTorque(val) {\n\t\t\tthis.body.applyTorque(val, true);\n\t\t}\n\n\t\t/**\n\t\t * Deprecated: set sprite.vel instead.\n\t\t *\n\t\t * Sets the velocity vector.\n\t\t *\n\t\t * @deprecated setVelocity\n\t\t * @param {Number} vector|x vector or horizontal velocity\n\t\t * @param {Number} y vertical velocity\n\t\t * @example\n\t\t * sprite.vel = createVector(1, 2);\n\t\t * // OR\n\t\t * sprite.vel.x = 1;\n\t\t * sprite.vel.y = 2;\n\t\t */\n\t\tsetVelocity(x, y) {\n\t\t\tconsole.warn('setVelocity() is deprecated. Set sprite.vel instead.');\n\t\t\tif (typeof x == 'object') {\n\t\t\t\ty = x.y;\n\t\t\t\tx = x.x;\n\t\t\t}\n\t\t\tthis.vel.x = x;\n\t\t\tthis.vel.y = y;\n\t\t}\n\n\t\t/**\n\t\t * Deprecated: set direction and set speed separately\n\t\t *\n\t\t * Sets the speed of the sprite.\n\t\t * The action overwrites the current velocity.\n\t\t * If direction is not supplied, the current direction is maintained.\n\t\t * If direction is not supplied and there is no current velocity, the\n\t\t * current rotation angle used for the direction.\n\t\t *\n\t\t * @deprecated setSpeed\n\t\t * @param {Number} speed Scalar speed\n\t\t * @param {Number} [direction] angle\n\t\t */\n\t\tsetSpeed(speed, direction) {\n\t\t\tconsole.warn('setSpeed is deprecated. Set sprite.direction and sprite.speed separately instead.');\n\t\t\tif (direction) this.direction = direction;\n\t\t\tthis.speed = speed;\n\t\t}\n\n\t\t/**\n\t\t * Add to the speed of the sprite.\n\t\t * If direction is not supplied, the current direction is maintained.\n\t\t * If direction is not supplied and there is no current velocity, the * current rotation angle used for the direction.\n\t\t *\n\t\t * @method addSpeed\n\t\t * @param {Number} speed Scalar speed\n\t\t * @param {Number} [angle] Direction in degrees\n\t\t */\n\t\taddSpeed(speed, angle) {\n\t\t\tangle ??= this.direction;\n\n\t\t\tthis.vel.x += this.p.cos(angle) * speed;\n\t\t\tthis.vel.y += this.p.sin(angle) * speed;\n\t\t}\n\n\t\t/**\n\t\t * Move a sprite towards a position.\n\t\t *\n\t\t * @method moveTowards\n\t\t * @param {Number|Object} x|position destination x or any object with x and y properties\n\t\t * @param {Number} y destination y\n\t\t * @param {Number} tracking [optional] 1 represents 1:1 tracking, the mouse moves to the destination immediately, 0 represents no tracking. Default is 0.1 (10% tracking).\n\t\t */\n\t\tmoveTowards(x, y, tracking) {\n\t\t\tif (typeof x != 'number') {\n\t\t\t\tlet obj = x;\n\t\t\t\tif (obj == this.p.mouse && !this.p.mouse.active) return;\n\t\t\t\tif (obj.x === undefined || obj.y === undefined) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t'sprite.moveTowards/moveAway ERROR: movement destination not defined, object given with no x or y properties'\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttracking = y;\n\t\t\t\ty = obj.y;\n\t\t\t\tx = obj.x;\n\t\t\t}\n\t\t\tif (x === undefined && y === undefined) return;\n\t\t\ttracking ??= 0.1;\n\n\t\t\t// let vec = new pl.Vec2(0, 0);\n\t\t\tif (x !== undefined && x !== null) {\n\t\t\t\t// vec.x = (destX - this.x) * tracking * this.tileSize * this.mass;\n\t\t\t\tthis.vel.x = (x - this.x) * tracking * this.tileSize;\n\t\t\t}\n\t\t\tif (y !== undefined && y !== null) {\n\t\t\t\t// vec.y = (destY - this.y) * tracking * this.tileSize * this.mass;\n\t\t\t\tthis.vel.y = (y - this.y) * tracking * this.tileSize;\n\t\t\t}\n\t\t\t// this.body.applyForce(vec, new pl.Vec2(0, 0));\n\t\t}\n\n\t\t/**\n\t\t * Move a sprite away from a position.\n\t\t *\n\t\t * @method moveAway\n\t\t * @param {Number|Object} x|position x or any object with x and y properties\n\t\t * @param {Number} y\n\t\t * @param {Number} repel [optional] the higher the value, the faster the sprite moves away. Default is 0.1 (10% repel).\n\t\t */\n\t\tmoveAway(x, y, repel) {\n\t\t\tthis.moveTowards(...arguments);\n\t\t\tthis.vel.x *= -1;\n\t\t\tthis.vel.y *= -1;\n\t\t}\n\n\t\t/**\n\t\t * Move the sprite a certain distance from its current position.\n\t\t *\n\t\t * @method move\n\t\t * @param {Number} distance [optional]\n\t\t * @param {Number|String} direction [optional]\n\t\t * @param {Number} speed [optional]\n\t\t * @returns {Promise} resolves when the movement is complete or cancelled\n\t\t *\n\t\t * @example\n\t\t * sprite.move(distance);\n\t\t * sprite.move(distance, direction);\n\t\t * sprite.move(distance, direction, speed);\n\t\t *\n\t\t * sprite.move(directionName);\n\t\t * sprite.move(directionName, speed);\n\t\t * sprite.move(directionName, speed, distance); // deprecated usage\n\t\t */\n\t\tmove(distance, direction, speed) {\n\t\t\tlet dirNameMode = isNaN(arguments[0]);\n\t\t\tif (dirNameMode) {\n\t\t\t\tdirection = arguments[0];\n\t\t\t\tspeed = arguments[1];\n\t\t\t\tdistance = arguments[2];\n\t\t\t\tif (distance !== undefined) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`In p5.play v3.3.0 the parameter ordering for the move() function was changed to: move(distance, direction, speed).`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdirNameMode = isNaN(direction);\n\t\t\t}\n\t\t\tif (direction !== undefined) this.direction = direction;\n\t\t\tdistance ??= 1;\n\t\t\tlet x = this.x + this.p.cos(this.direction) * distance;\n\t\t\tlet y = this.y + this.p.sin(this.direction) * distance;\n\t\t\tif (dirNameMode) {\n\t\t\t\tx = Math.round(x);\n\t\t\t\ty = Math.round(y);\n\t\t\t}\n\t\t\treturn this.moveTo(x, y, speed);\n\t\t}\n\n\t\t/**\n\t\t * Move the sprite to a position.\n\t\t *\n\t\t * @method moveTo\n\t\t * @param {Number|Object} x|position destination x or any object with x and y properties\n\t\t * @param {Number} y destination y\n\t\t * @param {Number} speed [optional]\n\t\t * @returns {Promise} resolves when the movement is complete or cancelled\n\t\t */\n\t\tmoveTo(x, y, speed) {\n\t\t\tif (typeof x == 'undefined') {\n\t\t\t\tconsole.error('sprite.move ERROR: movement direction or destination not defined');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (typeof x != 'number') {\n\t\t\t\tlet obj = x;\n\t\t\t\tif (obj == this.p.mouse && !this.p.mouse.active) return;\n\t\t\t\tif (obj.x === undefined || obj.y === undefined) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t'sprite.moveTo ERROR: movement destination not defined, object given with no x or y properties'\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tspeed = y;\n\t\t\t\ty = obj.y;\n\t\t\t\tx = obj.x;\n\t\t\t}\n\t\t\tthis._dest.x = this.x;\n\t\t\tthis._dest.y = this.y;\n\n\t\t\tlet direction = true;\n\n\t\t\tif (x == this.x) x = false;\n\t\t\telse {\n\t\t\t\tthis._dest.x = x;\n\t\t\t\tx = true;\n\t\t\t}\n\t\t\tif (y == this.y) y = false;\n\t\t\telse {\n\t\t\t\tthis._dest.y = y;\n\t\t\t\ty = true;\n\t\t\t}\n\n\t\t\tthis._destIdx++;\n\t\t\tif (!x && !y) return true;\n\n\t\t\tif (this.speed) speed ??= this.speed;\n\t\t\tif (this.tileSize > 1) speed ??= 0.1;\n\t\t\tspeed ??= 1;\n\t\t\tif (speed <= 0) {\n\t\t\t\tconsole.warn('sprite.move: speed should be a positive number');\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet a = this._dest.y - this.y;\n\t\t\tlet b = this._dest.x - this.x;\n\t\t\tlet c = Math.sqrt(a * a + b * b);\n\n\t\t\tlet percent = speed / c;\n\n\t\t\tthis.vel.x = b * percent;\n\t\t\tthis.vel.y = a * percent;\n\n\t\t\t// estimate how many frames it will take for the sprite\n\t\t\t// to reach its destination\n\t\t\tlet frames = Math.floor(c / speed) - 5;\n\n\t\t\t// margin of error\n\t\t\tlet margin = speed + 0.01;\n\n\t\t\tlet destIdx = this._destIdx;\n\n\t\t\treturn (async () => {\n\t\t\t\tlet distX = margin + margin;\n\t\t\t\tlet distY = margin + margin;\n\t\t\t\tdo {\n\t\t\t\t\tif (destIdx != this._destIdx) return false;\n\n\t\t\t\t\tawait p5.prototype.delay();\n\n\t\t\t\t\t// skip calculations if not close enough to destination yet\n\t\t\t\t\tif (frames > 0) {\n\t\t\t\t\t\tframes--;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// check if the sprite has reached its destination\n\t\t\t\t\tdistX = Math.abs(this.x - this._dest.x);\n\t\t\t\t\tdistY = Math.abs(this.y - this._dest.y);\n\t\t\t\t} while ((x && distX > margin) || (y && distY > margin));\n\t\t\t\t// stop moving the sprite, snap to destination\n\t\t\t\tif (distX < margin) this.x = this._dest.x;\n\t\t\t\tif (distY < margin) this.y = this._dest.y;\n\t\t\t\tthis.vel.x = 0;\n\t\t\t\tthis.vel.y = 0;\n\t\t\t\treturn true;\n\t\t\t})();\n\t\t}\n\n\t\t/**\n\t\t * Pushes the sprite toward a point.\n\t\t * The force is added to the current velocity.\n\t\t *\n\t\t * Legacy method, use moveTo or moveTowards instead.\n\t\t *\n\t\t * @deprecated\n\t\t * @param {Number}  magnitude Scalar speed to add\n\t\t * @param {Number}  x Direction x coordinate\n\t\t * @param {Number}  y Direction y coordinate\n\t\t */\n\t\tattractionPoint(magnitude, x, y) {\n\t\t\tconsole.warn('sprite.attractionPoint is deprecated, use sprite.moveTowards instead');\n\t\t\tlet angle = this.p.atan2(y - this.y, x - this.x);\n\t\t\tthis.vel.x += this.p.cos(angle) * magnitude;\n\t\t\tthis.vel.y += this.p.sin(angle) * magnitude;\n\t\t}\n\n\t\tsnap(o, dist) {\n\t\t\tif (o.isMoving || o.x != o._dest.x || o.y != o._dest.y || !this.isMoving) return;\n\t\t\tdist ??= 1 || this.tileSize * 0.1;\n\t\t\tif (Math.abs(this.x) % 1 >= dist || Math.abs(this.y) % 1 >= dist) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.vel.x = 0;\n\t\t\tthis.vel.y = 0;\n\t\t\tthis.x = Math.round(this.x);\n\t\t\tthis.y = Math.round(this.y);\n\t\t}\n\n\t\t/**\n\t\t * @method rotateTowards\n\t\t * @param {*} x position to rotate towards\n\t\t * @param {*} y position to rotate towards\n\t\t * @param {*} tracking percent of the distance to rotate on each frame towards the target angle, default is 0.1 (10%)\n\t\t * @param {*} facing rotation angle the sprite should be at when \"facing\" the position, default is 0\n\t\t */\n\t\trotateTowards(x, y, tracking, facing) {\n\t\t\tif (typeof x != 'number') {\n\t\t\t\tfacing = tracking;\n\t\t\t\ttracking = y;\n\t\t\t\ty = facing;\n\t\t\t}\n\t\t\tlet angle = this.angleTo(x, y, facing);\n\t\t\ttracking ??= 0.1;\n\t\t\tthis.rotationSpeed = angle * tracking;\n\t\t}\n\n\t\t/**\n\t\t * Finds the minimium amount the sprite would have to rotate to\n\t\t * \"face\" a position at a rotation.\n\t\t *\n\t\t * @method angleTo\n\t\t * @param {Number|Object} x|position\n\t\t * @param {Number} y\n\t\t * @param {Number} facing rotation angle the sprite should be at when \"facing\" the position, default is 0\n\t\t * @returns {Number} minimum angle of rotation to face the position\n\t\t */\n\t\tangleTo(x, y, facing) {\n\t\t\tif (typeof x != 'number') {\n\t\t\t\tlet obj = x;\n\t\t\t\tif (obj == this.p.mouse && !this.p.mouse.active) return 0;\n\t\t\t\tif (obj.x === undefined || obj.y === undefined) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t'sprite.angleTo ERROR: rotation destination not defined, object given with no x or y properties'\n\t\t\t\t\t);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\tfacing = y;\n\t\t\t\ty = obj.y;\n\t\t\t\tx = obj.x;\n\t\t\t}\n\n\t\t\tif (Math.abs(x - this.x) < 0.01 && Math.abs(y - this.y) < 0.01) {\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t\tfacing ??= 0;\n\n\t\t\tlet ang = this.p.atan2(y - this.y, x - this.x) + facing;\n\t\t\tlet dist1 = ang - (this.rotation % 360);\n\t\t\tlet dist2 = 360 - Math.abs(dist1);\n\t\t\tdist2 *= dist1 < 0 ? 1 : -1;\n\t\t\treturn Math.abs(dist1) < Math.abs(dist2) ? dist1 : dist2;\n\t\t}\n\n\t\t/**\n\t\t * Rotates the sprite to a position at a rotation.\n\t\t *\n\t\t * @method rotateTo\n\t\t * @param {Number|Object} x|position\n\t\t * @param {Number} y\n\t\t * @param {Number} speed the amount of rotation per frame, default is 1\n\t\t * @param {Number} facing rotation angle the sprite should be at when \"facing\" the position, default is 0\n\t\t * @returns {Promise} a promise that resolves when the rotation is complete\n\t\t */\n\t\trotateTo(x, y, speed, facing) {\n\t\t\tif (typeof x != 'number') {\n\t\t\t\tfacing = speed;\n\t\t\t\tspeed = y;\n\t\t\t\ty = facing;\n\t\t\t}\n\n\t\t\tlet angle = this.angleTo(x, y, facing);\n\n\t\t\treturn this.rotate(angle, speed);\n\t\t}\n\n\t\t/**\n\t\t * Rotates the sprite by an amount at a specified angles per frame speed.\n\t\t *\n\t\t * @method rotate\n\t\t * @param {Number} angle the amount to rotate the sprite\n\t\t * @param {Number} speed the amount of rotation per frame, default is 1\n\t\t * @returns {Promise} a promise that resolves when the rotation is complete\n\t\t */\n\t\trotate(angle, speed) {\n\t\t\tif (isNaN(angle)) throw new FriendlyError();\n\t\t\tif (angle == 0) return;\n\t\t\tlet absA = Math.abs(angle);\n\t\t\tspeed ??= 1;\n\t\t\tif (speed > absA) speed = absA;\n\n\t\t\tlet ang = this.rotation + angle;\n\t\t\tlet cw = angle > 0;\n\t\t\tthis.rotationSpeed = speed * (cw ? 1 : -1);\n\n\t\t\tlet frames = Math.ceil(absA / speed);\n\t\t\tthis._rotateIdx ??= 0;\n\t\t\tthis._rotateIdx++;\n\t\t\tlet _rotateIdx = this._rotateIdx;\n\n\t\t\treturn (async () => {\n\t\t\t\tif (frames > 1) {\n\t\t\t\t\twhile (frames > 0) {\n\t\t\t\t\t\tif (this._rotateIdx != _rotateIdx) return;\n\t\t\t\t\t\tawait p5.prototype.delay();\n\t\t\t\t\t\tframes--;\n\t\t\t\t\t}\n\n\t\t\t\t\twhile (Math.abs(this.rotationSpeed) < Math.abs(ang - this.rotation)) {\n\t\t\t\t\t\tawait p5.prototype.delay();\n\t\t\t\t\t}\n\t\t\t\t\tif (Math.abs(ang - this.rotation) > 0.01) {\n\t\t\t\t\t\tthis.rotationSpeed = ang - this.rotation;\n\t\t\t\t\t\tawait p5.prototype.delay();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tawait p5.prototype.delay();\n\t\t\t\t}\n\t\t\t\tthis.rotationSpeed = 0;\n\t\t\t\tthis.rotation = ang;\n\t\t\t})();\n\t\t}\n\n\t\t/**\n\t\t * Changes the sprite's animation. Use `addAni` to define the\n\t\t * animation(s) first.\n\t\t *\n\t\t * @method changeAni\n\t\t * @param {...String} anis the names of one or many animations to be played in\n\t\t * sequence\n\t\t * @returns A promise that fulfills when the animation or sequence of animations\n\t\t * completes\n\t\t */\n\t\tasync changeAni(...anis) {\n\t\t\tif (anis.length == 1 && Array.isArray(anis[0])) {\n\t\t\t\tanis = anis[0];\n\t\t\t}\n\n\t\t\tlet _ani = (name, start, end) => {\n\t\t\t\treturn new Promise((resolve) => {\n\t\t\t\t\tthis._changeAni(name);\n\t\t\t\t\tif (start < 0) start = this._animation.length + start;\n\t\t\t\t\tif (start) this._animation.frame = start;\n\n\t\t\t\t\tif (end !== undefined) this._animation.goToFrame(end);\n\t\t\t\t\telse if (this.frame == this.lastFrame) resolve();\n\n\t\t\t\t\tthis._animation.onComplete = () => {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tfor (let i = 0; i < anis.length; i++) {\n\t\t\t\tlet ani = anis[i];\n\t\t\t\tif (\n\t\t\t\t\tani instanceof SpriteAnimation ||\n\t\t\t\t\tani instanceof p5.Image ||\n\t\t\t\t\t(typeof ani == 'string' && ani.length != 1 && ani.includes('.'))\n\t\t\t\t) {\n\t\t\t\t\tanis[i] = this.addAni(ani);\n\t\t\t\t\tani = anis[i];\n\t\t\t\t}\n\t\t\t\tif (typeof ani == 'string') {\n\t\t\t\t\tanis[i] = { name: ani };\n\t\t\t\t\tani = anis[i];\n\t\t\t\t}\n\t\t\t\tif (ani.name[0] == '!') {\n\t\t\t\t\tani.name = ani.name.slice(1);\n\t\t\t\t\tani.start = -1;\n\t\t\t\t\tani.end = 0;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// let count = ++this._aniChanged;\n\n\t\t\tfor (let i = 0; i < anis.length; i++) {\n\t\t\t\tlet ani = anis[i];\n\t\t\t\t// if () { // TODO repeat\n\t\t\t\t// \tif (count == this._aniChanged) i = 0;\n\t\t\t\t// \tcontinue;\n\t\t\t\t// }\n\t\t\t\tlet { name, start, end } = ani;\n\t\t\t\tawait _ani(name, start, end);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Changes the sprite's animation. Use `addAni` to define the\n\t\t * animation(s) first. Alt for `changeAni`.\n\t\t *\n\t\t * @method changeAnimation\n\t\t * @param {...String} anis the names of one or many animations to be played in\n\t\t * sequence\n\t\t * @returns A promise that fulfills when the animation or sequence of animations\n\t\t * completes\n\t\t */\n\t\tchangeAnimation() {\n\t\t\treturn this.changeAni(...arguments);\n\t\t}\n\n\t\t/**\n\t\t * Changes the displayed animation. The animation must be added first\n\t\t * using the sprite.addAnimation method. The animation could also be\n\t\t * added using the group.addAnimation method to a group the sprite\n\t\t * has been added to.\n\t\t *\n\t\t * See SpriteAnimation for more control over the sequence.\n\t\t *\n\t\t * @method changeAnimation\n\t\t * @param {String} label SpriteAnimation identifier\n\t\t */\n\t\t_changeAni(label) {\n\t\t\tlet ani = this.animations[label];\n\t\t\tif (!ani) {\n\t\t\t\tfor (let i = this.groups.length - 1; i >= 0; i--) {\n\t\t\t\t\tlet g = this.groups[i];\n\t\t\t\t\tani = g.animations[label];\n\t\t\t\t\tif (ani) {\n\t\t\t\t\t\tani = ani.clone();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!ani) {\n\t\t\t\tthis.p.noLoop();\n\t\t\t\tthrow new FriendlyError('Sprite.changeAnimation', [label]);\n\t\t\t}\n\t\t\tthis._animation = ani;\n\t\t\tthis.animation.name = label;\n\t\t\t// reset to frame 0 of that animation\n\t\t\tif (this.autoResetAnimations || (this.autoResetAnimations !== false && this.p.world.autoResetAnimations)) {\n\t\t\t\tthis.animation.frame = 0;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Removes the Sprite from the sketch.\n\t\t * The removed Sprite will not be drawn or updated anymore.\n\t\t *\n\t\t * @method remove\n\t\t */\n\t\tremove() {\n\t\t\tif (this.body) this.p.world.destroyBody(this.body);\n\t\t\tthis.body = null;\n\t\t\tthis.removed = true;\n\n\t\t\t//when removed from the \"scene\" also remove all the references in all the groups\n\t\t\twhile (this.groups.length > 0) {\n\t\t\t\tthis.groups[0].remove(this);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Returns the sprite's unique identifier\n\t\t *\n\t\t * @method toString\n\t\t * @returns the sprite's id\n\t\t */\n\t\ttoString() {\n\t\t\treturn 's' + this.idNum;\n\t\t}\n\n\t\t_ensureCollide(target, callback) {\n\t\t\tif (!target) {\n\t\t\t\tthrow new FriendlyError('Sprite.collide', 2);\n\t\t\t}\n\t\t\tif (!(target instanceof Sprite) && !(target instanceof Group)) {\n\t\t\t\tthrow new FriendlyError('Sprite.collide', 0, [target]);\n\t\t\t}\n\t\t\tif (callback && typeof callback != 'function') {\n\t\t\t\tthrow new FriendlyError('Sprite.collide', 1, [callback]);\n\t\t\t}\n\t\t}\n\n\t\tcollide(target, callback) {\n\t\t\treturn this.collides(target, callback);\n\t\t}\n\n\t\t/**\n\t\t * Returns true on the first frame that the sprite collides with the\n\t\t * target sprite or group.\n\t\t *\n\t\t * Custom collision event handling can be done by using this function\n\t\t * in an if statement or adding a callback as the second parameter.\n\t\t *\n\t\t * @method collides\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t */\n\t\tcollides(target, callback) {\n\t\t\tthis._ensureCollide(target, callback);\n\t\t\tthis._collides[target] = callback || true;\n\t\t\treturn this._collisions.get(target) == 1;\n\t\t}\n\n\t\t/**\n\t\t * Returns a truthy value while the sprite is colliding with the\n\t\t * target sprite or group. The value is the number of frames that\n\t\t * the sprite has been colliding with the target.\n\t\t *\n\t\t * @method colliding\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t * @return {Number} frames\n\t\t */\n\t\tcolliding(target, callback) {\n\t\t\tthis._ensureCollide(target, callback);\n\t\t\tthis._colliding[target] = callback || true;\n\t\t\tlet val = this._collisions.get(target);\n\t\t\treturn val > 0 ? val : 0;\n\t\t}\n\n\t\t/**\n\t\t * Returns true on the first frame that the sprite no longer overlaps\n\t\t * with the target sprite or group.\n\t\t *\n\t\t * @method collided\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t * @return {Boolean}\n\t\t */\n\t\tcollided(target, callback) {\n\t\t\tthis._ensureCollide(target, callback);\n\t\t\tthis._collided[target] = callback || true;\n\t\t\treturn this._collisions.get(target) == -1;\n\t\t}\n\n\t\t_ensureOverlap(target, callback) {\n\t\t\tif (!target) {\n\t\t\t\tthrow new FriendlyError('Sprite.overlap', 2);\n\t\t\t}\n\t\t\tif (!(target instanceof Sprite) && !(target instanceof Group)) {\n\t\t\t\tthrow new FriendlyError('Sprite.overlap', 0, [target]);\n\t\t\t}\n\t\t\tif (callback && typeof callback != 'function') {\n\t\t\t\tthrow new FriendlyError('Sprite.overlap', 1, [callback]);\n\t\t\t}\n\t\t\tif (!this._hasOverlaps) this._createSensors();\n\t\t\tif (target instanceof Sprite) {\n\t\t\t\tif (!target._hasOverlaps) target._createSensors();\n\t\t\t} else if (target instanceof Group) {\n\t\t\t\tif (!target._hasOverlaps) {\n\t\t\t\t\tfor (let s of target) {\n\t\t\t\t\t\tif (!s._hasOverlaps) s._createSensors();\n\t\t\t\t\t}\n\t\t\t\t\ttarget._hasOverlaps = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._overlap[target] = true;\n\t\t}\n\n\t\toverlap(target, callback) {\n\t\t\treturn this.overlaps(target, callback);\n\t\t}\n\n\t\t/**\n\t\t * Returns true on the first frame that the sprite overlaps with the\n\t\t * target sprite or group.\n\t\t *\n\t\t * Custom overlap event handling can be done by using this function\n\t\t * in an if statement or adding a callback as the second parameter.\n\t\t *\n\t\t * @method overlaps\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t */\n\t\toverlaps(target, callback) {\n\t\t\tthis._ensureOverlap(target, callback);\n\t\t\tthis._overlaps[target] = callback || true;\n\t\t\treturn this._overlappers.get(target) == 1;\n\t\t}\n\n\t\t/**\n\t\t * Returns a truthy value while the sprite is overlapping with the\n\t\t * target sprite or group. The value returned is the number of\n\t\t * frames the sprite has been overlapping with the target.\n\t\t *\n\t\t * @method overlapping\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t * @return {Number} frames\n\t\t */\n\t\toverlapping(target, callback) {\n\t\t\tthis._ensureOverlap(target, callback);\n\t\t\tthis._overlapping[target] = callback || true;\n\t\t\tlet val = this._overlappers.get(target);\n\t\t\treturn val > 0 ? val : 0;\n\t\t}\n\n\t\t/**\n\t\t * Returns true on the first frame that the sprite no longer overlaps\n\t\t * with the target sprite or group.\n\t\t *\n\t\t * @method overlapped\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t * @return {Boolean}\n\t\t */\n\t\toverlapped(target, callback) {\n\t\t\tthis._ensureOverlap(target, callback);\n\t\t\tthis._overlapped[target] = callback || true;\n\t\t\treturn this._overlappers.get(target) == -1;\n\t\t}\n\n\t\t_createSensors() {\n\t\t\tlet shape;\n\t\t\tfor (let fxt = this.fixtureList; fxt; fxt = fxt.getNext()) {\n\t\t\t\tshape = fxt.m_shape;\n\t\t\t\tthis.body.createFixture({\n\t\t\t\t\tshape: shape,\n\t\t\t\t\tisSensor: true\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis._hasOverlaps = true;\n\t\t}\n\n\t\t/**\n\t\t * Use sprite.animation.name instead.\n\t\t *\n\t\t * @deprecated getAnimationLabel\n\t\t * @returns the name of the sprite's current animation\n\t\t */\n\t\tgetAnimationLabel() {\n\t\t\tconsole.warn('sprite.getAnimationLabel is deprecated. Use sprite.animation.name instead.');\n\t\t\treturn this.animation.name;\n\t\t}\n\t}\n\n\tthis.Turtle = function (size) {\n\t\tif (pInst.allSprites.tileSize > 1) {\n\t\t\tthrow new Error(`Turtle can't be used when allSprites.tileSize is greater than 1.`);\n\t\t}\n\t\tsize ??= 25;\n\t\tlet t = new Sprite(size, size, [\n\t\t\t[size, size * 0.4],\n\t\t\t[-size, size * 0.4],\n\t\t\t[0, -size * 0.8]\n\t\t]);\n\t\tt.color = 'green';\n\t\tt._isTurtleSprite = true;\n\t\tt._prevPos = { x: t.x, y: t.y };\n\t\tlet _move = t.move;\n\t\tt.move = async function () {\n\t\t\tthis._prevPos.x = this.x;\n\t\t\tthis._prevPos.y = this.y;\n\t\t\tawait _move.call(this, ...arguments);\n\t\t};\n\t\treturn t;\n\t};\n\n\t/**\n\t * Look at the Animation reference pages before reading these docs.\n\t *\n\t * https://p5play.org/learn/sprite_animation.html\n\t *\n\t * A SpriteAnimation object contains a series of images (p5.Image objects)\n\t * that can be displayed sequentially.\n\t *\n\t * A sprite can have multiple labeled animations, see Sprite.addAnimation\n\t * and Sprite.changeAnimation, but you can also create animations that\n\t * can be used without being added to a sprite first.\n\t *\n\t * An animation can be created either from a list of images or sequentially\n\t * numbered images. p5.play will try to detect the sequence pattern.\n\t *\n\t * For example if the image file path is \"image1.png\" and the last frame\n\t * index is 3 then \"image2.png\" and \"image3.png\" will be loaded as well.\n\t *\n\t * @example\n\t *\n\t * let shapeShifter = new SpriteAnimation(\"dog.png\", \"cat.png\", \"snake.png\");\n\t * let walking = new SpriteAnimation(\"walking0001.png\", 5);\n\t *\n\t * @class SpriteAnimation\n\t * @constructor\n\t */\n\tclass SpriteAnimation extends Array {\n\t\tconstructor() {\n\t\t\tsuper();\n\t\t\tthis.p = pInst;\n\t\t\tlet args = [...arguments];\n\n\t\t\t/**\n\t\t\t * The name of the animation\n\t\t\t *\n\t\t\t * @property name\n\t\t\t * @type {String}\n\t\t\t */\n\t\t\tthis.name = 'default';\n\n\t\t\tlet parent;\n\n\t\t\tif (args[0] instanceof Sprite || args[0] instanceof Group) {\n\t\t\t\tparent = args[0];\n\t\t\t\targs = args.slice(1);\n\t\t\t}\n\t\t\tparent ??= this.p.allSprites;\n\n\t\t\tif (typeof args[0] == 'string' && (args[0].length == 1 || !args[0].includes('.'))) {\n\t\t\t\tthis.name = args[0];\n\t\t\t\targs = args.slice(1);\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * The index of the current frame that the animation is on.\n\t\t\t *\n\t\t\t * @property frame\n\t\t\t * @type {Number}\n\t\t\t */\n\t\t\tthis.frame = 0;\n\n\t\t\tthis.cycles = 0;\n\n\t\t\tthis.targetFrame = -1;\n\n\t\t\t/**\n\t\t\t * The offset is how far the animation should be placed from\n\t\t\t * the location it is played at.\n\t\t\t *\n\t\t\t * @property offset\n\t\t\t * @type {Object} x and y keys\n\t\t\t *\n\t\t\t * @example\n\t\t\t * offset.x = 16;\n\t\t\t */\n\t\t\tthis.offset = { x: 0, y: 0 };\n\n\t\t\tthis._frameDelay = 4;\n\n\t\t\t/**\n\t\t\t * True if the animation is currently playing.\n\t\t\t *\n\t\t\t * @property playing\n\t\t\t * @type {Boolean}\n\t\t\t * @default true\n\t\t\t */\n\t\t\tthis.playing = true;\n\n\t\t\t/**\n\t\t\t * Animation visibility.\n\t\t\t *\n\t\t\t * @property visible\n\t\t\t * @type {Boolean}\n\t\t\t * @default true\n\t\t\t */\n\t\t\tthis.visible = true;\n\n\t\t\t/**\n\t\t\t * If set to false the animation will stop after reaching the last frame\n\t\t\t *\n\t\t\t * @property looping\n\t\t\t * @type {Boolean}\n\t\t\t * @default true\n\t\t\t */\n\t\t\tthis.looping = true;\n\n\t\t\t/**\n\t\t\t * Ends the loop on frame 0 instead of the last frame.\n\t\t\t * This is useful for animations that are symmetric.\n\t\t\t * For example a walking cycle where the first frame is the\n\t\t\t * same as the last frame.\n\t\t\t *\n\t\t\t * @property endOnFirstFrame\n\t\t\t * @type {Boolean}\n\t\t\t * @default false\n\t\t\t */\n\t\t\tthis.endOnFirstFrame = false;\n\n\t\t\t/**\n\t\t\t * True if frame changed during the last draw cycle\n\t\t\t *\n\t\t\t * @property frameChanged\n\t\t\t * @type {Boolean}\n\t\t\t */\n\t\t\tthis.frameChanged = false;\n\n\t\t\tthis.rotation = 0;\n\t\t\tthis._scale = new Scale();\n\n\t\t\tif (args.length == 0 || typeof args[0] == 'number') return;\n\n\t\t\tparent.addAni(this);\n\n\t\t\t// sequence mode\n\t\t\tif (\n\t\t\t\targs.length == 2 &&\n\t\t\t\ttypeof args[0] == 'string' &&\n\t\t\t\t(typeof args[1] == 'string' || typeof args[1] == 'number')\n\t\t\t) {\n\t\t\t\tlet from = args[0];\n\t\t\t\tlet to, num2;\n\t\t\t\tif (!isNaN(args[1])) num2 = Number(args[1]);\n\t\t\t\telse to = args[1];\n\n\t\t\t\t// print(\"sequence mode \"+from+\" -> \"+to);\n\n\t\t\t\t// make sure the extensions are fine\n\t\t\t\tif (from.slice(-4) != '.png' || (to && to.slice(-4) != '.png')) {\n\t\t\t\t\tthrow new FriendlyError('SpriteAnimation', 0, [from]);\n\t\t\t\t}\n\n\t\t\t\tlet digits1 = 0;\n\t\t\t\tlet digits2 = 0;\n\n\t\t\t\t// skip extension work backwards to find the numbers\n\t\t\t\tfor (let i = from.length - 5; i >= 0; i--) {\n\t\t\t\t\tif (!isNaN(from.charAt(i))) digits1++;\n\t\t\t\t\telse break;\n\t\t\t\t}\n\n\t\t\t\tif (to) {\n\t\t\t\t\tfor (let i = to.length - 5; i >= 0; i--) {\n\t\t\t\t\t\tif (!isNaN(to.charAt(i))) digits2++;\n\t\t\t\t\t\telse break;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlet prefix1 = from.slice(0, -4 - digits1);\n\t\t\t\tlet prefix2;\n\t\t\t\tif (to) prefix2 = to.slice(0, -4 - digits2);\n\n\t\t\t\t// images don't belong to the same sequence\n\t\t\t\t// they are just two separate images with numbers\n\t\t\t\tif (to && prefix1 != prefix2) {\n\t\t\t\t\tthis.push(this.p.loadImage(from));\n\t\t\t\t\tthis.push(this.p.loadImage(to));\n\t\t\t\t} else {\n\t\t\t\t\t// Our numbers likely have leading zeroes, which means that some\n\t\t\t\t\t// browsers (e.g., PhantomJS) will interpret them as base 8 (octal)\n\t\t\t\t\t// instead of decimal. To fix this, we'll explicity tell parseInt to\n\t\t\t\t\t// use a base of 10 (decimal). For more details on this issue, see\n\t\t\t\t\t// http://stackoverflow.com/a/8763427/2422398.\n\t\t\t\t\tlet num1 = parseInt(from.slice(-4 - digits1, -4), 10);\n\t\t\t\t\tnum2 ??= parseInt(to.slice(-4 - digits2, -4), 10);\n\n\t\t\t\t\t// swap if inverted\n\t\t\t\t\tif (num2 < num1) {\n\t\t\t\t\t\tlet t = num2;\n\t\t\t\t\t\tnum2 = num1;\n\t\t\t\t\t\tnum1 = t;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet fileName;\n\t\t\t\t\tif (!to || digits1 == digits2) {\n\t\t\t\t\t\t// load all images\n\t\t\t\t\t\tfor (let i = num1; i <= num2; i++) {\n\t\t\t\t\t\t\t// Use nf() to number format 'i' into the amount of digits\n\t\t\t\t\t\t\t// ex: 14 with 4 digits is 0014\n\t\t\t\t\t\t\tfileName = prefix1 + this.p.nf(i, digits1) + '.png';\n\t\t\t\t\t\t\tthis.push(this.p.loadImage(fileName));\n\t\t\t\t\t\t}\n\t\t\t\t\t} // case: case img1, img2\n\t\t\t\t\telse {\n\t\t\t\t\t\tfor (let i = num1; i <= num2; i++) {\n\t\t\t\t\t\t\t// Use nf() to number format 'i' into four digits\n\t\t\t\t\t\t\tfileName = prefix1 + i + '.png';\n\t\t\t\t\t\t\tthis.push(this.p.loadImage(fileName));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} // end sequence mode\n\n\t\t\t// SpriteSheet mode\n\t\t\telse if (typeof args[args.length - 1] != 'string' && !(args[args.length - 1] instanceof p5.Image)) {\n\t\t\t\tlet sheet = parent.spriteSheet;\n\t\t\t\tlet atlas;\n\t\t\t\tif (args[0] instanceof p5.Image || typeof args[0] == 'string') {\n\t\t\t\t\tif (args.length >= 3) {\n\t\t\t\t\t\tthrow new FriendlyError('SpriteAnimation', 1);\n\t\t\t\t\t}\n\t\t\t\t\tsheet = args[0];\n\t\t\t\t\tatlas = args[1];\n\t\t\t\t} else {\n\t\t\t\t\tatlas = args[0];\n\t\t\t\t}\n\n\t\t\t\tlet _this = this;\n\n\t\t\t\tif (sheet instanceof p5.Image && sheet.width != 1 && sheet.height != 1) {\n\t\t\t\t\tthis.spriteSheet = sheet;\n\t\t\t\t\t_generateSheetFrames();\n\t\t\t\t} else {\n\t\t\t\t\tlet url;\n\t\t\t\t\tif (typeof sheet == 'string') url = sheet;\n\t\t\t\t\telse url = sheet.url;\n\t\t\t\t\tthis.spriteSheet = this.p.loadImage(url, () => {\n\t\t\t\t\t\t_generateSheetFrames();\n\t\t\t\t\t});\n\t\t\t\t\t// parent.spriteSheet = this.spriteSheet;\n\t\t\t\t}\n\n\t\t\t\tfunction _generateSheetFrames() {\n\t\t\t\t\tif (Array.isArray(atlas) || Array.isArray(atlas.frames)) {\n\t\t\t\t\t\tif (typeof atlas[0] == 'number') {\n\t\t\t\t\t\t\tif (atlas.length == 4) {\n\t\t\t\t\t\t\t\tatlas = { pos: atlas.slice(0, 2), size: atlas.slice(2) };\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tatlas = { pos: atlas };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tlet frames = atlas;\n\t\t\t\t\t\t\tif (Array.isArray(atlas.frames)) {\n\t\t\t\t\t\t\t\tframes = atlas.frames;\n\t\t\t\t\t\t\t\tdelete atlas.frames;\n\t\t\t\t\t\t\t\tfor (let i = 0; i < frames.length; i++) {\n\t\t\t\t\t\t\t\t\tframes[i] = {\n\t\t\t\t\t\t\t\t\t\tpos: frames[i]\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\tObject.assign(frames[i], atlas);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfor (let frame of frames) {\n\t\t\t\t\t\t\t\tatlas = frame;\n\t\t\t\t\t\t\t\t_generateSheetFrames();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlet { w, h, width, height, frameSize, size, pos, line, x, y, frames, delay, rotation } = atlas;\n\t\t\t\t\tsize ??= frameSize;\n\t\t\t\t\tif (delay) _this.frameDelay = delay;\n\t\t\t\t\tif (rotation) _this.rotation = rotation;\n\n\t\t\t\t\tw ??= width;\n\t\t\t\t\th ??= height;\n\n\t\t\t\t\tlet tileSize;\n\t\t\t\t\tif (parent) {\n\t\t\t\t\t\tw ??= parent.w;\n\t\t\t\t\t\th ??= parent.h;\n\t\t\t\t\t\ttileSize = parent.tileSize;\n\t\t\t\t\t}\n\n\t\t\t\t\tx ??= 0;\n\t\t\t\t\ty ??= 0;\n\t\t\t\t\tpos ??= line;\n\t\t\t\t\t// if pos is a number or only y is defined but not x\n\t\t\t\t\t// the animation's first frame is at x = 0\n\t\t\t\t\t// the line number is the location of the animation line\n\t\t\t\t\t// given as a distance from the top of the image\n\t\t\t\t\tif (typeof pos == 'number') {\n\t\t\t\t\t\ty = pos;\n\t\t\t\t\t} else if (pos) {\n\t\t\t\t\t\t// pos is the location of the animation line\n\t\t\t\t\t\t// given as a [row,column] coordinate pair of distances in tiles\n\t\t\t\t\t\t// from the top left corner of the image\n\t\t\t\t\t\tx = pos[0]; // column\n\t\t\t\t\t\ty = pos[1]; // row\n\t\t\t\t\t}\n\n\t\t\t\t\tif (typeof size == 'number') {\n\t\t\t\t\t\tw = h = size;\n\t\t\t\t\t} else if (size) {\n\t\t\t\t\t\tw = size[0];\n\t\t\t\t\t\th = size[1];\n\t\t\t\t\t}\n\n\t\t\t\t\t// get the real dimensions and position of the frame\n\t\t\t\t\t// in the sheet\n\t\t\t\t\tx *= tileSize;\n\t\t\t\t\ty *= tileSize;\n\n\t\t\t\t\tif (!w || !h) {\n\t\t\t\t\t\tif (tileSize) {\n\t\t\t\t\t\t\tw = h = 1 * tileSize;\n\t\t\t\t\t\t} else if (_this.spriteSheet.width < _this.spriteSheet.height) {\n\t\t\t\t\t\t\tw = h = _this.spriteSheet.width;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tw = h = _this.spriteSheet.height;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tw *= tileSize;\n\t\t\t\t\t\th *= tileSize;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet frameCount = frames || 1;\n\n\t\t\t\t\t// add all the frames in the animation to the frames array\n\t\t\t\t\tfor (let i = 0; i < frameCount; i++) {\n\t\t\t\t\t\t_this.push({ x, y, w, h });\n\t\t\t\t\t\tx += w;\n\t\t\t\t\t\tif (x >= _this.spriteSheet.width) {\n\t\t\t\t\t\t\tx = 0;\n\t\t\t\t\t\t\ty += h;\n\t\t\t\t\t\t\tif (y >= _this.spriteSheet.height) y = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} // end SpriteSheet mode\n\t\t\telse {\n\t\t\t\t// list of images\n\t\t\t\tfor (let i = 0; i < args.length; i++) {\n\t\t\t\t\tif (args[i] instanceof p5.Image) this.push(args[i]);\n\t\t\t\t\telse this.push(this.p.loadImage(args[i]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Delay between frames in number of draw cycles.\n\t\t * If set to 4 the framerate of the animation would be the\n\t\t * sketch framerate divided by 4 (60fps = 15fps)\n\t\t *\n\t\t * @property frameDelay\n\t\t * @type {Number}\n\t\t * @default 4\n\t\t */\n\t\tget frameDelay() {\n\t\t\treturn this._frameDelay;\n\t\t}\n\t\tset frameDelay(val) {\n\t\t\tif (val <= 0) val = 1;\n\t\t\tthis._frameDelay = val;\n\t\t}\n\t\t/**\n\t\t * TODO frameRate\n\t\t * Another way to set the animation's frame delay.\n\t\t */\n\t\t// get frameRate() {\n\n\t\t// }\n\t\t// set frameRate(val) {\n\n\t\t// }\n\n\t\t/**\n\t\t * The animation's scale.\n\t\t *\n\t\t * Can be set to a number to scale both x and y\n\t\t * or an object with x and/or y properties.\n\t\t *\n\t\t * @property scale\n\t\t * @type {Number|Object}\n\t\t * @default 1\n\t\t */\n\t\tget scale() {\n\t\t\treturn this._scale;\n\t\t}\n\t\tset scale(val) {\n\t\t\tif (typeof val == 'number') {\n\t\t\t\tval = { x: val, y: val };\n\t\t\t}\n\t\t\tthis._scale._x = val.x;\n\t\t\tthis._scale._y = val.y;\n\t\t\tthis._scale._avg = val.x;\n\t\t}\n\n\t\t/**\n\t\t * Make a copy of the animation.\n\t\t *\n\t\t * @method clone\n\t\t * @return {SpriteAnimation} A copy of the animation.\n\t\t */\n\t\tclone() {\n\t\t\tlet ani = new SpriteAnimation();\n\t\t\tani.spriteSheet = this.spriteSheet;\n\t\t\tfor (let i = 0; i < this.length; i++) {\n\t\t\t\tani.push(this[i]);\n\t\t\t}\n\t\t\tani.offset.x = this.offset.x;\n\t\t\tani.offset.y = this.offset.y;\n\t\t\tani.frameDelay = this.frameDelay;\n\t\t\tani.playing = this.playing;\n\t\t\tani.looping = this.looping;\n\t\t\tani.rotation = this.rotation;\n\t\t\treturn ani;\n\t\t}\n\n\t\t/**\n\t\t * Draws the animation at coordinate x and y.\n\t\t * Updates the frames automatically.\n\t\t *\n\t\t * Optional parameters effect the current draw cycle only and\n\t\t * are not saved between draw cycles.\n\t\t *\n\t\t * @method draw\n\t\t * @param {Number} x horizontal position\n\t\t * @param {Number} y vertical position\n\t\t * @param {Number} [r] rotation\n\t\t * @param {Number} [sx] scale x\n\t\t * @param {Number} [sy] scale y\n\t\t */\n\t\tdraw(x, y, r, sx, sy) {\n\t\t\tthis.x = x || 0;\n\t\t\tthis.y = y || 0;\n\n\t\t\tif (!this.visible) return;\n\n\t\t\tsx ??= 1;\n\t\t\tsy ??= 1;\n\n\t\t\tthis.p.push();\n\t\t\tthis.p.imageMode(p5.prototype.CENTER);\n\t\t\tthis.p.translate(this.x, this.y);\n\t\t\tthis.p.rotate(r || this.rotation);\n\t\t\tthis.p.scale(sx * this._scale.x, sy * this._scale.y);\n\t\t\tlet img = this[this.frame];\n\t\t\tif (img !== undefined) {\n\t\t\t\tif (this.spriteSheet) {\n\t\t\t\t\tlet { x, y, w, h } = img; // image info\n\t\t\t\t\tthis.p.image(this.spriteSheet, this.offset.x, this.offset.y, w, h, x, y, w, h);\n\t\t\t\t} else {\n\t\t\t\t\tthis.p.image(img, this.offset.x, this.offset.y);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlog(\n\t\t\t\t\t'Warning: ' +\n\t\t\t\t\t\tthis.name +\n\t\t\t\t\t\t' animation not loaded yet or frame ' +\n\t\t\t\t\t\tthis.frame +\n\t\t\t\t\t\t' does not exist. Load this animation in the p5.js preload function if you need to use it at the start of your program.'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.p.pop();\n\t\t}\n\n\t\tupdate() {\n\t\t\tthis.cycles++;\n\t\t\tvar previousFrame = this.frame;\n\t\t\tthis.frameChanged = false;\n\n\t\t\t//go to frame\n\t\t\tif (this.length === 1) {\n\t\t\t\tthis.playing = false;\n\t\t\t\tthis.frame = 0;\n\t\t\t}\n\n\t\t\tif (this.playing && this.cycles % this.frameDelay === 0) {\n\t\t\t\tthis.frameChanged = true;\n\n\t\t\t\tif ((this.targetFrame == -1 && this.frame == this.lastFrame) || this.frame == this.targetFrame) {\n\t\t\t\t\tif (this.endOnFirstFrame) this.frame = 0;\n\t\t\t\t\tif (this.looping) this.targetFrame = -1;\n\t\t\t\t\telse this.playing = false;\n\t\t\t\t\tthis.onComplete(); //fire when on last frame\n\t\t\t\t\tif (!this.looping) return;\n\t\t\t\t}\n\n\t\t\t\t//going to target frame up\n\t\t\t\tif (this.targetFrame > this.frame && this.targetFrame !== -1) {\n\t\t\t\t\tthis.frame++;\n\t\t\t\t}\n\t\t\t\t//going to target frame down\n\t\t\t\telse if (this.targetFrame < this.frame && this.targetFrame !== -1) {\n\t\t\t\t\tthis.frame--;\n\t\t\t\t} else if (this.targetFrame === this.frame && this.targetFrame !== -1) {\n\t\t\t\t\tthis.playing = false;\n\t\t\t\t} else if (this.looping) {\n\t\t\t\t\t//advance frame\n\t\t\t\t\t//if next frame is too high\n\t\t\t\t\tif (this.frame >= this.lastFrame) {\n\t\t\t\t\t\tthis.frame = 0;\n\t\t\t\t\t} else this.frame++;\n\t\t\t\t} else {\n\t\t\t\t\t//if next frame is too high\n\t\t\t\t\tif (this.frame < this.lastFrame) this.frame++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Plays the animation, starting from the specified frame.\n\t\t *\n\t\t * @method play\n\t\t * @returns [Promise] a promise that resolves when the animation completes\n\t\t */\n\t\tplay(frame) {\n\t\t\tthis.playing = true;\n\t\t\tif (frame !== undefined) this.frame = frame;\n\t\t\tthis.targetFrame = -1;\n\t\t\treturn new Promise((resolve) => {\n\t\t\t\tthis.onComplete = () => {\n\t\t\t\t\tresolve();\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Pauses the animation.\n\t\t *\n\t\t * @method pause\n\t\t */\n\t\tpause(frame) {\n\t\t\tthis.playing = false;\n\t\t\tif (frame) this.frame = frame;\n\t\t}\n\n\t\t/**\n\t\t * Stops the animation. Alt for pause.\n\t\t *\n\t\t * @method stop\n\t\t */\n\t\tstop(frame) {\n\t\t\tthis.playing = false;\n\t\t\tif (frame) this.frame = frame;\n\t\t}\n\n\t\t/**\n\t\t * Plays the animation backwards.\n\t\t * Equivalent to ani.goToFrame(0)\n\t\t *\n\t\t * @method rewind\n\t\t * @returns [Promise] a promise that resolves when the animation completes\n\t\t * rewinding\n\t\t */\n\t\trewind() {\n\t\t\tthis.looping = false;\n\t\t\treturn this.goToFrame(0);\n\t\t}\n\n\t\t/**\n\t\t * Plays the animation forwards and loops it.\n\t\t *\n\t\t * @method loop\n\t\t */\n\t\tloop() {\n\t\t\tthis.looping = true;\n\t\t\tthis.playing = true;\n\t\t}\n\n\t\t/**\n\t\t * Prevents the animation from looping\n\t\t *\n\t\t * @method noLoop\n\t\t */\n\t\tnoLoop() {\n\t\t\tthis.looping = false;\n\t\t}\n\n\t\t/**\n\t\t * fire when animation ends\n\t\t *\n\t\t * @method onComplete\n\t\t * @return {SpriteAnimation}\n\t\t */\n\t\tonComplete() {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t/**\n\t\t * Deprecated, change the frame property directly.\n\t\t *\n\t\t * Changes the current frame.\n\t\t *\n\t\t * @deprecated\n\t\t * @param {Number} frame Frame number (starts from 0).\n\t\t */\n\t\tchangeFrame(f) {\n\t\t\tconsole.warn('Deprecated, change the ani.frame property directly.');\n\t\t\tif (f < this.length) this.frame = f;\n\t\t\telse this.frame = this.length - 1;\n\n\t\t\tthis.targetFrame = -1;\n\t\t\t//this.playing = false;\n\t\t}\n\n\t\t/**\n\t\t * Goes to the next frame and stops.\n\t\t *\n\t\t * @method nextFrame\n\t\t */\n\t\tnextFrame() {\n\t\t\tif (this.frame < this.length - 1) this.frame = this.frame + 1;\n\t\t\telse if (this.looping) this.frame = 0;\n\n\t\t\tthis.targetFrame = -1;\n\t\t\tthis.playing = false;\n\t\t}\n\n\t\t/**\n\t\t * Goes to the previous frame and stops.\n\t\t *\n\t\t * @method previousFrame\n\t\t */\n\t\tpreviousFrame() {\n\t\t\tif (this.frame > 0) this.frame = this.frame - 1;\n\t\t\telse if (this.looping) this.frame = this.length - 1;\n\n\t\t\tthis.targetFrame = -1;\n\t\t\tthis.playing = false;\n\t\t}\n\n\t\t/**\n\t\t * Plays the animation forward or backward toward a target frame.\n\t\t *\n\t\t * @method goToFrame\n\t\t * @param {Number} toFrame Frame number destination (starts from 0)\n\t\t * @returns [Promise] a promise that resolves when the animation completes\n\t\t */\n\t\tgoToFrame(toFrame) {\n\t\t\tif (toFrame < 0 || toFrame >= this.length) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// targetFrame gets used by the update() method to decide what frame to\n\t\t\t// select next.  When it's not being used it gets set to -1.\n\t\t\tthis.targetFrame = toFrame;\n\n\t\t\tif (this.targetFrame !== this.frame) {\n\t\t\t\tthis.playing = true;\n\t\t\t}\n\t\t\treturn new Promise((resolve) => {\n\t\t\t\tthis.onComplete = () => {\n\t\t\t\t\tresolve();\n\t\t\t\t};\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Use .frame instead.\n\t\t *\n\t\t * Returns the current frame number.\n\t\t *\n\t\t * @deprecated\n\t\t * @return {Number} Current frame (starts from 0)\n\t\t */\n\t\tgetFrame() {\n\t\t\tconsole.warn('Deprecated, use ani.frame instead.');\n\t\t\treturn this.frame;\n\t\t}\n\n\t\t/**\n\t\t * Use .lastFrame instead.\n\t\t *\n\t\t * Returns the last frame number.\n\t\t *\n\t\t * @deprecated\n\t\t * @return {Number} Last frame number (starts from 0)\n\t\t */\n\t\tgetLastFrame() {\n\t\t\tconsole.warn('Deprecated, use ani.lastFrame instead.');\n\t\t\treturn this.lastFrame;\n\t\t}\n\n\t\t/**\n\t\t * Returns the index of the last frame.\n\t\t *\n\t\t * @property lastFrame\n\t\t * @type {Number}\n\t\t * @readonly\n\t\t */\n\t\tget lastFrame() {\n\t\t\treturn this.length - 1;\n\t\t}\n\n\t\t/**\n\t\t * Returns the current frame as p5.Image.\n\t\t *\n\t\t * @method frameImage\n\t\t * @return {p5.Image} Current frame image\n\t\t * @readonly\n\t\t */\n\t\tget frameImage() {\n\t\t\tlet f = this.frame;\n\t\t\tlet img = this[f];\n\t\t\tif (img instanceof p5.Image) return img;\n\n\t\t\tlet { x, y, w, h } = img; // image info\n\t\t\tlet g = createGraphics(w, h);\n\t\t\tg.image(this.spriteSheet, this.offset.x, this.offset.y, w, h, x, y, w, h);\n\t\t\treturn g;\n\t\t}\n\n\t\t/**\n\t\t * Width of the animation.\n\t\t *\n\t\t * @property w\n\t\t * @type {Number}\n\t\t */\n\t\tget w() {\n\t\t\treturn this.width;\n\t\t}\n\t\t/**\n\t\t * Width of the animation.\n\t\t *\n\t\t * @property width\n\t\t * @type {Number}\n\t\t */\n\t\tget width() {\n\t\t\tif (this[this.frame] instanceof p5.Image) {\n\t\t\t\treturn this[this.frame].width;\n\t\t\t} else if (this[this.frame]) {\n\t\t\t\treturn this[this.frame].w;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\n\t\t/**\n\t\t * Height of the animation.\n\t\t *\n\t\t * @property h\n\t\t * @type {Number}\n\t\t */\n\t\tget h() {\n\t\t\treturn this.height;\n\t\t}\n\t\t/**\n\t\t * Height of the animation.\n\t\t *\n\t\t * @property height\n\t\t * @type {Number}\n\t\t */\n\t\tget height() {\n\t\t\tif (this[this.frame] instanceof p5.Image) {\n\t\t\t\treturn this[this.frame].height;\n\t\t\t} else if (this[this.frame]) {\n\t\t\t\treturn this[this.frame].h;\n\t\t\t}\n\t\t\treturn 1;\n\t\t}\n\n\t\t/**\n\t\t * The frames of the animation.\n\t\t *\n\t\t * @property frames\n\t\t * @type {Array}\n\t\t */\n\t\tget frames() {\n\t\t\tlet frames = [];\n\t\t\tfor (let i = 0; i < this.length; i++) {\n\t\t\t\tframes.push(this[i]);\n\t\t\t}\n\t\t\treturn frames;\n\t\t}\n\n\t\t/**\n\t\t * The frames of the animation. Alt for ani.frames\n\t\t *\n\t\t * @property images\n\t\t * @type {Array}\n\t\t */\n\t\tget images() {\n\t\t\treturn this.frames;\n\t\t}\n\t}\n\n\t/**\n\t * Look at the Group reference pages before reading these docs.\n\t *\n\t * https://p5play.org/learn/group.html\n\t *\n\t * In p5.play groups are collections of sprites with similar behavior.\n\t * For example a group may contain all the coin sprites that the\n\t * player can collect.\n\t *\n\t * Group extends Array. You can use them in for loops just like arrays\n\t * since they inherit all the functions and properties of standard\n\t * arrays such as group.length\n\t *\n\t * Since groups just contain references to sprites, a sprite can be in\n\t * multiple groups.\n\t *\n\t * sprite.remove() removes the sprite from all the groups\n\t * it belongs to. group.removeAll() removes all the sprites from\n\t * a group.\n\t *\n\t * The top level group is a p5 instance level variable named\n\t * 'allSprites' that contains all the sprites added to the sketch.\n\t *\n\t * @class Group\n\t * @constructor\n\t */\n\tclass Group extends Array {\n\t\tconstructor(...args) {\n\t\t\tlet parent;\n\t\t\tif (args[0] instanceof Group) {\n\t\t\t\tparent = args[0];\n\t\t\t\targs = args.slice(1);\n\t\t\t}\n\t\t\tsuper(...args);\n\t\t\tthis.idNum = 0;\n\t\t\tthis.p = pInst;\n\n\t\t\t// if all sprites doesn't exist yet,\n\t\t\t// this group is the allSprites group\n\t\t\tif (!this.p.allSprites) this._isAllSpritesGroup = true;\n\n\t\t\tif (!this._isAllSpritesGroup) this.parent = 0;\n\t\t\tif (parent) this.parent = parent.idNum;\n\n\t\t\t/**\n\t\t\t * Keys are the animation label, values are SpriteAnimation objects.\n\t\t\t *\n\t\t\t * @property animations\n\t\t\t * @type {Object}\n\t\t\t */\n\t\t\tthis.animations = {};\n\n\t\t\t/**\n\t\t\t * Contains all the collision callback functions for this group\n\t\t\t * when it comes in contact with other sprites or groups.\n\t\t\t */\n\t\t\tthis._collides = {};\n\t\t\tthis._colliding = {};\n\t\t\tthis._collided = {};\n\n\t\t\tthis._overlap = {};\n\t\t\t/**\n\t\t\t * Contains all the overlap callback functions for this group\n\t\t\t * when it comes in contact with other sprites or groups.\n\t\t\t */\n\t\t\tthis._overlaps = {};\n\t\t\tthis._overlapping = {};\n\t\t\tthis._overlapped = {};\n\n\t\t\tthis._collisions = new Map();\n\t\t\tthis._overlappers = new Map();\n\n\t\t\t// mainly for internal use\n\t\t\t// autoCull as a property of allSprites only refers to the default allSprites cull\n\t\t\t// in the post draw function, if the user calls cull on allSprites it should work\n\t\t\t// for any other group made by users autoCull affects whether cull removes sprites or not\n\t\t\t// by default for allSprites it is set to true, for all other groups it is undefined\n\t\t\tthis.autoCull;\n\n\t\t\tif (this.p.world) {\n\t\t\t\tthis.idNum = this.p.world.groupsCreated;\n\t\t\t\tthis.p.world.groups[this.idNum] = this;\n\t\t\t\tthis.p.world.groupsCreated++;\n\t\t\t}\n\n\t\t\tlet _this = this;\n\n\t\t\tclass GroupSprite extends Sprite {\n\t\t\t\tconstructor() {\n\t\t\t\t\tsuper(_this, ...arguments);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.GroupSprite = GroupSprite;\n\t\t\tthis.Sprite = GroupSprite;\n\n\t\t\tclass SubGroup extends Group {\n\t\t\t\tconstructor() {\n\t\t\t\t\tsuper(_this, ...arguments);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.SubGroup = SubGroup;\n\t\t\tthis.Group = SubGroup;\n\n\t\t\tthis.mouse = {\n\t\t\t\tpresses: null,\n\t\t\t\tpressing: null,\n\t\t\t\tpressed: null,\n\t\t\t\tholds: null,\n\t\t\t\tholding: null,\n\t\t\t\theld: null,\n\t\t\t\treleased: null,\n\t\t\t\thovers: null,\n\t\t\t\thovering: null,\n\t\t\t\thovered: null\n\t\t\t};\n\t\t\tfor (let state in this.mouse) {\n\t\t\t\tthis.mouse[state] = function (inp) {\n\t\t\t\t\tfor (let s of _this) {\n\t\t\t\t\t\tif (s.mouse[state](inp)) return true;\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet props = [...spriteProps, 'spriteSheet'];\n\t\t\tfor (let prop of props) {\n\t\t\t\tObject.defineProperty(this, prop, {\n\t\t\t\t\tget() {\n\t\t\t\t\t\tlet val = _this['_' + prop];\n\t\t\t\t\t\tlet i = _this.length - 1;\n\t\t\t\t\t\tif (val === undefined && this.p.world && !_this._isAllSpritesGroup) {\n\t\t\t\t\t\t\tlet parent = this.p.world.groups[_this.parent];\n\t\t\t\t\t\t\tif (parent) {\n\t\t\t\t\t\t\t\tval = parent[prop];\n\t\t\t\t\t\t\t\ti = parent.length - 1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn val;\n\t\t\t\t\t},\n\t\t\t\t\tset(val) {\n\t\t\t\t\t\t_this['_' + prop] = val;\n\n\t\t\t\t\t\t// change the prop in all the sprite of this group\n\t\t\t\t\t\tfor (let i = 0; i < _this.length; i++) {\n\t\t\t\t\t\t\tlet s = _this[i];\n\t\t\t\t\t\t\tlet v = val;\n\t\t\t\t\t\t\tif (typeof val == 'function') v = val(i);\n\t\t\t\t\t\t\ts[prop] = v;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tthis.vel = pInst.createVector.call(pInst);\n\t\t\tthis.mirror = {};\n\n\t\t\tlet objProps = { vel: ['x', 'y'], mirror: ['x', 'y'] };\n\t\t\tfor (let objProp in objProps) {\n\t\t\t\tfor (let prop of objProps[objProp]) {\n\t\t\t\t\tObject.defineProperty(this[objProp], prop, {\n\t\t\t\t\t\tget() {\n\t\t\t\t\t\t\tlet val = _this[objProp]['_' + prop];\n\t\t\t\t\t\t\tlet i = _this.length - 1;\n\t\t\t\t\t\t\tif (val === undefined && _this.p.world && !_this._isAllSpritesGroup) {\n\t\t\t\t\t\t\t\tlet parent = _this.p.world.groups[_this.parent];\n\t\t\t\t\t\t\t\tif (parent) {\n\t\t\t\t\t\t\t\t\tval = parent[objProp][prop];\n\t\t\t\t\t\t\t\t\ti = parent.length - 1;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn val;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tset(val) {\n\t\t\t\t\t\t\t_this[objProp]['_' + prop] = val;\n\n\t\t\t\t\t\t\t// change the prop in all the sprite of this group\n\t\t\t\t\t\t\tfor (let i = 0; i < _this.length; i++) {\n\t\t\t\t\t\t\t\tlet s = _this[i];\n\t\t\t\t\t\t\t\tlet v = val;\n\t\t\t\t\t\t\t\tif (typeof val == 'function') v = val(i);\n\t\t\t\t\t\t\t\ts[objProp][prop] = v;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.orbitAngle = 0;\n\t\t}\n\n\t\t/**\n\t\t * Reference to the group's current animation.\n\t\t *\n\t\t * @property ani\n\t\t * @type {SpriteAnimation}\n\t\t */\n\t\tget ani() {\n\t\t\treturn this._animation;\n\t\t}\n\t\tset ani(val) {\n\t\t\tthis.addAni(val);\n\t\t\tfor (let s of this) s.changeAni(val);\n\t\t}\n\t\t/**\n\t\t * Reference to the group's current animation.\n\t\t *\n\t\t * @property animation\n\t\t * @type {SpriteAnimation}\n\t\t */\n\t\tget animation() {\n\t\t\treturn this._animation;\n\t\t}\n\t\tset animation(val) {\n\t\t\tthis.ani = val;\n\t\t}\n\n\t\t/**\n\t\t * The group's animations.\n\t\t *\n\t\t * @property anis\n\t\t * @type {SpriteAnimation}\n\t\t */\n\t\tget anis() {\n\t\t\treturn this.animations;\n\t\t}\n\t\t/**\n\t\t * Reference to the group's current image.\n\t\t *\n\t\t * @property img\n\t\t * @type {SpriteAnimation}\n\t\t */\n\t\tget img() {\n\t\t\treturn this._animation.frameImage;\n\t\t}\n\t\tset img(val) {\n\t\t\tthis.ani = val;\n\t\t}\n\t\t/**\n\t\t * Reference to the group's current image.\n\t\t *\n\t\t * @property image\n\t\t * @type {SpriteAnimation}\n\t\t */\n\t\tget image() {\n\t\t\treturn this._animation.frameImage;\n\t\t}\n\t\tset image(val) {\n\t\t\tthis.ani = val;\n\t\t}\n\t\t/**\n\t\t * Depending on the value that the amount property is set to, the group will\n\t\t * either add or remove sprites.\n\t\t *\n\t\t * @property amount\n\t\t * @type {Number}\n\t\t */\n\t\tset amount(val) {\n\t\t\tlet diff = val - this.length;\n\t\t\tlet shouldAdd = diff > 0;\n\t\t\tdiff = Math.abs(diff);\n\t\t\tfor (let i = 0; i < diff; i++) {\n\t\t\t\tif (shouldAdd) this.add(new this.Sprite());\n\t\t\t\telse this[this.length - 1].remove();\n\t\t\t}\n\t\t}\n\n\t\tresetCentroid() {\n\t\t\tlet x = 0;\n\t\t\tlet y = 0;\n\t\t\tfor (let s of this) {\n\t\t\t\tx += s.x;\n\t\t\t\ty += s.y;\n\t\t\t}\n\t\t\tthis.centroid = { x: x / this.length, y: y / this.length };\n\t\t\treturn this.centroid;\n\t\t}\n\n\t\tresetDistancesFromCentroid() {\n\t\t\tfor (let s of this) {\n\t\t\t\ts.distCentroid = {\n\t\t\t\t\tx: s.x - this.centroid.x,\n\t\t\t\t\ty: s.y - this.centroid.y\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tsnap(o, dist) {\n\t\t\tdist ??= 1 || this.tileSize * 0.1;\n\t\t\tfor (let s of this) {\n\t\t\t\ts.snap(o, dist);\n\t\t\t}\n\t\t}\n\n\t\t_ensureCollide(target, callback) {\n\t\t\tif (!target) {\n\t\t\t\tthrow new FriendlyError('Group.collide', 2);\n\t\t\t}\n\t\t\tif (!(target instanceof Sprite) && !(target instanceof Group)) {\n\t\t\t\tthrow new FriendlyError('Group.collide', 0, [target]);\n\t\t\t}\n\t\t\tif (callback && typeof callback != 'function') {\n\t\t\t\tthrow new FriendlyError('Group.collide', 1, [callback]);\n\t\t\t}\n\t\t}\n\n\t\tcollide(target, callback) {\n\t\t\treturn this.collides(target, callback);\n\t\t}\n\n\t\t/**\n\t\t * Returns true on the first frame that the group collides with the\n\t\t * target sprite or group.\n\t\t *\n\t\t * Custom collision event handling can be done by using this function\n\t\t * in an if statement or adding a callback as the second parameter.\n\t\t *\n\t\t * @method collides\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t */\n\t\tcollides(target, callback) {\n\t\t\tthis._ensureCollide(target, callback);\n\t\t\tthis._collides[target] = callback || true;\n\t\t\treturn this._collisions.get(target) == 1;\n\t\t}\n\n\t\t/**\n\t\t * Returns a truthy value while the group is colliding with the\n\t\t * target sprite or group. The value is the number of frames that\n\t\t * the group has been colliding with the target.\n\t\t *\n\t\t * @method colliding\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t * @return {Number} frames\n\t\t */\n\t\tcolliding(target, callback) {\n\t\t\tthis._ensureCollide(target, callback);\n\t\t\tthis._colliding[target] = callback || true;\n\t\t\tlet val = this._collisions.get(target);\n\t\t\treturn val > 0 ? val : 0;\n\t\t}\n\n\t\t/**\n\t\t * Returns true on the first frame that the group no longer overlaps\n\t\t * with the target sprite or group.\n\t\t *\n\t\t * @method collided\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t * @return {Boolean}\n\t\t */\n\t\tcollided(target, callback) {\n\t\t\tthis._ensureCollide(target, callback);\n\t\t\tthis._collided[target] = callback || true;\n\t\t\treturn this._collisions.get(target) == -1;\n\t\t}\n\n\t\t_ensureOverlap(target, callback) {\n\t\t\tif (!target) {\n\t\t\t\tthrow new FriendlyError('Group.overlap', 2);\n\t\t\t}\n\t\t\tif (!(target instanceof Sprite) && !(target instanceof Group)) {\n\t\t\t\tthrow new FriendlyError('Group.overlap', 0, [target]);\n\t\t\t}\n\t\t\tif (callback && typeof callback != 'function') {\n\t\t\t\tthrow new FriendlyError('Group.overlap', 1, [callback]);\n\t\t\t}\n\t\t\tif (!this._hasOverlaps) {\n\t\t\t\tfor (let s of this) {\n\t\t\t\t\tif (!s._hasOverlaps) s._createSensors();\n\t\t\t\t}\n\t\t\t\tthis._hasOverlaps = true;\n\t\t\t}\n\t\t\tif (target instanceof Sprite) {\n\t\t\t\tif (!target._hasOverlaps) target._createSensors();\n\t\t\t} else if (target instanceof Group) {\n\t\t\t\tif (!target._hasOverlaps) {\n\t\t\t\t\tfor (let s of target) {\n\t\t\t\t\t\tif (!s._hasOverlaps) s._createSensors();\n\t\t\t\t\t}\n\t\t\t\t\ttarget._hasOverlaps = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._overlap[target] = true;\n\t\t}\n\n\t\toverlap(target, callback) {\n\t\t\treturn this.overlaps(target, callback);\n\t\t}\n\n\t\t/**\n\t\t * Returns true on the first frame that the group overlaps with the\n\t\t * target sprite or group.\n\t\t *\n\t\t * Custom overlap event handling can be done by using this function\n\t\t * in an if statement or adding a callback as the second parameter.\n\t\t *\n\t\t * @method overlaps\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t */\n\t\toverlaps(target, callback) {\n\t\t\tthis._ensureOverlap(target, callback);\n\t\t\tthis._overlaps[target] = callback || true;\n\t\t\treturn this._overlappers.get(target) == 1;\n\t\t}\n\n\t\t/**\n\t\t * Returns a truthy value while the group is overlapping with the\n\t\t * target sprite or group. The value returned is the number of\n\t\t * frames the group has been overlapping with the target.\n\t\t *\n\t\t * @method overlapping\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t * @return {Number} frames\n\t\t */\n\t\toverlapping(target, callback) {\n\t\t\tthis._ensureOverlap(target, callback);\n\t\t\tthis._overlapping[target] = callback || true;\n\t\t\tlet val = this._overlappers.get(target);\n\t\t\treturn val > 0 ? val : 0;\n\t\t}\n\n\t\t/**\n\t\t * Returns true on the first frame that the group no longer overlaps\n\t\t * with the target sprite or group.\n\t\t *\n\t\t * @method overlapped\n\t\t * @param {Sprite|Group} target\n\t\t * @param {Function} [callback]\n\t\t * @return {Boolean}\n\t\t */\n\t\toverlapped(target, callback) {\n\t\t\tthis._ensureOverlap(target, callback);\n\t\t\tthis._overlapped[target] = callback || true;\n\t\t\treturn this._overlappers.get(target) == -1;\n\t\t}\n\n\t\t/**\n\t\t * EXPERIMENTAL implementation for beta testing!\n\t\t *\n\t\t * Apply a force that is scaled to the sprite's mass.\n\t\t *\n\t\t * @method applyForce\n\t\t * @param {p5.Vector|Array} forceVector force vector\n\t\t * @param {p5.Vector|Array} [forceOrigin] force origin\n\t\t */\n\t\tapplyForce(forceVector, forceOrigin) {\n\t\t\tfor (let s of this) {\n\t\t\t\ts.applyForce(forceVector, forceOrigin);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * @method move\n\t\t */\n\t\tmove(distance, direction, speed) {\n\t\t\tlet movements = [];\n\t\t\tfor (let s of this) {\n\t\t\t\tmovements.push(s.move(distance, direction, speed));\n\t\t\t}\n\t\t\treturn Promise.all(movements);\n\t\t}\n\n\t\t/**\n\t\t * @method moveTo\n\t\t */\n\t\tmoveTo(x, y, speed) {\n\t\t\tif (typeof x != 'number') {\n\t\t\t\tlet obj = x;\n\t\t\t\tif (obj == this.p.mouse && !this.p.mouse.active) return;\n\t\t\t\tspeed = y;\n\t\t\t\ty = obj.y;\n\t\t\t\tx = obj.x;\n\t\t\t}\n\t\t\tlet centroid = this.resetCentroid();\n\t\t\tlet movements = [];\n\t\t\tfor (let s of this) {\n\t\t\t\tlet dest = {\n\t\t\t\t\tx: s.x - centroid.x + x,\n\t\t\t\t\ty: s.y - centroid.y + y\n\t\t\t\t};\n\t\t\t\tmovements.push(s.moveTo(dest.x, dest.y, speed));\n\t\t\t}\n\t\t\treturn Promise.all(movements);\n\t\t}\n\n\t\t/**\n\t\t * @method moveTowards\n\t\t */\n\t\tmoveTowards(x, y, tracking) {\n\t\t\tif (typeof x != 'number') {\n\t\t\t\tlet obj = x;\n\t\t\t\tif (obj == this.p.mouse && !this.p.mouse.active) return;\n\t\t\t\ttracking = y;\n\t\t\t\ty = obj.y;\n\t\t\t\tx = obj.x;\n\t\t\t}\n\t\t\tif (x === undefined && y === undefined) return;\n\t\t\tthis.resetCentroid();\n\t\t\tfor (let s of this) {\n\t\t\t\tif (s.distCentroid === undefined) this.resetDistancesFromCentroid();\n\t\t\t\tlet dest = {\n\t\t\t\t\tx: s.distCentroid.x + x,\n\t\t\t\t\ty: s.distCentroid.y + y\n\t\t\t\t};\n\t\t\t\ts.moveTowards(dest.x, dest.y, tracking);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * @method moveAway\n\t\t */\n\t\tmoveAway(x, y, tracking) {\n\t\t\tif (typeof x != 'number') {\n\t\t\t\tlet obj = x;\n\t\t\t\tif (obj == this.p.mouse && !this.p.mouse.active) return;\n\t\t\t\ttracking = y;\n\t\t\t\ty = obj.y;\n\t\t\t\tx = obj.x;\n\t\t\t}\n\t\t\tif (x === undefined && y === undefined) return;\n\t\t\tthis.resetCentroid();\n\t\t\tfor (let s of this) {\n\t\t\t\tif (s.distCentroid === undefined) this.resetDistancesFromCentroid();\n\t\t\t\tlet dest = {\n\t\t\t\t\tx: s.distCentroid.x + x,\n\t\t\t\t\ty: s.distCentroid.y + y\n\t\t\t\t};\n\t\t\t\ts.moveAway(dest.x, dest.y, tracking);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * EXPERIMENTAL! Subject to change in the future!\n\t\t *\n\t\t * Rotates the group around its centroid.\n\t\t *\n\t\t * @method orbit\n\t\t * @param {Number} amount Amount of rotation\n\t\t */\n\t\torbit(amount) {\n\t\t\tif (this.frame == 0) console.warn('group.orbit is experimental and is subject to change in the future!');\n\t\t\tif (!this.centroid) this.resetCentroid();\n\t\t\tthis.orbitAngle += amount;\n\t\t\tlet angle = this.orbitAngle;\n\t\t\tfor (let s of this) {\n\t\t\t\tif (s.distCentroid === undefined) this.resetDistancesFromCentroid();\n\t\t\t\tlet x = s.distCentroid.x;\n\t\t\t\tlet y = s.distCentroid.y;\n\t\t\t\tlet x2 = x * this.p.cos(angle) - y * this.p.sin(angle);\n\t\t\t\tlet y2 = x * this.p.sin(angle) + y * this.p.cos(angle);\n\t\t\t\tx2 += this.centroid.x;\n\t\t\t\ty2 += this.centroid.y;\n\t\t\t\ts.vel.x = (x2 - s.x) * 0.1 * s.tileSize;\n\t\t\t\ts.vel.y = (y2 - s.y) * 0.1 * s.tileSize;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Gets the member at index i.\n\t\t *\n\t\t * @deprecated get\n\t\t * @param {Number} i The index of the object to retrieve\n\t\t */\n\t\tget(i) {\n\t\t\tconsole.warn('Deprecated: use group[i] instead of group.get(i)');\n\t\t\treturn this[i];\n\t\t}\n\n\t\t/**\n\t\t * Check if a sprite is in the group.\n\t\t *\n\t\t * @method includes\n\t\t * @param {Sprite} sprite\n\t\t * @return {Number} index of the sprite or -1 if not found\n\t\t */\n\n\t\t/**\n\t\t * Use group.includes(sprite) instead.\n\t\t *\n\t\t * @deprecated contains\n\t\t * @param {Sprite} sprite The sprite to search\n\t\t * @return {Number} Index or -1 if not found\n\t\t */\n\t\tcontains(sprite) {\n\t\t\tconsole.warn('Deprecated: use group.includes(sprite) instead of group.contains(sprite)');\n\t\t\treturn this.indexOf(sprite) > -1;\n\t\t}\n\n\t\t/**\n\t\t * Adds a sprite to the group. Returns true if the sprite was added\n\t\t * because it was not already in the group.\n\t\t *\n\t\t * @method push\n\t\t * @param {Sprite} s The sprite to be added\n\t\t */\n\t\tpush(s) {\n\t\t\tif (!(s instanceof Sprite)) {\n\t\t\t\tthrow new Error('you can only add sprites to a group');\n\t\t\t}\n\n\t\t\tif (this.indexOf(s) == -1) {\n\t\t\t\tsuper.push(s);\n\t\t\t\tif (this.parent) this.p.world.groups[this.parent].push(s);\n\t\t\t\ts.groups.push(this);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Alias for push.\n\t\t *\n\t\t * @method add\n\t\t * @param {Sprite} s The sprite to be added\n\t\t */\n\t\tadd(s) {\n\t\t\tthis.push(s);\n\t\t}\n\n\t\t/**\n\t\t * @property length\n\t\t * @return {Number} The amount of sprites in the group\n\t\t */\n\n\t\t/**\n\t\t * Alias for group.length\n\t\t * @deprecated size\n\t\t */\n\t\tsize() {\n\t\t\treturn this.length;\n\t\t}\n\n\t\t/**\n\t\t * Returns the group's unique identifier.\n\t\t *\n\t\t * @returns {String} groupID\n\t\t */\n\t\ttoString() {\n\t\t\treturn 'g' + this.idNum;\n\t\t}\n\n\t\t/**\n\t\t * Remove sprites that go outside the given culling boundary\n\t\t * relative to the camera.\n\t\t *\n\t\t * @method cull\n\t\t * @param {Number} top|size The distance that sprites can move below the p5.js canvas before they are removed. *OR* The distance sprites can travel outside the screen on all sides before they get removed.\n\t\t * @param {Number} bottom|cb The distance that sprites can move below the p5.js canvas before they are removed.\n\t\t * @param {Number} [left] The distance that sprites can move beyond the left side of the p5.js canvas before they are removed.\n\t\t * @param {Number} [right] The distance that sprites can move beyond the right side of the p5.js canvas before they are removed.\n\t\t * @param {Function} [cb(sprite)] The callback is given the sprite that\n\t\t * passed the cull boundary, if no callback is given the sprite is\n\t\t * removed by default\n\t\t */\n\t\tcull(top, bottom, left, right, cb) {\n\t\t\tif (left === undefined) {\n\t\t\t\tlet size = top;\n\t\t\t\tcb = bottom;\n\t\t\t\ttop = bottom = left = right = size;\n\t\t\t}\n\t\t\tif (isNaN(top) || isNaN(bottom) || isNaN(left) || isNaN(right)) {\n\t\t\t\tthrow new TypeError('The culling boundary must be defined with numbers');\n\t\t\t}\n\t\t\tif (cb && typeof cb != 'function') {\n\t\t\t\tthrow new TypeError('The callback to group.cull must be a function');\n\t\t\t}\n\n\t\t\tlet cx = this.p.camera.x - this.p.world.hw / this.p.camera.zoom;\n\t\t\tlet cy = this.p.camera.y - this.p.world.hh / this.p.camera.zoom;\n\n\t\t\tlet minX = -left + cx;\n\t\t\tlet minY = -top + cy;\n\t\t\tlet maxX = this.p.width + right + cx;\n\t\t\tlet maxY = this.p.height + bottom + cy;\n\n\t\t\tfor (let s of this) {\n\t\t\t\tif (s.x < minX || s.y < minY || s.x > maxX || s.y > maxY) {\n\t\t\t\t\tif (cb) cb(s);\n\t\t\t\t\telse s.remove();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * If no input is given all sprites in the group are removed.\n\t\t *\n\t\t * If a sprite or index is given, that sprite is removed from this\n\t\t * group and any group this group inherits from except for the\n\t\t * allSprites group.\n\t\t *\n\t\t * @method remove\n\t\t * @param {Sprite} item The sprite to be removed\n\t\t * @return {Boolean} true if sprite was found and removed\n\t\t */\n\t\tremove(item) {\n\t\t\tif (item === undefined) {\n\t\t\t\twhile (this.length > 0) {\n\t\t\t\t\tthis[0].remove();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet idx;\n\t\t\tif (typeof item == 'number') {\n\t\t\t\tidx = item;\n\t\t\t} else {\n\t\t\t\tfor (let i = this.length - 1; i >= 0; i--) {\n\t\t\t\t\tif (this[i] === item) {\n\t\t\t\t\t\tidx = i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (idx !== undefined) {\n\t\t\t\tlet removed = this[idx];\n\t\t\t\tlet gIdx = this[idx].groups.findIndex((g) => g.idNum == this.idNum);\n\t\t\t\tthis[idx].groups.splice(gIdx, 1);\n\t\t\t\tthis.splice(idx, 1);\n\n\t\t\t\treturn removed;\n\t\t\t}\n\t\t\tthrow new Error('Sprite not found in group');\n\t\t}\n\n\t\t/**\n\t\t * Removes all sprites from the group and destroys the group.\n\t\t *\n\t\t * @method removeAll\n\t\t */\n\t\tremoveAll() {\n\t\t\tthis.remove();\n\t\t}\n\n\t\t/**\n\t\t * Returns the highest depth in a group\n\t\t *\n\t\t * @deprecated maxDepth\n\t\t * @return {Number} The depth of the sprite drawn on the top\n\t\t */\n\t\tmaxDepth() {\n\t\t\tif (this.length == 0) return 0;\n\t\t\tif (this.length == 1 && this[0].layer === undefined) return 0;\n\t\t\tlet max = this[0].layer;\n\t\t\tfor (let s of this) {\n\t\t\t\tif (s.layer > max) max = s.layer;\n\t\t\t}\n\t\t\treturn max;\n\t\t}\n\n\t\t/**\n\t\t * Returns the lowest depth in a group\n\t\t *\n\t\t * @deprecated minDepth\n\t\t * @return {Number} The depth of the sprite drawn on the bottom\n\t\t */\n\t\tminDepth() {\n\t\t\tif (this.length === 0) {\n\t\t\t\treturn 99999;\n\t\t\t}\n\n\t\t\treturn this.reduce(function (minDepth, sprite) {\n\t\t\t\treturn Math.min(minDepth, sprite.depth);\n\t\t\t}, Infinity);\n\t\t}\n\n\t\t/**\n\t\t * Draws all the sprites in the group.\n\t\t *\n\t\t * @method draw\n\t\t */\n\t\tdraw() {\n\t\t\tlet g = [...this];\n\t\t\tg.sort((a, b) => a.layer - b.layer);\n\t\t\tfor (let i = 0; i < g.length; i++) {\n\t\t\t\tlet sprite = g[i];\n\t\t\t\tif (sprite.life-- < 0) {\n\t\t\t\t\tsprite.remove();\n\t\t\t\t\tg.splice(i, 1);\n\t\t\t\t\ti--;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (sprite.visible) sprite.draw();\n\t\t\t}\n\t\t}\n\n\t\tupdate() {\n\t\t\tthrow new Error('Use the updateSprites function instead to control whether sprites are updated or not.');\n\t\t}\n\t}\n\n\t/**\n\t * Adds an animation to the sprite. Use this function in the preload p5.js\n\t * function. You don't need to name the animation if the sprite will only\n\t * use one animation. See SpriteAnimation for more information.\n\t *\n\t * @example\n\t * sprite.addAni(name, animation);\n\t * sprite.addAni(name, frame1, frame2, frame3...);\n\t * sprite.addAni(name, atlas);\n\t *\n\t * @method addAni\n\t * @param {String} name SpriteAnimation identifier\n\t * @param {SpriteAnimation} animation The preloaded animation\n\t */\n\tSprite.prototype.addAnimation =\n\t\tGroup.prototype.addAnimation =\n\t\tSprite.prototype.addAni =\n\t\tGroup.prototype.addAni =\n\t\tSprite.prototype.addImage =\n\t\tGroup.prototype.addImage =\n\t\tSprite.prototype.addImg =\n\t\tGroup.prototype.addImg =\n\t\t\tfunction () {\n\t\t\t\tlet args = [...arguments];\n\t\t\t\tlet name, ani;\n\t\t\t\tif (args[0] instanceof SpriteAnimation) {\n\t\t\t\t\tani = args[0];\n\t\t\t\t\tname = ani.name || 'default';\n\t\t\t\t\tani.name = name;\n\t\t\t\t} else if (args[1] instanceof SpriteAnimation) {\n\t\t\t\t\tname = args[0];\n\t\t\t\t\tani = args[1];\n\t\t\t\t\tani.name = name;\n\t\t\t\t} else {\n\t\t\t\t\tani = new SpriteAnimation(this, ...args);\n\t\t\t\t\tname = ani.name;\n\t\t\t\t}\n\t\t\t\tthis.animations[name] = ani;\n\t\t\t\tthis._animation = ani;\n\n\t\t\t\t// only works if the animation was loaded in preload\n\t\t\t\tif (this._dimensionsUndefined && (ani.w != 1 || ani.h != 1)) {\n\t\t\t\t\tthis.w = ani.w;\n\t\t\t\t\tthis.h = ani.h;\n\t\t\t\t}\n\t\t\t\treturn ani;\n\t\t\t};\n\n\t/**\n\t * Add multiple animations\n\t *\n\t * @method addAnis\n\t */\n\tSprite.prototype.addAnis =\n\t\tGroup.prototype.addAnis =\n\t\tSprite.prototype.addAnimations =\n\t\tGroup.prototype.addAnimations =\n\t\tSprite.prototype.addImages =\n\t\tGroup.prototype.addImages =\n\t\tSprite.prototype.addImgs =\n\t\tGroup.prototype.addImgs =\n\t\t\tfunction () {\n\t\t\t\tlet args = arguments;\n\t\t\t\tlet atlases;\n\t\t\t\tif (args.length == 1) {\n\t\t\t\t\tatlases = args[0];\n\t\t\t\t} else {\n\t\t\t\t\tthis.spriteSheet = args[0];\n\t\t\t\t\tatlases = args[1];\n\t\t\t\t}\n\t\t\t\tfor (let name in atlases) {\n\t\t\t\t\tlet atlas = atlases[name];\n\t\t\t\t\tthis.addAni(name, atlas);\n\t\t\t\t}\n\t\t\t};\n\n\t/**\n\t * Look at the World reference pages before reading these docs.\n\t *\n\t * https://p5play.org/learn/world.html\n\t *\n\t * @class World\n\t * @constructor\n\t */\n\tclass World extends pl.World {\n\t\tconstructor() {\n\t\t\tsuper(new pl.Vec2(0, 0), true);\n\t\t\tthis.p = pInst;\n\t\t\tthis.width = this.p.width;\n\t\t\tthis.height = this.p.height;\n\t\t\tthis._offset = { x: 0, y: 0 };\n\t\t\tlet _this = this;\n\t\t\tthis.offset = {\n\t\t\t\tget x() {\n\t\t\t\t\treturn -_this._offset.x;\n\t\t\t\t},\n\t\t\t\t/**\n\t\t\t\t * @property offset.x\n\t\t\t\t */\n\t\t\t\tset x(val) {\n\t\t\t\t\t_this._offset.x = val;\n\t\t\t\t\t_this.resize();\n\t\t\t\t},\n\t\t\t\tget y() {\n\t\t\t\t\treturn -_this._offset.y;\n\t\t\t\t},\n\t\t\t\t/**\n\t\t\t\t * @property offset.y\n\t\t\t\t */\n\t\t\t\tset y(val) {\n\t\t\t\t\t_this._offset.y = val;\n\t\t\t\t\t_this.resize();\n\t\t\t\t}\n\t\t\t};\n\t\t\tthis.resize();\n\n\t\t\t/**\n\t\t\t * If false, animations that are stopped before they are completed,\n\t\t\t * typically by a call to sprite.changeAni, will restart at the\n\t\t\t * frame they were stopped at. If true, animations will always\n\t\t\t * start playing from frame 0 unless specified by the user in a\n\t\t\t * separate `anim.changeFrame` call.\n\t\t\t *\n\t\t\t * @property autoResetAnimations\n\t\t\t * @type {SpriteAnimation}\n\t\t\t * @default false\n\t\t\t */\n\t\t\tthis.autoResetAnimations = false;\n\n\t\t\tthis.palettes = this.p.world?.palettes || [\n\t\t\t\t{\n\t\t\t\t\t// a\n\t\t\t\t\tb: 'black',\n\t\t\t\t\tc: 'crimson',\n\t\t\t\t\td: 'dark blue',\n\t\t\t\t\t// e\n\t\t\t\t\tf: 'fuchsia',\n\t\t\t\t\tg: 'green',\n\t\t\t\t\th: 'hot pink',\n\t\t\t\t\ti: 'blue', // indigo\n\t\t\t\t\t// j\n\t\t\t\t\tk: 'black',\n\t\t\t\t\tl: 'lavender',\n\t\t\t\t\tm: 'magenta',\n\t\t\t\t\tn: 'brown',\n\t\t\t\t\to: 'orange',\n\t\t\t\t\tp: 'pink',\n\t\t\t\t\t// q\n\t\t\t\t\tr: 'red',\n\t\t\t\t\ts: 'sky blue',\n\t\t\t\t\tt: 'turquoise',\n\t\t\t\t\tu: 'blue',\n\t\t\t\t\tv: 'violet',\n\t\t\t\t\tw: 'white',\n\t\t\t\t\t// x\n\t\t\t\t\ty: 'yellow'\n\t\t\t\t\t// z\n\t\t\t\t}\n\t\t\t];\n\n\t\t\tthis.groups = [this.p.allSprites];\n\t\t\tthis.groupsCreated = 1;\n\t\t\tthis.spritesCreated = 0;\n\t\t\tthis.contacts = [];\n\n\t\t\tthis.on('begin-contact', this._beginContact);\n\t\t\tthis.on('end-contact', this._endContact);\n\n\t\t\t/**\n\t\t\t * Gravity vector (x, y)\n\t\t\t *\n\t\t\t * All sprites getting\n\t\t\t *\n\t\t\t * @property gravity\n\t\t\t */\n\t\t\tthis.gravity = {\n\t\t\t\tget x() {\n\t\t\t\t\treturn _this.m_gravity.x;\n\t\t\t\t},\n\t\t\t\tset x(val) {\n\t\t\t\t\tfor (let s of _this.p.allSprites) {\n\t\t\t\t\t\ts.sleeping = false;\n\t\t\t\t\t}\n\t\t\t\t\t_this.m_gravity.x = _this.p.round(val || 0);\n\t\t\t\t},\n\t\t\t\tget y() {\n\t\t\t\t\treturn _this.m_gravity.y;\n\t\t\t\t},\n\t\t\t\tset y(val) {\n\t\t\t\t\tfor (let s of _this.p.allSprites) {\n\t\t\t\t\t\ts.sleeping = false;\n\t\t\t\t\t}\n\t\t\t\t\t_this.m_gravity.y = _this.p.round(val || 0);\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tresize(w, h) {\n\t\t\tw ??= this.p.width;\n\t\t\th ??= this.p.height;\n\t\t\tthis.origin = {\n\t\t\t\tx: w * 0.5 + this.offset.x,\n\t\t\t\ty: h * 0.5 + this.offset.y\n\t\t\t};\n\t\t\tif (this.p.allSprites.tileSize != 1) {\n\t\t\t\tthis.origin.x -= this.p.allSprites.tileSize * 0.5;\n\t\t\t\tthis.origin.y -= this.p.allSprites.tileSize * 0.5;\n\t\t\t}\n\t\t\tthis.hw = w * 0.5;\n\t\t\tthis.hh = h * 0.5;\n\t\t}\n\n\t\t_beginContact(contact) {\n\t\t\t// Get both fixtures\n\t\t\tlet a = contact.m_fixtureA;\n\t\t\tlet b = contact.m_fixtureB;\n\t\t\tlet t = '_collisions';\n\t\t\tif (a.isSensor()) t = '_overlappers';\n\t\t\ta = a.m_body.sprite;\n\t\t\tb = b.m_body.sprite;\n\n\t\t\ta[t].set(b, 0);\n\t\t\tb[t].set(a, 0);\n\n\t\t\tfor (let g of b.groups) {\n\t\t\t\tg[t].set(a, g[t].get(a) || 0);\n\t\t\t\ta[t].set(g, a[t].get(g) || 0);\n\t\t\t}\n\n\t\t\tfor (let g of a.groups) {\n\t\t\t\tg[t].set(b, g[t].get(b) || 0);\n\t\t\t\tb[t].set(g, b[t].get(g) || 0);\n\t\t\t\tfor (let g2 of b.groups) {\n\t\t\t\t\tg[t].set(g2, g[t].get(g2) || 0);\n\t\t\t\t\tg2[t].set(g, g2[t].get(g) || 0);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t_endContact(contact) {\n\t\t\tlet a = contact.m_fixtureA;\n\t\t\tlet b = contact.m_fixtureB;\n\t\t\tlet contactType = '_collisions';\n\t\t\tif (a.isSensor()) contactType = '_overlappers';\n\t\t\ta = a.m_body.sprite;\n\t\t\tb = b.m_body.sprite;\n\n\t\t\ta[contactType].set(b, -2);\n\t\t\tb[contactType].set(a, -2);\n\n\t\t\tfor (let g of b.groups) {\n\t\t\t\tlet inContact = false;\n\t\t\t\tfor (let s of g) {\n\t\t\t\t\tif (s[contactType].get(a) >= 0) {\n\t\t\t\t\t\tinContact = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!inContact) {\n\t\t\t\t\tg[contactType].set(a, -2);\n\t\t\t\t\ta[contactType].set(g, -2);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (let g of a.groups) {\n\t\t\t\tlet inContact = false;\n\t\t\t\tfor (let s of g) {\n\t\t\t\t\tif (s[contactType].get(b) >= 0) {\n\t\t\t\t\t\tinContact = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!inContact) {\n\t\t\t\t\tg[contactType].set(b, -2);\n\t\t\t\t\tb[contactType].set(g, -2);\n\t\t\t\t\tfor (let g2 of b.groups) {\n\t\t\t\t\t\tg[contactType].set(g2, -2);\n\t\t\t\t\t\tg2[contactType].set(g, -2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tget autoCull() {\n\t\t\treturn this.p.allSprites.autoCull;\n\t\t}\n\n\t\tset autoCull(val) {\n\t\t\tthis.p.allSprites.autoCull = val;\n\t\t}\n\n\t\tget allowSleeping() {\n\t\t\treturn this.getAllowSleeping();\n\t\t}\n\n\t\tset allowSleeping(val) {\n\t\t\tthis.setAllowSleeping(val);\n\t\t}\n\t}\n\n\t/**\n\t * Look at the Camera reference pages before reading these docs.\n\t *\n\t * https://p5play.org/learn/camera.html\n\t *\n\t * A camera facilitates scrolling and zooming for scenes extending beyond\n\t * the canvas. A camera has a position, a zoom factor, and the mouse\n\t * coordinates relative to the view.\n\t * The camera is automatically created on the first draw cycle.\n\t *\n\t * In p5.js terms the camera wraps the whole drawing cycle in a\n\t * transformation matrix but it can be disable anytime during the draw\n\t * cycle for example to draw interface elements in an absolute position.\n\t *\n\t * @class Camera\n\t * @constructor\n\t * @param {Number} x Initial x coordinate\n\t * @param {Number} y Initial y coordinate\n\t * @param {Number} zoom magnification\n\t **/\n\tclass Camera {\n\t\tconstructor(x, y, zoom) {\n\t\t\tthis.p = pInst;\n\t\t\tlet _this = this;\n\n\t\t\tthis._pos = { x: 0, y: 0 };\n\n\t\t\t/**\n\t\t\t * Camera zoom.\n\t\t\t *\n\t\t\t * A scale of 1 will be the normal size. Setting it to 2 will\n\t\t\t * make everything twice the size. .5 will make everything half\n\t\t\t * size.\n\t\t\t *\n\t\t\t * @property zoom\n\t\t\t * @type {Number}\n\t\t\t * @default 1\n\t\t\t */\n\t\t\tthis.zoom = zoom || 1;\n\n\t\t\t/**\n\t\t\t * Get the translated mouse position relative to the camera view.\n\t\t\t * Offsetting and scaling the canvas will not change the sprites' position\n\t\t\t * nor the mouseX and mouseY variables. Use this property to read the mouse\n\t\t\t * position if the camera moved or zoomed.\n\t\t\t *\n\t\t\t * @property mouse\n\t\t\t * @type {Object}\n\t\t\t */\n\t\t\tthis.mouse = {\n\t\t\t\tx: this.p.mouseX,\n\t\t\t\ty: this.p.mouseY\n\t\t\t};\n\t\t\t/**\n\t\t\t * @property mouse.x\n\t\t\t * @type {Number}\n\t\t\t */\n\t\t\t/**\n\t\t\t * @property mouse.y\n\t\t\t * @type {Number}\n\t\t\t */\n\n\t\t\t/**\n\t\t\t * True if the camera is active.\n\t\t\t * Read only property. Use the methods Camera.on() and Camera.off()\n\t\t\t * to enable or disable the camera.\n\t\t\t *\n\t\t\t * @property active\n\t\t\t * @type {Boolean}\n\t\t\t * @default false\n\t\t\t */\n\t\t\tthis.active = false;\n\n\t\t\tthis.bound = {\n\t\t\t\tmin: { x: 0, y: 0 },\n\t\t\t\tmax: { x: 0, y: 0 }\n\t\t\t};\n\n\t\t\tif (x) this.x = x;\n\t\t\tif (y) this.y = y;\n\t\t}\n\n\t\t/**\n\t\t * The camera's position. {x, y}\n\t\t *\n\t\t * @property pos\n\t\t * @type {Object}\n\t\t */\n\t\tget pos() {\n\t\t\treturn this._pos;\n\t\t}\n\t\t/**\n\t\t * The camera's position. Alias for pos.\n\t\t *\n\t\t * @property position\n\t\t * @type {Object}\n\t\t */\n\t\tget position() {\n\t\t\treturn this._pos;\n\t\t}\n\n\t\t/**\n\t\t * The camera x position.\n\t\t *\n\t\t * @property x\n\t\t * @type {Number}\n\t\t */\n\t\tget x() {\n\t\t\treturn this._pos.x;\n\t\t}\n\t\tset x(val) {\n\t\t\tthis._pos.x = val;\n\t\t\tthis.bound.min.x = this.x - this.p.world.hw / this.zoom - 100;\n\t\t\tthis.bound.max.x = this.x + this.p.world.hw / this.zoom + 100;\n\t\t}\n\n\t\t/**\n\t\t * The camera y position.\n\t\t *\n\t\t * @property y\n\t\t * @type {Number}\n\t\t */\n\t\tget y() {\n\t\t\treturn this._pos.y;\n\t\t}\n\t\tset y(val) {\n\t\t\tthis._pos.y = val;\n\t\t\tthis.bound.min.y = this.y - this.p.world.hh / this.zoom - 100;\n\t\t\tthis.bound.max.y = this.y + this.p.world.hh / this.zoom + 100;\n\t\t}\n\n\t\t/**\n\t\t * Activates the camera.\n\t\t * The canvas will be drawn according to the camera position and scale until\n\t\t * camera.off() is called\n\t\t *\n\t\t * @method on\n\t\t */\n\t\ton() {\n\t\t\tif (!this.active) {\n\t\t\t\tthis.p.push();\n\t\t\t\tthis.p.scale(this.zoom);\n\t\t\t\tthis.p.translate(-this.x + this.p.world.hw / this.zoom, -this.y + this.p.world.hh / this.zoom);\n\t\t\t\tthis.active = true;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Deactivates the camera.\n\t\t * The canvas will be drawn normally, ignoring the camera's position\n\t\t * and scale until camera.on() is called\n\t\t *\n\t\t * @method off\n\t\t */\n\t\toff() {\n\t\t\tif (this.active) {\n\t\t\t\tthis.p.pop();\n\t\t\t\tthis.active = false;\n\t\t\t}\n\t\t}\n\t} //end camera class\n\n\t/**\n\t * Used internally to find a contact callback between two sprites.\n\t *\n\t * @private _findContactCB\n\t * @param {String} type \"collide\" or \"overlap\"\n\t * @param {Sprite} s0\n\t * @param {Sprite} s1\n\t * @returns contact cb if one can be found between the two sprites\n\t */\n\tfunction _findContactCB(type, s0, s1) {\n\t\tlet cb = s0[type][s1];\n\t\tif (cb) return cb;\n\n\t\tlet s1IsSprite = s1 instanceof Sprite;\n\n\t\tif (s1IsSprite) {\n\t\t\tfor (let g1 of s1.groups) {\n\t\t\t\tcb = s0[type][g1];\n\t\t\t\tif (cb) return cb;\n\t\t\t}\n\t\t}\n\n\t\tif (s0 instanceof Sprite) {\n\t\t\tfor (let g0 of s0.groups) {\n\t\t\t\tcb = g0[type][s1];\n\t\t\t\tif (cb) return cb;\n\t\t\t\tif (s1IsSprite) {\n\t\t\t\t\tfor (let g1 of s1.groups) {\n\t\t\t\t\t\tcb = g0[type][g1];\n\t\t\t\t\t\tif (cb) return cb;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * This planck function should've be named \"shouldContact\", because that's what\n\t * it actually decides.\n\t *\n\t * Here we override it to allow for overlap events between sprites.\n\t */\n\tpl.Fixture.prototype.shouldCollide = function (that) {\n\t\t// should this and that produce a contact event?\n\t\tlet a = this;\n\t\tlet b = that;\n\n\t\t// sensors overlap (returning true doesn't mean they will collide it means\n\t\t// they're included in begin contact and end contact events)\n\t\tif (a.isSensor() && b.isSensor()) return true;\n\t\t// ignore contact events between a sensor and a non-sensor\n\t\tif (a.isSensor() || b.isSensor()) return false;\n\t\t// else test if the two non-sensor colliders should overlap\n\n\t\ta = a.m_body.sprite;\n\t\tb = b.m_body.sprite;\n\n\t\t// if `a` has an overlap enabled with `b` their colliders should not produce a\n\t\t// contact event, the overlap contact event is between their sensors\n\t\tlet shouldOverlap = _findContactCB('_overlap', a, b);\n\t\tif (!shouldOverlap) shouldOverlap = _findContactCB('_overlap', b, a);\n\t\tif (shouldOverlap) return false;\n\t\treturn true;\n\t};\n\n\t/**\n\t * Look at the Tiles reference pages before reading these docs.\n\t *\n\t * https://p5play.org/learn/tiles.html\n\t *\n\t * @class Tiles\n\t * @constructor\n\t * @param {String} tiles\n\t * @param {Number} x\n\t * @param {Number} y\n\t * @param {Number} w\n\t * @param {Number} h\n\t */\n\tclass Tiles {\n\t\tconstructor(tiles, x, y, w, h) {\n\t\t\tif (typeof tiles == 'string') tiles = tiles.split('\\n');\n\n\t\t\tx ??= 0;\n\t\t\ty ??= 0;\n\t\t\tw ??= 1;\n\t\t\th ??= 1;\n\n\t\t\tfor (let row = 0; row < tiles.length; row++) {\n\t\t\t\tfor (let col = 0; col < tiles[row].length; col++) {\n\t\t\t\t\tlet t = tiles[row][col];\n\t\t\t\t\tif (t == ' ' || t == '.') continue;\n\t\t\t\t\tlet ani, g;\n\t\t\t\t\tfor (g of pInst.world.groups) {\n\t\t\t\t\t\tani = g.animations[t];\n\t\t\t\t\t\tif (ani) break;\n\t\t\t\t\t}\n\t\t\t\t\tif (ani) {\n\t\t\t\t\t\tnew g.Sprite(ani, x + col * w, y + row * h);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tlet wasFound = false;\n\t\t\t\t\tfor (g of pInst.world.groups) {\n\t\t\t\t\t\tif (g.tile == t) {\n\t\t\t\t\t\t\twasFound = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (wasFound) {\n\t\t\t\t\t\tnew g.Sprite(x + col * w, y + row * h);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tlet s;\n\t\t\t\t\tfor (s of pInst.allSprites) {\n\t\t\t\t\t\tif (s.tile == t) {\n\t\t\t\t\t\t\twasFound = true;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (wasFound) {\n\t\t\t\t\t\ts.x = x + col * w;\n\t\t\t\t\t\ts.y = y + row * h;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconsole.error('Tile not found: ' + t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tthis.Tiles = Tiles;\n\n\t/**\n\t * Look at the p5.play reference pages before reading these docs.\n\t *\n\t * https://p5play.org/learn\n\t *\n\t * @class p5.play\n\t */\n\n\t/**\n\t * Equivalent to `new Tiles`\n\t *\n\t * @method createTiles\n\t * @param {String|Array} tiles String or array of strings\n\t */\n\tthis.createTiles = function (tiles, x, y, w, h) {\n\t\treturn new Tiles(tiles, x, y, w, h);\n\t};\n\n\tclass Scale {\n\t\tconstructor() {\n\t\t\tthis._x = 1;\n\t\t\tthis._y = 1;\n\t\t\tthis._avg = 1;\n\t\t}\n\n\t\tvalueOf() {\n\t\t\treturn this._avg;\n\t\t}\n\n\t\tget x() {\n\t\t\treturn this._x;\n\t\t}\n\t\tset x(val) {\n\t\t\tif (val == this._x) return;\n\t\t\tthis._x = val;\n\t\t\tthis._avg = (this._x + this._y) * 0.5;\n\t\t}\n\n\t\tget y() {\n\t\t\treturn this._y;\n\t\t}\n\t\tset y(val) {\n\t\t\tif (val == this._y) return;\n\t\t\tthis._y = val;\n\t\t\tthis._avg = (this._x + this._y) * 0.5;\n\t\t}\n\t}\n\n\t/**\n\t * This function is automatically called at the end of the p5.js draw\n\t * loop, unless it was already called in the draw loop.\n\t *\n\t * @method updateSprites\n\t * @param {Number} timeStep\n\t * @param {Number} velocityIterations\n\t * @param {Number} positionIterations\n\t */\n\tthis.updateSprites = function (timeStep, velocityIterations, positionIterations) {\n\t\tfor (let s of this.allSprites) {\n\t\t\ts.prevPos.x = s.x;\n\t\t\ts.prevPos.y = s.y;\n\t\t}\n\n\t\t// 2nd and 3rd arguments are velocity and position iterations\n\t\tthis.world.step(timeStep || 1 / 60, velocityIterations || 8, positionIterations || 3);\n\n\t\tfor (let s of this.allSprites) {\n\t\t\ts.update();\n\t\t}\n\t\tthis.p5play.autoUpdateSprites = false;\n\t};\n\n\t/**\n\t * Returns the sprites at a position.\n\t *\n\t * @method getSpriteAt\n\t * @param {Number} x\n\t * @param {Number} y\n\t * @returns\n\t */\n\tthis.getSpritesAt = function (x, y, group, cameraActiveWhenDrawn) {\n\t\tcameraActiveWhenDrawn ??= true;\n\t\tconst convertedPoint = new pl.Vec2(x / plScale, y / plScale);\n\t\tconst aabb = new pl.AABB();\n\t\taabb.lowerBound = new pl.Vec2(convertedPoint.x - 0.001, convertedPoint.y - 0.001);\n\t\taabb.upperBound = new pl.Vec2(convertedPoint.x + 0.001, convertedPoint.y + 0.001);\n\n\t\t// Query the world for overlapping shapes.\n\t\tlet fxts = [];\n\t\tpInst.world.queryAABB(aabb, (fxt) => {\n\t\t\tif (fxt.getShape().testPoint(fxt.getBody().getTransform(), convertedPoint)) {\n\t\t\t\tfxts.push(fxt);\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\n\t\tgroup ??= pInst.allSprites;\n\n\t\tlet sprites = [];\n\t\tif (fxts.length > 0) {\n\t\t\tfor (let s of group) {\n\t\t\t\tif (!s.body) continue;\n\t\t\t\tif (fxts.includes(s.body.m_fixtureList)) {\n\t\t\t\t\tif (s._cameraActiveWhenDrawn == cameraActiveWhenDrawn) sprites.push(s);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn sprites;\n\t};\n\n\t/**\n\t * Returns the sprite at the top most layer position where\n\t * the mouse click occurs\n\t *\n\t * @method getSpriteAt\n\t * @param {Number} x\n\t * @param {Number} y\n\t * @returns\n\t */\n\tthis.getSpriteAt = function (x, y, group) {\n\t\tlet sprites = this.getSpritesAt(x, y, group);\n\t\tsprites.sort((a, b) => (a.layer - b.layer) * -1);\n\t\treturn sprites[0];\n\t};\n\n\t// TODO implement planck joints\n\t// the following code is from https://github.com/bobcgausa/cook-js\n\n\t// const debugDraw = (canvas, scale, world) => {\n\t// \tconst context = canvas.getContext('2d');\n\t// \t//context.fillStyle = '#DDD';\n\t// \t//context.fillRect(0, 0, canvas.width, canvas.height);\n\n\t// \t// Draw joints\n\t// \tfor (let j = world.m_jointList; j; j = j.m_next) {\n\t// \t\tcontext.lineWidth = 0.25;\n\t// \t\tcontext.strokeStyle = '#00F';\n\t// \t\tdrawJoint(context, scale, world, j);\n\t// \t}\n\t// };\n\n\t// const drawJoint = (context, scale, world, joint) => {\n\t// \tcontext.save();\n\t// \tcontext.scale(scale, scale);\n\t// \tcontext.lineWidth /= scale;\n\n\t// \tconst b1 = joint.m_bodyA;\n\t// \tconst b2 = joint.m_bodyB;\n\t// \tconst x1 = b1.getPosition();\n\t// \tconst x2 = b2.getPosition();\n\t// \tlet p1;\n\t// \tlet p2;\n\t// \tcontext.beginPath();\n\t// \tswitch (joint.m_type) {\n\t// \t\tcase 'distance-joint':\n\t// \t\tcase 'rope-joint':\n\t// \t\t\tcontext.moveTo(x1.x, x1.y);\n\t// \t\t\tcontext.lineTo(x2.x, x2.y);\n\t// \t\t\tbreak;\n\t// \t\tcase 'wheel-joint':\n\t// \t\tcase 'revolute-joint':\n\t// \t\t\tp1 = joint.m_localAnchorA;\n\t// \t\t\tp2 = joint.m_localAnchorB;\n\t// \t\t\tconst a = b2.getAngle();\n\t// \t\t\tconst v = new pl.Vec2(cos(a), sin(a));\n\t// \t\t\tcontext.moveTo(x2.x, x2.y);\n\t// \t\t\tcontext.lineTo(x2.x + v.x, x2.y + v.y);\n\t// \t\t\tbreak;\n\t// \t\tcase 'mouse-joint':\n\t// \t\tcase 'weld-joint':\n\t// \t\t\tp1 = joint.getAnchorA();\n\t// \t\t\tp2 = joint.getAnchorB();\n\t// \t\t\tcontext.moveTo(p1.x, p1.y);\n\t// \t\t\tcontext.lineTo(p2.x, p2.y);\n\t// \t\t\tbreak;\n\t// \t\tcase 'pulley-joint':\n\t// \t\t\tp1 = joint.m_groundAnchorA;\n\t// \t\t\tp2 = joint.m_groundAnchorB;\n\t// \t\t\tcontext.moveTo(p1.x, p1.y);\n\t// \t\t\tcontext.lineTo(x1.x, x1.y);\n\t// \t\t\tcontext.moveTo(p2.x, p2.y);\n\t// \t\t\tcontext.lineTo(x2.x, x2.y);\n\t// \t\t\tcontext.moveTo(p1.x, p1.y);\n\t// \t\t\tcontext.lineTo(p2.x, p2.y);\n\t// \t\t\tbreak;\n\t// \t\tdefault:\n\t// \t\t\tbreak;\n\t// \t}\n\t// \tcontext.closePath();\n\t// \tcontext.stroke();\n\t// \tcontext.restore();\n\t// };\n\n\t// function getAABB(body) {\n\t// \tconst aabb = new pl.AABB();\n\t// \tconst t = new pl.Transform();\n\t// \tt.setIdentity();\n\t// \tconst shapeAABB = new pl.AABB();\n\t// \taabb.lowerBound = new pl.Vec2(1000000, 1000000);\n\t// \taabb.upperBound = new pl.Vec2(-1000000, -1000000);\n\t// \tlet fixture = body.body.getFixtureList();\n\t// \twhile (fixture) {\n\t// \t\tconst shape = fixture.getShape();\n\t// \t\tconst childCount = shape.getChildCount(); //only for chains\n\t// \t\tfor (let child = 0; child < childCount; ++child) {\n\t// \t\t\tshape.computeAABB(shapeAABB, body.body.m_xf, child);\n\t// \t\t\tunionTo(aabb, shapeAABB);\n\t// \t\t}\n\t// \t\tfixture = fixture.getNext();\n\t// \t}\n\t// \taabb.lowerBound.mul(plScale); //upper left, offset from center\n\t// \taabb.upperBound.mul(plScale); //lower right\n\t// \treturn aabb;\n\t// }\n\n\t// function unionTo(a, b) {\n\t// \ta.lowerBound.x = min(a.lowerBound.x, b.lowerBound.x);\n\t// \ta.lowerBound.y = min(a.lowerBound.y, b.lowerBound.y);\n\t// \ta.upperBound.x = max(a.upperBound.x, b.upperBound.x);\n\t// \ta.upperBound.y = max(a.upperBound.y, b.upperBound.y);\n\t// }\n\n\t// The ray cast collects multiple hits along the ray in ALL mode.\n\t// The fixtures are not necessary reported in order.\n\t// We might not capture the closest fixture in ANY.\n\t// const rayCast = (() => {\n\t// \tlet def = {\n\t// \t\tANY: 0,\n\t// \t\tNEAREST: 2,\n\t// \t\tALL: 1\n\t// \t};\n\n\t// \tconst reset = (mode, ignore) => {\n\t// \t\tdef.points = [];\n\t// \t\tdef.normals = [];\n\t// \t\tdef.fixtures = [];\n\t// \t\tdef.fractions = [];\n\t// \t\tdef.ignore = ignore || [];\n\t// \t\tdef.mode = mode == undefined ? def.NEAREST : mode;\n\t// \t};\n\n\t// \tdef.rayCast = (point1, point2, mode, ignore) => {\n\t// \t\treset(mode, ignore);\n\t// \t\tworld.rayCast(scaleTo(point1), scaleTo(point2), def.callback);\n\t// \t};\n\n\t// \tdef.callback = (fixture, point, normal, fraction) => {\n\t// \t\tif (def.ignore.length > 0) for (let i = 0; i < def.ignore.length; i++) if (def.ignore[i] === fixture) return -1;\n\t// \t\tif (def.mode == def.NEAREST && def.points.length == 1) {\n\t// \t\t\tdef.fixtures[0] = fixture;\n\t// \t\t\tdef.points[0] = scaleFrom(point);\n\t// \t\t\tdef.normals[0] = normal;\n\t// \t\t\tdef.fractions[0] = fraction;\n\t// \t\t} else {\n\t// \t\t\tdef.fixtures.push(fixture);\n\t// \t\t\tdef.points.push(scaleFrom(point));\n\t// \t\t\tdef.normals.push(normal);\n\t// \t\t\tdef.fractions.push(fraction);\n\t// \t\t}\n\t// \t\t// -1 to ignore a fixture and continue\n\t// \t\t//  0 to terminate on first hit, or for searching\n\t// \t\t//  fraction seems to return nearest fixture as last entry in array\n\t// \t\t// +1 returns multiple but mix of low high or high low\n\t// \t\treturn def.mode == def.NEAREST ? fraction : def.mode;\n\t// \t};\n\n\t// \treturn def;\n\t// })();\n\n\t// const queryAABB = (() => {\n\t// \tlet def = {};\n\t// \tfunction reset(search) {\n\t// \t\tdef.fixtures = [];\n\t// \t\tdef.search = search || [];\n\t// \t}\n\n\t// \tdef.query = ({ lowerBound, upperBound }, search) => {\n\t// \t\treset(search);\n\t// \t\taabbc = new pl.AABB(lowerBound.mul(1 / plScale), upperBound.mul(1 / plScale));\n\t// \t\tworld.queryAABB(aabbc, def.callback);\n\t// \t};\n\n\t// \tdef.callback = (fixture) => {\n\t// \t\tdef.fixtures.push(fixture);\n\t// \t\treturn true;\n\t// \t};\n\n\t// \treturn def;\n\t// })();\n\n\t/**\n\t * Gets a color from a color palette\n\t *\n\t * @method colorPal\n\t * @param {String} c A single character, a key found in the color palette object.\n\t * @param {Number|Object} palette Can be a palette object or number index\n\t * in the system's palettes array.\n\t * @returns a hex color string for use by p5.js functions\n\t */\n\tthis.colorPal = (c, palette) => {\n\t\tif (c instanceof p5.Color) return c;\n\t\tif (typeof palette == 'number') {\n\t\t\tpalette = pInst.world.palettes[palette];\n\t\t}\n\t\tpalette ??= pInst.world.palettes[0];\n\t\tlet clr;\n\t\tif (palette) clr = palette[c];\n\t\t// if transparent\n\t\tif (clr === '' || c === '.' || c === ' ') {\n\t\t\treturn pInst.color(0, 0, 0, 0);\n\t\t}\n\t\treturn pInst.color(clr || c);\n\t};\n\n\t/**\n\t * Create pixel art images from a string. Each character in the\n\t * input string represents a color value defined in the palette\n\t * object.\n\t *\n\t * @method spriteArt\n\t * @param {String} txt Each character represents a pixel color value\n\t * @param {Number} scale The scale of the image\n\t * @param {Number|Object} palette Color palette\n\t * @returns A p5.js Image\n\t *\n\t * @example\n\t * let str = `\n\t * ...yyyy\n\t * .yybyybyy\n\t * yyyyyyyyyy\n\t * yybyyyybyy\n\t * .yybbbbyy\n\t * ...yyyy`;\n\t *\n\t * let img = spriteArt(str);\n\t */\n\tthis.spriteArt = (txt, scale, palette) => {\n\t\tscale ??= 1;\n\t\tif (typeof palette == 'number') {\n\t\t\tpalette = pInst.world.palettes[palette];\n\t\t}\n\t\tpalette ??= pInst.world.palettes[0];\n\t\tlet lines = txt; // accepts 2D arrays of characters\n\t\tif (typeof txt == 'string') {\n\t\t\ttxt = txt.trim();\n\t\t\ttxt = txt.replace(/\\r*\\n\\t+/g, '\\n'); // trim leading tabs\n\t\t\ttxt = txt.replace(/\\s+$/g, ''); // trim trailing whitespace\n\t\t\tlines = txt.split('\\n');\n\t\t}\n\t\tlet w = 0;\n\t\tfor (let line of lines) {\n\t\t\tif (line.length > w) w = line.length;\n\t\t}\n\t\tlet h = lines.length;\n\t\tlet img = pInst.createImage(w * scale, h * scale);\n\t\timg.loadPixels();\n\n\t\tfor (let i = 0; i < lines.length; i++) {\n\t\t\tfor (let j = 0; j < lines[i].length; j++) {\n\t\t\t\tfor (let sX = 0; sX < scale; sX++) {\n\t\t\t\t\tfor (let sY = 0; sY < scale; sY++) {\n\t\t\t\t\t\tlet c = this.colorPal(lines[i][j], palette);\n\t\t\t\t\t\timg.set(j * scale + sX, i * scale + sY, c);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\timg.updatePixels();\n\t\timg.w = img.width;\n\t\timg.h = img.height;\n\t\tpInst.p5play.images.onLoad(img);\n\t\treturn img; // return the p5 graphics object\n\t};\n\n\t/**\n\t * Deprecated, use sprite.draw() instead.\n\t *\n\t * allSprites.draw() is run automatically at the end of the p5.js\n\t * draw loop, unless a sprite or group is drawn separately within the\n\t * draw loop.\n\t *\n\t * @deprecated\n\t * @method drawSprites\n\t */\n\tthis.drawSprite = function (sprite) {\n\t\tif (pInst.frameCount == 1) console.warn('drawSprite() is deprecated, use sprite.draw() instead.');\n\t\tsprite.draw();\n\t};\n\n\t/**\n\t * Deprecated, use group.draw() instead.\n\t *\n\t * allSprites.draw() is run automatically at the end of the p5.js\n\t * draw loop, unless a sprite or group is drawn separately within the\n\t * draw loop.\n\t *\n\t * @deprecated\n\t * @method drawSprites\n\t */\n\tthis.drawSprites = function (group) {\n\t\tif (pInst.frameCount == 1) console.warn('drawSprites() is deprecated, use group.draw() instead.');\n\t\tgroup ??= pInst.allSprites;\n\t\tgroup.draw();\n\t};\n\n\t/**\n\t * Creates a new sprite. Equivalent to `new Sprite()`\n\t *\n\t * @returns {Sprite}\n\t */\n\tthis.createSprite = function () {\n\t\treturn new Sprite(...arguments);\n\t};\n\n\t/**\n\t * Creates a new group of sprites. Equivalent to `new Group()`\n\t *\n\t * @returns {Group}\n\t */\n\tthis.createGroup = function () {\n\t\treturn new Group(...arguments);\n\t};\n\n\t/**\n\t * Loads an animation. Equivalent to `new SpriteAnimation()`\n\t *\n\t * Load animations in the preload p5.js function if you need to use\n\t * them when your program starts.\n\t *\n\t * @method loadAni\n\t * @returns {SpriteAnimation}\n\t */\n\t/**\n\t * Alias for loadAni\n\t *\n\t * @method loadAnimation\n\t * @returns {SpriteAnimation}\n\t */\n\tthis.loadAni = this.loadAnimation = function () {\n\t\treturn new SpriteAnimation(...arguments);\n\t};\n\n\t/**\n\t * Displays an animation. Similar to the p5.js image function.\n\t *\n\t * @method animation\n\t * @param {SpriteAnimation} ani Animation to be displayed\n\t * @param {Number} x X coordinate\n\t * @param {Number} y Y coordinate\n\t *\n\t */\n\tthis.animation = function (ani, x, y, r, sX, sY) {\n\t\tif (ani.visible) ani.update();\n\t\tani.draw(x, y, r, sX, sY);\n\t};\n\n\t/**\n\t * Delay code execution in an async function for the specified time.\n\t *\n\t * @method delay\n\t * @param {Number} millisecond\n\t * @returns {Promise} A Promise that fulfills after the specified time.\n\t *\n\t * @example\n\t * async function startGame() {\n\t *   await delay(3000);\n\t * }\n\t */\n\tp5.prototype.delay = (millisecond) => {\n\t\t// if no input arg given, delay waits for the next possible animation frame\n\t\tif (!millisecond) {\n\t\t\treturn new Promise(requestAnimationFrame);\n\t\t} else {\n\t\t\t// else it wraps setTimeout in a Promise\n\t\t\treturn new Promise((resolve) => {\n\t\t\t\tsetTimeout(resolve, millisecond);\n\t\t\t});\n\t\t}\n\t};\n\n\t/**\n\t * Sleep for the specified time. Equivalent to the delay function.\n\t *\n\t * @method sleep\n\t * @param {Number} millisecond\n\t * @returns {Promise} A Promise that fulfills after the specified time.\n\t *\n\t * @example\n\t * async function startGame() {\n\t *   await sleep(3000);\n\t * }\n\t */\n\tp5.prototype.sleep = (millisecond) => {\n\t\treturn p5.prototype.delay(millisecond);\n\t};\n\n\t/**\n\t * Awaitable function for playing sounds.\n\t *\n\t * @method play\n\t * @param {p5.Sound} sound\n\t * @returns {Promise}\n\t */\n\tthis.play = (sound) => {\n\t\tif (!sound.play) throw new Error('Tried to play a sound but the sound is not a sound object: ' + sound);\n\t\t// TODO reject if sound not found\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tsound.play();\n\t\t\tsound.onended(() => resolve());\n\t\t});\n\t};\n\n\tlet userDisabledP5Errors = p5.disableFriendlyErrors;\n\tp5.disableFriendlyErrors = true;\n\n\tconst _createCanvas = this.createCanvas;\n\n\t/**\n\t * Equivalent to p5.js createCanvas function and `new Canvas()`\n\t *\n\t * In p5.play a canvas can be created with an aspect ratio in the\n\t * format `width:height`. For example `new Canvas('16:9')` will create\n\t * the largest possible canvas with a 16:9 aspect ratio.\n\t *\n\t * This function also disables the default keydown responses for\n\t * the arrow keys, slash, and spacebar. This is to prevent the\n\t * browser from scrolling the page when the user is playing a game using\n\t * common keyboard commands.\n\t *\n\t * @method createCanvas\n\t * @param {Number} width|ratio\n\t * @param {Number} height\n\t */\n\tthis.createCanvas = function () {\n\t\tlet args = [...arguments];\n\t\tlet isFullScreen = false;\n\t\tlet pixelated = false;\n\t\tlet w, h, ratio;\n\t\tif (typeof args[0] == 'string') {\n\t\t\tratio = args[0].split(':');\n\t\t\tif (args[1] == 'fullscreen') {\n\t\t\t\tisFullScreen = true;\n\t\t\t}\n\t\t}\n\t\tif (!args.length) {\n\t\t\targs[0] = window.innerWidth;\n\t\t\targs[1] = window.innerHeight;\n\t\t\tisFullScreen = true;\n\t\t} else if (typeof args[0] == 'number' && typeof args[1] != 'number') {\n\t\t\targs[2] = args[1];\n\t\t\targs[1] = args[0];\n\t\t}\n\n\t\tif (args[2] == 'pixelated') {\n\t\t\tpixelated = true;\n\t\t\tisFullScreen = true;\n\t\t\tratio = [args[0], args[1]];\n\t\t}\n\t\tif (ratio) {\n\t\t\tlet rW = Number(ratio[0]);\n\t\t\tlet rH = Number(ratio[1]);\n\n\t\t\tw = window.innerWidth;\n\t\t\th = window.innerWidth * (rH / rW);\n\t\t\tif (h > window.innerHeight) {\n\t\t\t\tw = window.innerHeight * (rW / rH);\n\t\t\t\th = window.innerHeight;\n\t\t\t}\n\t\t\tw = Math.round(w);\n\t\t\th = Math.round(h);\n\n\t\t\tif (!pixelated) {\n\t\t\t\targs[0] = w;\n\t\t\t\targs[1] = h;\n\t\t\t}\n\t\t}\n\t\tif (args.length < 3) args[2] = 'p2d';\n\t\tlet can = _createCanvas.call(pInst, ...args);\n\t\tthis.canvas.tabIndex = 0;\n\t\tthis.canvas.addEventListener('keydown', function (e) {\n\t\t\tif (\n\t\t\t\te.key == ' ' ||\n\t\t\t\te.key == '/' ||\n\t\t\t\te.key == 'ArrowUp' ||\n\t\t\t\te.key == 'ArrowDown' ||\n\t\t\t\te.key == 'ArrowLeft' ||\n\t\t\t\te.key == 'ArrowRight'\n\t\t\t) {\n\t\t\t\te.preventDefault();\n\t\t\t}\n\t\t});\n\t\tthis.canvas.addEventListener('mouseover', () => {\n\t\t\tthis.mouse.isOnCanvas = true;\n\t\t\tthis.mouse.active = true;\n\t\t});\n\t\tthis.canvas.addEventListener('mouseleave', () => {\n\t\t\tthis.mouse.isOnCanvas = false;\n\t\t});\n\t\tthis.canvas.addEventListener('touchstart', (e) => {\n\t\t\te.preventDefault();\n\t\t});\n\t\tthis.world.resize();\n\t\tif (!userDisabledP5Errors) p5.disableFriendlyErrors = false;\n\n\t\t/* prevent callout to copy image, etc when tap to hold */\n\t\t/* prevent webkit from resizing text to fit */\n\t\t/* prevent copy paste, to allow, change 'none' to 'text' */\n\t\tlet style = `\ncanvas { \n\toutline: none;\n\t-webkit-touch-callout: none;\n\t-webkit-text-size-adjust: none;\n\t-webkit-user-select: none;\n\toverscroll-behavior: none;\n}\nmain{\n\toverscroll-behavior: none;\n}`;\n\t\tif (isFullScreen) {\n\t\t\tstyle = 'html,\\nbody,\\n' + style;\n\t\t\tstyle += `\nhtml, body {\n\tmargin: 0;\n\tpadding: 0;\n\toverflow: hidden;\n}\nmain {\n\tmargin: auto;\n\tdisplay: flex;\n\talign-content: center;\n\tjustify-content: center;\n}`;\n\t\t}\n\t\tif (pixelated) {\n\t\t\tstyle += `\ncanvas {\n\timage-rendering: pixelated;\n\twidth: ${w}px!important;\n\theight: ${h}px!important;\n}`;\n\t\t}\n\t\tlet styleElem = document.createElement('style');\n\t\tstyleElem.innerHTML = style;\n\t\tdocument.head.appendChild(styleElem);\n\n\t\tlet idx = navigator.userAgent.indexOf('iPhone OS');\n\t\tif (idx > -1) {\n\t\t\tlet version = navigator.userAgent.substring(idx + 10, idx + 12);\n\t\t\tthis.p5play.version = version;\n\t\t\tif (version < 16) {\n\t\t\t\tpInst.pixelDensity(1);\n\t\t\t}\n\t\t\tthis.p5play.os.platform = 'iOS';\n\t\t\tthis.p5play.os.version = version;\n\t\t} else if (navigator.userAgentData !== undefined) {\n\t\t\tthis.p5play.os.platform = navigator.userAgentData.platform;\n\t\t}\n\n\t\tif (pixelated) {\n\t\t\tpInst.pixelDensity(1);\n\t\t\tpInst.noSmooth();\n\t\t}\n\n\t\treturn can;\n\t};\n\n\tfunction Canvas() {\n\t\treturn pInst.createCanvas(...arguments);\n\t}\n\n\tconst _background = this.background;\n\n\t/**\n\t * Just like the p5.js background function except it also accepts\n\t * a color pallette code.\n\t *\n\t * @method background\n\t */\n\tthis.background = function () {\n\t\tlet args = arguments;\n\t\tlet c;\n\t\tif (args.length == 1 && (typeof args[0] == 'string' || args[0] instanceof p5.Color)) {\n\t\t\tc = this.colorPal(args[0]);\n\t\t}\n\t\tif (c !== undefined) _background.call(this, c);\n\t\telse _background.call(this, ...args);\n\t};\n\n\tconst _fill = this.fill;\n\n\t/**\n\t * Just like the p5.js fill function except it also accepts\n\t * a color pallette code.\n\t *\n\t * @method fill\n\t */\n\tthis.fill = function () {\n\t\tlet args = arguments;\n\t\tlet c;\n\t\tif (args.length == 1) {\n\t\t\tc = this.colorPal(args[0]);\n\t\t}\n\t\tif (c !== undefined) _fill.call(this, c);\n\t\telse _fill.call(this, ...args);\n\t};\n\n\tconst _stroke = this.stroke;\n\n\t/**\n\t * Just like the p5.js stroke function except it also accepts\n\t * a color pallette code.\n\t *\n\t * @method stroke\n\t */\n\tthis.stroke = function () {\n\t\tlet args = arguments;\n\t\tlet c;\n\t\tif (args.length == 1) {\n\t\t\tc = this.colorPal(args[0]);\n\t\t}\n\t\tif (c !== undefined) _stroke.call(this, c);\n\t\telse _stroke.call(this, ...args);\n\t};\n\n\t// images is a cache of loaded/loading images, to prevent making\n\t// the same loadImage fetch requests multiple times (inefficient)\n\tthis.p5play.images = {\n\t\tonLoad: (img) => {} // called anytime an image is fully loaded\n\t};\n\n\tconst _loadImage = this.loadImage;\n\n\t/**\n\t * Just like the p5.js loadImage function except it also caches images\n\t * so that they are only loaded once. Multiple calls to loadImage with\n\t * the same path will return the same image object. It also adds the\n\t * image's url as a property of the image object.\n\t *\n\t * @method loadImage\n\t * @param {string} url\n\t * @param {number} [width]\n\t * @param {number} [height]\n\t * @param {function} [callback]\n\t */\n\tthis.loadImg = this.loadImage = function () {\n\t\tlet args = arguments;\n\t\tlet url = args[0];\n\t\tlet img = pInst.p5play.images[url];\n\t\tlet cb;\n\t\tif (typeof args[args.length - 1] == 'function') {\n\t\t\tcb = args[args.length - 1];\n\t\t}\n\t\tif (img) {\n\t\t\t// if not finished loading, add callback to the list\n\t\t\tif ((img.width == 1 && img.height == 1) || !img.pixels.length) {\n\t\t\t\tif (cb) {\n\t\t\t\t\timg.cbs.push(cb);\n\t\t\t\t\timg.calls++;\n\t\t\t\t} else pInst._decrementPreload();\n\t\t\t} else {\n\t\t\t\tif (cb) cb(); // if already loaded, run the callback immediately\n\t\t\t\tpInst._decrementPreload();\n\t\t\t}\n\t\t\treturn img;\n\t\t}\n\t\tconst _cb = (_img) => {\n\t\t\t// if (!_img.pixels.length) {\n\t\t\t// \tlog('hi');\n\t\t\t// \t_loadImage.call(pInst, url, _cb);\n\t\t\t// \treturn;\n\t\t\t// }\n\n\t\t\t_img.w = _img.width;\n\t\t\t_img.h = _img.height;\n\t\t\tfor (let cb of _img.cbs) {\n\t\t\t\tcb();\n\t\t\t}\n\t\t\tfor (let i = 1; i < _img.calls; i++) {\n\t\t\t\tpInst._decrementPreload();\n\t\t\t}\n\t\t\t// delete _img.calls;\n\t\t\t// delete _img.cbs;\n\t\t\t_img.cbs = [];\n\t\t\tpInst.p5play.images.onLoad(img);\n\t\t};\n\t\timg = _loadImage.call(pInst, url, _cb);\n\t\timg.cbs = [];\n\t\timg.calls = 1;\n\t\tif (cb) img.cbs.push(cb);\n\t\timg.url = url;\n\t\tpInst.p5play.images[url] = img;\n\t\treturn img;\n\t};\n\n\tlet errorMessages = {\n\t\tgeneric: [\n\t\t\t'Ah! I found an error',\n\t\t\t'Oh no! Something went wrong',\n\t\t\t'Oof! Something went wrong',\n\t\t\t'Houston, we have a problem',\n\t\t\t'Whoops, having trouble here'\n\t\t],\n\t\tSprite: {\n\t\t\tconstructor: {\n\t\t\t\tbase: \"Sorry I'm unable to make a new Sprite\",\n\t\t\t\t0: \"What is $0 for? If you're trying to specify the x position of the sprite, please specify the y position as well.\",\n\t\t\t\t1: \"If you're trying to specify points for a chain Sprite, please use an array of position arrays:\\n$0\"\n\t\t\t},\n\t\t\thw: \"I can't change the halfWidth of a Sprite directly, change the sprite's width instead.\",\n\t\t\thh: \"I can't change the halfHeight of a Sprite directly, change the sprite's height instead.\",\n\t\t\trotate: 'The angle of rotation must be a number.',\n\t\t\tchangeAnimation: `I can't find any animation named \"$0\".`,\n\t\t\tcollide: {\n\t\t\t\t0: \"I can't make that sprite collide with $0. Sprites can only collide with another sprite or a group.\",\n\t\t\t\t1: 'The collision callback has to be a function.',\n\t\t\t\t2: \"You're trying to check for an collision with a sprite or group that doesn't exist!\"\n\t\t\t},\n\t\t\toverlap: {\n\t\t\t\t0: \"I can't make that sprite overlap with $0. Sprites can only overlap with another sprite or a group.\",\n\t\t\t\t1: 'The overlap callback has to be a function.',\n\t\t\t\t2: \"You're trying to check for an overlap with a sprite or group that doesn't exist!\"\n\t\t\t}\n\t\t},\n\t\tSpriteAnimation: {\n\t\t\tconstructor: {\n\t\t\t\tbase: \"Hey so, I tried to make a new SpriteAnimation but couldn't\",\n\t\t\t\t0: `I don't know how to display this type of image: \"$0\". I can only use \".png\" image files.`,\n\t\t\t\t1: 'The name of the animation must be the first input parameter.'\n\t\t\t}\n\t\t},\n\t\tGroup: {\n\t\t\tconstructor: {\n\t\t\t\tbase: \"Hmm awkward! Well it seems I can't make that new Group you wanted\"\n\t\t\t}\n\t\t}\n\t};\n\terrorMessages.Group.collide = errorMessages.Sprite.collide;\n\terrorMessages.Group.overlap = errorMessages.Sprite.overlap;\n\n\t/**\n\t * A FriendlyError is a custom error class that extends the native JS Error class.\n\t *\n\t * @private FriendlyError\n\t * @param {String} func is the name of the function the error was thrown in\n\t * @param {Number} errorNum is the error's code number\n\t * @param {Array} e is an array with references to the cause of the error\n\t */\n\tclass FriendlyError extends Error {\n\t\tconstructor(func, errorNum, e) {\n\t\t\tsuper();\n\n\t\t\tif (typeof func != 'string') {\n\t\t\t\te = errorNum;\n\t\t\t\terrorNum = func;\n\t\t\t\tfunc = this.stack.match(/\\n\\s*at ([^\\(]*)/)[1];\n\t\t\t\tfunc = func.slice(0, -1);\n\t\t\t}\n\t\t\tif (typeof errorNum != 'number') {\n\t\t\t\te = errorNum;\n\t\t\t\terrorNum = undefined;\n\t\t\t}\n\t\t\tif (func.slice(0, 3) == 'new') func = func.slice(4);\n\t\t\tfunc = func.split('.');\n\t\t\tlet className = func[0];\n\t\t\tfunc = func[1] || 'constructor';\n\n\t\t\tlet ln = this.stack.match(/\\/([^p\\/][^5][^\\/:]*:[^\\/:]+):/);\n\t\t\tif (ln) {\n\t\t\t\tln = ln[1].split(':');\n\t\t\t\tln = ' in ' + ln[0] + ' at line ' + ln[1] + '. ';\n\t\t\t} else ln = '.';\n\n\t\t\te = e || [];\n\n\t\t\tlet m = errorMessages[className][func];\n\t\t\tlet msg;\n\t\t\tif (m.base) msg = m.base + ln;\n\t\t\telse msg = errorMessages.generic[Math.floor(Math.random() * errorMessages.generic.length)] + ln;\n\t\t\tif (errorNum !== undefined) m = m[errorNum];\n\t\t\tm = m.replace(/\\$([0-9]+)/g, (m, n) => {\n\t\t\t\treturn e[n];\n\t\t\t});\n\t\t\tmsg += m;\n\n\t\t\tp5._friendlyError(msg, func);\n\t\t}\n\t}\n\n\tthis.Sprite = Sprite;\n\tthis.SpriteAnimation = SpriteAnimation;\n\tthis.Group = Group;\n\tthis.World = World;\n\tthis.Canvas = Canvas;\n\n\t/**\n\t * A group of all the sprites.\n\t *\n\t * @property allSprites\n\t */\n\tthis.allSprites = new Group();\n\tthis.allSprites.autoCull = true;\n\tthis.allSprites.tileSize = 1;\n\n\t/**\n\t * The planck physics world. Use this to change gravity and offset the\n\t * sprite's coordinate system.\n\t *\n\t * @property world\n\t */\n\tthis.world = new World();\n\n\t/**\n\t * Equal to the p5.js frameCount, the amount of times the draw() function has\n\t * been called.\n\t *\n\t * @property frame\n\t */\n\tthis.frame = 0;\n\n\t/**\n\t * The default camera. Use this to pan and zoom the camera.\n\t *\n\t * @property camera\n\t */\n\tthis.camera = new Camera();\n\n\t/**\n\t * Get user input from the mouse.\n\t * Stores the state of the left, center, or right mouse buttons.\n\t *\n\t * @property mouse\n\t */\n\t/**\n\t * Get user input from the keyboard.\n\t *\n\t * @property kb\n\t */\n\t/**\n\t * Alias for kb.\n\t *\n\t * @property keyboard\n\t */\n\t/**\n\t * Get user input from game controllers.\n\t *\n\t * @property contro\n\t */\n\n\t/**\n\t * Look at the Input reference pages before reading these docs.\n\t *\n\t * https://p5play.org/learn/input_devices.html\n\t *\n\t * Root class for storing the state of inputs (mouse, keyboard,\n\t * gamepads).\n\t *\n\t * -3 means input was released after being held, pressed for 12 frames\n\t * -2 means input was pressed and released on the same frame\n\t * -1 means input was released\n\t * 0 means input is not pressed\n\t * 1 means input was pressed\n\t * >1 means input is still being pressed\n\t * 12 means input was held\n\t * >12 means input is being held\n\t *\n\t * @class InputDevice\n\t */\n\tclass InputDevice {\n\t\tconstructor() {\n\t\t\t/**\n\t\t\t * The amount of frames an input must be pressed to be considered held.\n\t\t\t * Default is 12.\n\t\t\t *\n\t\t\t * @property holdThreshold\n\t\t\t * @type {number}\n\t\t\t */\n\t\t\tthis.holdThreshold = 12;\n\t\t}\n\n\t\t/**\n\t\t * Initializes the input's values to zero.\n\t\t *\n\t\t * @private init\n\t\t */\n\t\tinit(inputs) {\n\t\t\tfor (let inp of inputs) {\n\t\t\t\tthis[inp] = 0;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Attempt to auto-correct the user's input. Inheriting classes\n\t\t * override this method.\n\t\t *\n\t\t * @private ac\n\t\t */\n\t\tac(inp) {\n\t\t\treturn inp;\n\t\t}\n\n\t\t/**\n\t\t * @method presses\n\t\t * @param {string} inp\n\t\t * @returns {boolean} true on the first frame that the user presses the input\n\t\t */\n\t\tpresses(inp) {\n\t\t\tinp ??= this.default;\n\t\t\tif (this[inp] === undefined) inp = this.ac(inp);\n\t\t\treturn this[inp] == 1 || this[inp] == -2;\n\t\t}\n\n\t\t/**\n\t\t * @method pressing\n\t\t * @param {string} inp\n\t\t * @returns {number} the amount of frames the user has been pressing the input\n\t\t */\n\t\tpressing(inp) {\n\t\t\tinp ??= this.default;\n\t\t\tif (this[inp] === undefined) inp = this.ac(inp);\n\t\t\tif (this[inp] == -2) return 1;\n\t\t\treturn this[inp] > 0 ? this[inp] : 0;\n\t\t}\n\n\t\t/**\n\t\t * @method pressed\n\t\t * @param {string} inp\n\t\t * @returns {boolean} true on the first frame that the user released the input\n\t\t */\n\t\tpressed(inp) {\n\t\t\treturn this.released(inp);\n\t\t}\n\n\t\t/**\n\t\t * @method holds\n\t\t * @param {string} inp\n\t\t * @returns {boolean} true on the first frame that the user holds the input\n\t\t */\n\t\tholds(inp) {\n\t\t\tinp ??= this.default;\n\t\t\tif (this[inp] === undefined) inp = this.ac(inp);\n\t\t\treturn this[inp] == this.holdThreshold;\n\t\t}\n\n\t\t/**\n\t\t * @method holding\n\t\t * @param {string} inp\n\t\t * @returns {number} the amount of frames the user has been holding the input\n\t\t */\n\t\tholding(inp) {\n\t\t\tinp ??= this.default;\n\t\t\tif (this[inp] === undefined) inp = this.ac(inp);\n\t\t\treturn this[inp] >= this.holdThreshold ? this[inp] : 0;\n\t\t}\n\n\t\t/**\n\t\t * @method held\n\t\t * @param {string} inp\n\t\t * @returns {boolean} true on the first frame that the user released a held input\n\t\t */\n\t\theld(inp) {\n\t\t\tinp ??= this.default;\n\t\t\tif (this[inp] === undefined) inp = this.ac(inp);\n\t\t\treturn this[inp] == -3;\n\t\t}\n\n\t\t/**\n\t\t * @method released\n\t\t * @param {string} inp\n\t\t * @returns {boolean} true on the first frame that the user released the input\n\t\t */\n\t\treleased(inp) {\n\t\t\tinp ??= this.default;\n\t\t\tif (this[inp] === undefined) inp = this.ac(inp);\n\t\t\treturn this[inp] <= -1;\n\t\t}\n\n\t\treleases(inp) {\n\t\t\treturn this.released(inp);\n\t\t}\n\t}\n\n\tclass Mouse extends InputDevice {\n\t\tconstructor() {\n\t\t\tsuper();\n\t\t\tlet _this = this;\n\n\t\t\t// this.x and this.y store the actual position values of the mouse\n\t\t\tthis._position = {\n\t\t\t\tget x() {\n\t\t\t\t\treturn _this.x;\n\t\t\t\t},\n\t\t\t\tset x(val) {\n\t\t\t\t\t_this.x = val;\n\t\t\t\t},\n\t\t\t\tget y() {\n\t\t\t\t\treturn _this.y;\n\t\t\t\t},\n\t\t\t\tset y(val) {\n\t\t\t\t\t_this.y = val;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tlet inputs = ['x', 'y', 'left', 'center', 'right'];\n\t\t\tthis.init(inputs);\n\t\t\tthis.default = 'left';\n\t\t\tthis.draggable = false;\n\t\t\tthis.isOnCanvas = false;\n\t\t\tthis.active = false;\n\n\t\t\t/**\n\t\t\t * The mouse's x position.\n\t\t\t * @property x\n\t\t\t * @type {number}\n\t\t\t */\n\t\t\tthis.x;\n\n\t\t\t/**\n\t\t\t * The mouse's y position.\n\t\t\t * @property y\n\t\t\t * @type {number}\n\t\t\t */\n\t\t\tthis.y;\n\t\t}\n\n\t\t/**\n\t\t * The mouse's position.\n\t\t * @property pos\n\t\t */\n\t\tget pos() {\n\t\t\treturn this._position;\n\t\t}\n\t\t/**\n\t\t * The mouse's position. Alias for pos.\n\t\t * @property position\n\t\t */\n\t\tget position() {\n\t\t\treturn this._position;\n\t\t}\n\n\t\tac(inp) {\n\t\t\tif (inp.slice(0, 4)) inp = 'left';\n\t\t\telse if (inp.slice(0, 5) == 'right') inp = 'right';\n\t\t\telse if (inp.slice(0, 6) == 'middle') inp = 'center';\n\t\t\telse inp = inp.toLowerCase();\n\t\t\treturn inp;\n\t\t}\n\n\t\t/**\n\t\t * @method dragging\n\t\t * @param {string} inp\n\t\t * @returns {number} the amount of frames the user has been dragging the input\n\t\t */\n\t\tdragging(inp) {\n\t\t\tinp ??= this.default;\n\t\t\tthis.draggable = true;\n\t\t\treturn this[inp] >= this.holdThreshold ? this[inp] : 0;\n\t\t}\n\t}\n\n\tthis.mouse = new Mouse();\n\n\tclass SpriteMouse extends Mouse {\n\t\tconstructor() {\n\t\t\tsuper();\n\t\t\tthis.hover = 0;\n\t\t}\n\n\t\t/**\n\t\t * @method hovers\n\t\t * @returns {boolean} true on the first frame that the mouse is over the sprite\n\t\t */\n\t\thovers() {\n\t\t\treturn this.hover == 1;\n\t\t}\n\n\t\t/**\n\t\t * @method hovering\n\t\t * @returns {number} the amount of frames the mouse has been over the sprite\n\t\t */\n\t\thovering() {\n\t\t\treturn this.hover > 0 ? this.hover : 0;\n\t\t}\n\n\t\t/**\n\t\t * @method hovered\n\t\t * @returns {boolean} true on the first frame that the mouse is no longer over the sprite\n\t\t */\n\t\thovered() {\n\t\t\treturn this.hover == -1;\n\t\t}\n\t}\n\n\tconst _onmousedown = this._onmousedown;\n\n\tconst __onmousedown = function (btn) {\n\t\tthis.mouse[btn]++;\n\t\tthis.mouse.active = true;\n\n\t\tlet ms;\n\t\tif (this.p5play.mouseSprites.length) {\n\t\t\tms = this.p5play.mouseSprites[0];\n\t\t\tms.mouse[btn] = 1;\n\t\t\t// old mouse sprite didn't have the mouse released on it\n\t\t\t// so it just gets set to 0 (not pressed)\n\t\t\tif (this.p5play.mouseSprite) {\n\t\t\t\tthis.p5play.mouseSprite.mouse[btn] = 0;\n\t\t\t\tif (btn == 'left') {\n\t\t\t\t\tthis.p5play.mouseSprite.mouse.draggable = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.p5play.mouseSprite = ms;\n\t\t}\n\t};\n\n\tthis._onmousedown = function (e) {\n\t\tlet btn = 'left';\n\t\tif (e.button === 1) btn = 'center';\n\t\telse if (e.button === 2) btn = 'right';\n\n\t\t__onmousedown.call(this, btn);\n\n\t\t_onmousedown.call(this, e);\n\t};\n\n\tconst _ontouchstart = this._ontouchstart;\n\n\tthis._ontouchstart = function (e) {\n\t\t__onmousedown.call(this, 'left');\n\t\t_ontouchstart.call(this, e);\n\t};\n\n\tconst _onmouseup = this._onmouseup;\n\n\tconst __onmouseup = function (btn) {\n\t\tif (this.mouse[btn] >= this.mouse.holdThreshold) {\n\t\t\tthis.mouse[btn] = -3;\n\t\t} else if (this.mouse[btn] > 1) this.mouse[btn] = -1;\n\t\telse this.mouse[btn] = -2;\n\n\t\tif (this.p5play.mouseSprite) {\n\t\t\tif (this.p5play.mouseSprite.mouse.hover > 1) {\n\t\t\t\tif (this.p5play.mouseSprite.mouse[btn] >= this.mouse.holdThreshold) {\n\t\t\t\t\tthis.p5play.mouseSprite.mouse[btn] = -3;\n\t\t\t\t} else if (this.p5play.mouseSprite.mouse[btn] > 1) {\n\t\t\t\t\tthis.p5play.mouseSprite.mouse[btn] = -1;\n\t\t\t\t} else {\n\t\t\t\t\tthis.p5play.mouseSprite.mouse[btn] = -2;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.p5play.mouseSprite.mouse[btn] = 0;\n\t\t\t\tthis.p5play.mouseSprite.mouse.draggable = false;\n\t\t\t}\n\t\t}\n\t};\n\n\tthis._onmouseup = function (e) {\n\t\tlet btn = 'left';\n\t\tif (e.button === 1) btn = 'center';\n\t\telse if (e.button === 2) btn = 'right';\n\n\t\t__onmouseup.call(this, btn);\n\t\t_onmouseup.call(this, e);\n\t};\n\n\tconst _ontouchend = this._ontouchend;\n\n\tthis._ontouchend = function (e) {\n\t\t__onmouseup.call(this, 'left');\n\t\t_ontouchend.call(this, e);\n\t};\n\n\tclass KeyBoard extends InputDevice {\n\t\tconstructor() {\n\t\t\tsuper();\n\t\t\tthis.default = ' ';\n\t\t}\n\n\t\tac(inp) {\n\t\t\tif (inp.length == 1) return inp.toLowerCase();\n\t\t\tif (!isNaN(inp)) {\n\t\t\t\tif (inp == 38) return 'ArrowUp';\n\t\t\t\tif (inp == 40) return 'ArrowDown';\n\t\t\t\tif (inp == 37) return 'ArrowLeft';\n\t\t\t\tif (inp == 39) return 'ArrowRight';\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Use key names with the keyboard input functions, not key codes! If you are trying to detect if the user pressed a number key make it a string. For example: \"5\"'\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (inp == 'space' || inp == 'spacebar') return ' ';\n\t\t\treturn inp[0].toUpperCase() + inp.slice(1).toLowerCase();\n\t\t}\n\n\t\tget space() {\n\t\t\treturn this[' '];\n\t\t}\n\t\tget spacebar() {\n\t\t\treturn this[' '];\n\t\t}\n\t}\n\n\tthis.kb = new KeyBoard();\n\tthis.keyboard = this.kb;\n\n\tif (navigator.keyboard) {\n\t\tconst keyboard = navigator.keyboard;\n\t\tif (window == window.top) {\n\t\t\tkeyboard.getLayoutMap().then((keyboardLayoutMap) => {\n\t\t\t\tconst key = keyboardLayoutMap.get('KeyW');\n\t\t\t\tif (key != 'w') this.p5play.standardizeKeyboard = true;\n\t\t\t});\n\t\t} else {\n\t\t\tthis.p5play.standardizeKeyboard = true;\n\t\t}\n\t} else {\n\t\t// Firefox doesn't have navigator.keyboard\n\t\t// so just make it use key codes\n\t\tthis.p5play.standardizeKeyboard = true;\n\t}\n\n\t/**\n\t * Obsolete: Use kb.pressing(key) instead.\n\t *\n\t * @obsolete keyIsDown\n\t * @param {String} key\n\t */\n\tthis.keyIsDown = function (keyCode) {\n\t\tthrow new Error(\n\t\t\t`The p5.js keyIsDown function is outdated and can't be used in p5.play. Trust me, you'll see that the p5.play kb.pressing function is much better. It uses key name strings that are easier to write and easier to read! https://p5play.org/learn/input_devices.html The p5.js keyIsDown function relies on key codes and custom constants for key codes, which are not only hard to remember but were also deprecated in the JavaScript language standards over six years ago and shouldn't be used in new projects. More info: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode`\n\t\t);\n\t};\n\n\t/**\n\t * @private _getKeyFromCode\n\t * @param {*} e keyboard event\n\t * @returns key name\n\t */\n\tfunction _getKeyFromCode(e) {\n\t\tlet code = e.code;\n\t\tif (code.length == 4 && code.slice(0, 3) == 'Key') {\n\t\t\treturn code[3].toLowerCase();\n\t\t}\n\t\treturn e.key;\n\t}\n\n\tlet simpleKeyControls = {\n\t\tw: 'up',\n\t\ts: 'down',\n\t\ta: 'left',\n\t\td: 'right',\n\t\tArrowUp: 'up',\n\t\tArrowDown: 'down',\n\t\tArrowLeft: 'left',\n\t\tArrowRight: 'right',\n\t\ti: 'up2',\n\t\tk: 'down2',\n\t\tj: 'left2',\n\t\tl: 'right2'\n\t};\n\n\tconst _onkeydown = this._onkeydown;\n\n\tthis._onkeydown = function (e) {\n\t\tlet key = e.key;\n\t\tif (this.p5play.standardizeKeyboard) {\n\t\t\tkey = _getKeyFromCode(e);\n\t\t}\n\t\tlet keys = [key];\n\t\tlet k = simpleKeyControls[key];\n\t\tif (k) keys.push(k);\n\t\tfor (let k of keys) {\n\t\t\tif (!this.kb[k] || this.kb[k] < 0) {\n\t\t\t\tthis.kb[k] = 1;\n\t\t\t}\n\t\t}\n\t\t_onkeydown.call(this, e);\n\t};\n\n\tconst _onkeyup = this._onkeyup;\n\n\tthis._onkeyup = function (e) {\n\t\tlet key = e.key;\n\t\tif (this.p5play.standardizeKeyboard) {\n\t\t\tkey = _getKeyFromCode(e);\n\t\t}\n\t\tlet keys = [key];\n\t\tlet k = simpleKeyControls[key];\n\t\tif (k) keys.push(k);\n\t\tfor (let k of keys) {\n\t\t\tif (this.kb[k] >= this.kb.holdThreshold) {\n\t\t\t\tthis.kb[k] = -3;\n\t\t\t} else if (this.kb[k] > 1) this.kb[k] = -1;\n\t\t\telse this.kb[k] = -2;\n\t\t}\n\n\t\t_onkeyup.call(this, e);\n\t};\n\n\tclass Contro extends InputDevice {\n\t\tconstructor(gp) {\n\t\t\tsuper();\n\t\t\tlet inputs = [\n\t\t\t\t'a',\n\t\t\t\t'b',\n\t\t\t\t'x',\n\t\t\t\t'y',\n\t\t\t\t'l',\n\t\t\t\t'r',\n\t\t\t\t'lt',\n\t\t\t\t'rt',\n\t\t\t\t'select',\n\t\t\t\t'start',\n\t\t\t\t'up',\n\t\t\t\t'down',\n\t\t\t\t'left',\n\t\t\t\t'right',\n\t\t\t\t'leftTrigger',\n\t\t\t\t'rightTrigger'\n\t\t\t];\n\t\t\tthis.init(inputs);\n\n\t\t\tthis.leftStick = {\n\t\t\t\tx: 0,\n\t\t\t\ty: 0,\n\t\t\t\tbtn: 0\n\t\t\t};\n\n\t\t\tthis.rightStick = {\n\t\t\t\tx: 0,\n\t\t\t\ty: 0,\n\t\t\t\tbtn: 0\n\t\t\t};\n\n\t\t\tthis._btns = {\n\t\t\t\ta: 0,\n\t\t\t\tb: 1,\n\t\t\t\tx: 2,\n\t\t\t\ty: 3,\n\t\t\t\tl: 4,\n\t\t\t\tr: 5,\n\t\t\t\tlt: 6,\n\t\t\t\trt: 7,\n\t\t\t\tselect: 8,\n\t\t\t\tstart: 9,\n\t\t\t\tleftStickButton: 10,\n\t\t\t\trightStickButton: 11,\n\t\t\t\tup: 12,\n\t\t\t\tdown: 13,\n\t\t\t\tleft: 14,\n\t\t\t\tright: 15\n\t\t\t};\n\t\t\tthis._axes = {\n\t\t\t\tleftStick: {\n\t\t\t\t\tx: 0,\n\t\t\t\t\ty: 1\n\t\t\t\t},\n\t\t\t\trightStick: {\n\t\t\t\t\tx: 2,\n\t\t\t\t\ty: 3\n\t\t\t\t},\n\t\t\t\tleftTrigger: 4,\n\t\t\t\trightTrigger: 5\n\t\t\t};\n\n\t\t\t// corrects button mapping for GuliKit gamepads\n\t\t\t// which have a Nintendo Switch style button layout\n\t\t\t// https://www.aliexpress.com/item/1005003624801819.html\n\t\t\tif (gp.id.includes('GuliKit')) {\n\t\t\t\tthis._btns.a = 1;\n\t\t\t\tthis._btns.b = 0;\n\t\t\t\tthis._btns.x = 3;\n\t\t\t\tthis._btns.y = 2;\n\t\t\t}\n\n\t\t\tlog(gp);\n\n\t\t\tthis.gamepad = gp;\n\t\t\tthis.id = gp.id;\n\t\t}\n\n\t\tac(inp) {\n\t\t\treturn inp.toLowerCase();\n\t\t}\n\n\t\t_update() {\n\t\t\tthis.gamepad = navigator.getGamepads()[this.gamepad.index];\n\t\t\tif (!this.gamepad) return;\n\n\t\t\tlet pad = this.gamepad;\n\n\t\t\t// buttons\n\t\t\tfor (let name in this._btns) {\n\t\t\t\tlet idx = this._btns[name];\n\t\t\t\tif (pad.buttons[idx].pressed) this[name]++;\n\t\t\t\telse this[name] = 0;\n\t\t\t}\n\n\t\t\t// sticks\n\t\t\tthis.leftStick.x = pad.axes[this._axes.leftStick.x];\n\t\t\tthis.leftStick.y = pad.axes[this._axes.leftStick.y];\n\n\t\t\tthis.rightStick.x = pad.axes[this._axes.rightStick.x];\n\t\t\tthis.rightStick.y = pad.axes[this._axes.rightStick.y];\n\n\t\t\t// triggers\n\t\t\tif (pad.axes[this._axes.leftTrigger] !== undefined) {\n\t\t\t\tthis.leftTrigger = pad.axes[this._axes.leftTrigger];\n\t\t\t\tthis.rightTrigger = pad.axes[this._axes.rightTrigger];\n\t\t\t} else {\n\t\t\t\tthis.leftTrigger = pad.buttons[this._btns.lt].value;\n\t\t\t\tthis.rightTrigger = pad.buttons[this._btns.rt].value;\n\t\t\t}\n\n\t\t\treturn true; // update completed\n\t\t}\n\t}\n\n\tclass Contros extends Array {\n\t\tconstructor() {\n\t\t\tsuper();\n\t\t\tlet _this = this;\n\t\t\twindow.addEventListener('gamepadconnected', (e) => {\n\t\t\t\t_this._addContro(e.gamepad);\n\t\t\t});\n\t\t\t// TODO\n\t\t\t// window.addEventListener('gamepaddisconnected', (e) => {\n\t\t\t// \t_this._removeContro(e.gamepad);\n\t\t\t// });\n\n\t\t\tthis.default = 'a';\n\n\t\t\tlet methods = ['presses', 'pressing', 'pressed', 'holds', 'holding', 'held', 'released'];\n\t\t\tfor (let m of methods) {\n\t\t\t\tthis[m] = (inp) => {\n\t\t\t\t\tif (this[0]) return this[0][m](inp);\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet inputs = [\n\t\t\t\t'a',\n\t\t\t\t'b',\n\t\t\t\t'x',\n\t\t\t\t'y',\n\t\t\t\t'l',\n\t\t\t\t'r',\n\t\t\t\t'lt',\n\t\t\t\t'rt',\n\t\t\t\t'select',\n\t\t\t\t'start',\n\t\t\t\t'leftStickButton',\n\t\t\t\t'rightStickButton',\n\t\t\t\t'up',\n\t\t\t\t'down',\n\t\t\t\t'left',\n\t\t\t\t'right'\n\t\t\t];\n\t\t\tfor (let inp of inputs) {\n\t\t\t\tObject.defineProperty(this, inp, {\n\t\t\t\t\tget() {\n\t\t\t\t\t\tif (_this[0]) return _this[0][inp];\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet props = ['leftStick', 'rightStick'];\n\t\t\tfor (let prop of props) {\n\t\t\t\tthis[prop] = {};\n\t\t\t\tfor (let axis of ['x', 'y']) {\n\t\t\t\t\tObject.defineProperty(this[prop], axis, {\n\t\t\t\t\t\tget() {\n\t\t\t\t\t\t\tif (_this[0]) return _this[0][prop][axis];\n\t\t\t\t\t\t\treturn 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// test if the broswer supports the HTML5 Gamepad API\n\t\t\t// all modern browsers do, this is really just to prevent\n\t\t\t// p5.play's Jest tests from failing\n\t\t\tif (!navigator?.getGamepads) return;\n\n\t\t\t// if the page was not reloaded, but p5.play sketch was,\n\t\t\t// then gamepads could be already connected\n\t\t\t// so they need to be added as Contro objects\n\t\t\tlet gps = navigator.getGamepads();\n\t\t\tfor (let gp of gps) {\n\t\t\t\tif (gp) this._addContro(gp);\n\t\t\t}\n\t\t}\n\n\t\t_addContro(gp) {\n\t\t\tif (!gp) return;\n\t\t\tlog('controller ' + this.length + ' connected: ' + gp.id);\n\t\t\tthis.push(new Contro(gp));\n\t\t}\n\n\t\t/**\n\t\t * Updates the state of all controllers.\n\t\t */\n\t\t_update() {\n\t\t\tfor (let c of this) {\n\t\t\t\tc._update();\n\t\t\t}\n\t\t}\n\t}\n\n\tthis.contro = new Contros();\n\tthis.controllers = this.contro;\n});\n\n// called before each p5.js draw function call\np5.prototype.registerMethod('pre', function () {\n\tif (this.frameCount == 1) {\n\t\tthis.camera.x = this.world.hw;\n\t\tthis.camera.y = this.world.hh;\n\t\tthis.camera.init = true;\n\n\t\t// this stops the right click menu from appearing\n\t\tthis.canvas.addEventListener('contextmenu', (event) => event.preventDefault());\n\t}\n\n\tthis.mouse.x = (this.mouseX - this.world.hw) / this.camera.zoom + this.camera.x;\n\tthis.mouse.y = (this.mouseY - this.world.hh) / this.camera.zoom + this.camera.y;\n\n\tthis.camera.mouse.x = this.mouseX;\n\tthis.camera.mouse.y = this.mouseY;\n\n\tthis.contro._update();\n});\n\n// called after each p5.js draw function call\np5.prototype.registerMethod('post', function p5playPostDraw() {\n\tthis.frame = this.frameCount;\n\n\tif (this.p5play.autoDrawSprites) {\n\t\tthis.camera.on();\n\t\tthis.allSprites.draw();\n\t\tthis.camera.off();\n\t\tthis.p5play.autoDrawSprites = true;\n\t}\n\n\tif (this.p5play.autoUpdateSprites) {\n\t\tthis.updateSprites();\n\t\tthis.p5play.autoUpdateSprites = true;\n\t}\n\n\tif (this.allSprites.autoCull) {\n\t\tthis.allSprites.cull(10000);\n\t}\n\n\tfor (let btn of ['left', 'center', 'right']) {\n\t\tif (this.mouse[btn] < 0) this.mouse[btn] = 0;\n\t\telse if (this.mouse[btn] > 0) this.mouse[btn]++;\n\n\t\tif (this.p5play.mouseSprite) {\n\t\t\tif (this.p5play.mouseSprite.mouse[btn] < 0) {\n\t\t\t\tthis.p5play.mouseSprite.mouse[btn] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (let k in this.kb) {\n\t\tif (k == 'holdThreshold') continue;\n\t\tif (this.kb[k] < 0) this.kb[k] = 0;\n\t\telse if (this.kb[k] > 0) this.kb[k]++;\n\t}\n\n\tif (this.p5play.mouseTracking) {\n\t\tif (this.p5play.mouseSprite) {\n\t\t\tlet val = 0;\n\t\t\tfor (let btn of ['left', 'center', 'right']) {\n\t\t\t\tval += this.p5play.mouseSprite.mouse[btn];\n\t\t\t}\n\t\t\tif (val == 0) this.p5play.mouseSprite = null;\n\t\t}\n\n\t\tlet sprites = this.getSpritesAt(this.mouse.x, this.mouse.y);\n\t\tsprites.sort((a, b) => (a.layer - b.layer) * -1);\n\n\t\tlet uiSprites = this.getSpritesAt(this.camera.mouse.x, this.camera.mouse.y, this.allSprites, false);\n\t\tuiSprites.sort((a, b) => (a.layer - b.layer) * -1);\n\n\t\tsprites = sprites.concat(uiSprites);\n\n\t\tlet ms;\n\t\tif (this.mouse.pressing('left') || this.mouse.pressing('center') || this.mouse.pressing('right')) {\n\t\t\t// mouse sprite is not draggable\n\t\t\tif (!this.p5play.mouseSprite?.mouse.draggable) {\n\t\t\t\t// if sprite is being dragged,\n\t\t\t\t// it should be dragged behind sprites on higher layers\n\t\t\t\tfor (let s of sprites) {\n\t\t\t\t\tif (s == this.p5play.mouseSprite) {\n\t\t\t\t\t\tms = s;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tms = this.p5play.mouseSprite;\n\t\t\t}\n\t\t\t// if mouse is pressing the sprite\n\t\t\tif (ms) {\n\t\t\t\tms.mouse.left = this.mouse.left;\n\t\t\t\tms.mouse.center = this.mouse.center;\n\t\t\t\tms.mouse.right = this.mouse.right;\n\t\t\t\tms.mouse.x = ms.x - this.mouse.x;\n\t\t\t\tms.mouse.y = ms.y - this.mouse.y;\n\t\t\t} else if (this.p5play.mouseSprite) {\n\t\t\t\tthis.p5play.mouseSprite.mouse.left = 0;\n\t\t\t\tthis.p5play.mouseSprite.mouse.center = 0;\n\t\t\t\tthis.p5play.mouseSprite.mouse.right = 0;\n\t\t\t\tthis.p5play.mouseSprite.mouse.draggable = false;\n\t\t\t}\n\t\t}\n\n\t\tfor (let s of sprites) {\n\t\t\ts.mouse.hover++;\n\t\t}\n\n\t\tfor (let s of this.p5play.mouseSprites) {\n\t\t\tif ((!this.p5play.mouseSprite?.mouse.draggable || s != ms) && !sprites.includes(s)) {\n\t\t\t\ts.mouse.hover = -1;\n\t\t\t\ts.mouse.left = 0;\n\t\t\t\ts.mouse.center = 0;\n\t\t\t\ts.mouse.right = 0;\n\t\t\t\ts.mouse.draggable = false;\n\t\t\t}\n\t\t}\n\t\tthis.p5play.mouseSprites = sprites;\n\t}\n\n\tthis.camera.off();\n});\n"
  },
  {
    "path": "package.json",
    "content": "{\n\t\"name\": \"p5.play\",\n\t\"author\": \"quinton-ashley <qashto@gmail.com> (https://quintos.org)\",\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/quinton-ashley/p5.play/issues\"\n\t},\n\t\"contributors\": [\n\t\t\"Paolo Pedercini <info@molleindustria.it>\"\n\t],\n\t\"description\": \"A p5.js library for making games and interactive art!\",\n\t\"keywords\": [\n\t\t\"p5play\",\n\t\t\"p5.js\",\n\t\t\"p5js\",\n\t\t\"p5\",\n\t\t\"game\",\n\t\t\"games\",\n\t\t\"animation\",\n\t\t\"art\",\n\t\t\"interactive\",\n\t\t\"creative\",\n\t\t\"generative\"\n\t],\n\t\"license\": \"GPL-3.0-only\",\n\t\"homepage\": \"https://github.com/quinton-ashley/p5.play#readme\",\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"git+https://github.com/quinton-ashley/p5.play.git\"\n\t},\n\t\"scripts\": {\n\t\t\"v\": \"npm version patch --force\",\n\t\t\"V\": \"npm version minor --force\",\n\t\t\"version\": \"git add -A\",\n\t\t\"postversion\": \"git push\"\n\t},\n\t\"version\": \"3.5.13\"\n}\n"
  }
]